Coding the Universe Jon Keon

Actionscript, Flash

So I’ve been enjoying the work of Greg Martin lately. (Art of Greg Martin)

His work is pretty impressive and I thought it would be cool to see what kind of imitations I could come up with in Flash.

Now if you google Flash 3D Planets, you get a wide variety of results. With no disrespect to the authors whatsoever, I’ve just found them all to be a bit lack luster. (Granted, their intent was more technical than artistic and I definitely checked out the source where possible to see how they did it)

An Older Demo from Gene Pavlosky in 3D

Variety of Planets from Flash and Math

Senocular’s Demo of Flash 10 Sphere’s

Brian Wilgus’ take in Papervision

So I decided to take a go at it and see where we could end up.

The first thing to do was see if we could even get a decent render going with an acceptable frame rate. Borrowing textures from JHT’s Planetary Pixel Emporium, I think it is.

Click on the image to launch the demo. Use the arrow keys to move the camera up/down/left/right and use the O and P keys to move the camera in and out.

In this demo, I’m using the 1000×500 Earth Texture from JHT along with the Cloud Map and Cloud Map Transparency. The Planet itself is a sphere using Flash 10’s draw Triangles modified from Senocular’s post. The Cloud layer is another sphere with a slightly larger radius and a slightly faster rotation speed. Finally there is an outer glow layer, inner glow layer and shadow layer to make up the final image.

All in all, it looks fairly nice although kudos if you noticed that the Earth was flipped… oops!

The biggest downside though is that it’s 2.6MB to download because of the textures. And that’s just one planet!

So I started reading up on procedural texture generation and started experimenting. After a little bit, I ended up with the second demo:

Same as the demo before, arrow keys to move up/down/left/right and O, P to move in and out.

In this demo, there are 11 planets placed around a sun. Each planet moves around the sun in orbit while spinning on it’s own axis. The lighting is not yet hooked up so each planet it lit from the top-left regardless of where it is around the sun.

The sun and the rock planet though are 100% procedural. There are no textures being used and so the final file size is only 230KB. Of course the trade off is the initial start time and memory usage but I’m fine with that for now.

The textures themselves aren’t that exciting but if you zoom up nice and close they hold a pretty solid amount of detail allowing for future expansion in complexity and visual interest.

Which brings us to the last demo for this post, a better sun texture.

I’ll admit, I find the sun texture in the previous example really boring. Sure there are sometime these irregular blobs for sunspots but it just doesn’t do it for me. I felt like it needed a bit more oomph so I tweaked the texture algorithm with multiple passes of difference blending and recursive perlin masks. The result below is a much more impressive looking sun that’s way more interesting to look at.

Same controls as before for moving and zooming.

The next steps are to finish up the lighting model and then start populating with some different types of planets. Maybe add a nebula or two and a better procedural star field too. Eventually I’d like to have a full scene that you can just fly around in endlessly, dynamically creating and destroying different planets and entities.

We’ll see where it goes.

This entry was posted on Tuesday, June 29th, 2010 at 7:04 am and is filed under Actionscript, Flash. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.