| « The basics of setting up a website |
I've been thinking a lot about space recently, partially because of the awesome competition my mate at the Science Museum is running, and partially cause I've been thinking about visualisation ideas for next year and this infographic has been of immediate inspiration.
So I was messing around with some graphics libraries last night, sitting up as my son went to sleep, and I made this. It's a fully generative starfield, with nebula clouds. Click on it to generate a new layout.
There are a couple of notable things about this (not that it's that notable really, but I was quite excited about it). Firstly is the randomise function which I found on Snipplr. This is really just a simple extension of the Math.random() function, but giving it two numbers to randomise between. It's a really useful thing to have actually and I use it not only to choose a random number of stars to create (between 300 and 500 in this example), but also for their relative size (this is a radius between 1 and 10, which I then /10 to get a value between 0-1 (this also then sets the alpha so smaller ones are dimmer) and I also use it for position (this is dead easy, a random number between 0 and the width of the stage!).
public function randomInRange(from:int, to:int):int {
return Math.ceil(Math.random() * (to - from + 1)) + from;
}
The second thing of interest is the cloud nebulae which are a bitmap I've generated on the fly. I discovered that the Bitmap Class has an inbuilt Perlin noise generator (this is the same thing that generates "clouds" in photoshop!) so it was quite straightforward to generate some random clouds. Source to follow