Planet Generator

Sketches have a way of growing old when you don’t touch them for a couple weeks. Aug06 is a random planet generator that I worked on pretty furiously for about four days, and then promptly got bored of. It seems that the more you work on a project, the more you become interested in it, and also that the less you work on a project the less you become interested :P. Anyways, here’s a basic outline of what happened:


First draft. Map a 2D Perlin noise grid onto the sphere. I made a wrapping error by saying the elevation angle should wrap around from PI/2 -PI/2 (which is why all of the lines go towards the bottom center point).


Added plane-drawing and colors based on height. This image shows the major issue that this sketch faced: working in a spherical geometry space. The 2D Perlin noise field produces different heights for different multiples of two pi, thus creating that abrupt line. Also apparent is the squishing of the rectangular projection near the pole of the planet.


It’s an alien planet! LOL. My halfbaked puns will destroy you. This also shows that Perlin noise is an even function, hence unwanted symmetry.


After a rethinking of the underlying mechanism, the planet’s starting to look like an actual planet. The coloring is now a nice gradient; I superimposed several Perlin noises of different time/height scales for a more natural look. I got rid of the Perlin problems by a) adding an offset to the parameters so that there was no symmetry, and b) writing a “smooth” method that basically Gaussian blurs all of the heights. The basic outline for creating a planet is to generate a height map based of Perlin noises and then turn everything below a certain height into ocean, creating semi-realistic looking seas/lakes.


I actually wasn’t originally sure how this planet got to be so swirly, but it looks good. Also, it’s amazing what a simple call to lights() will do to a sketch.


The swirliness was caused by a bug in my smooth method, which actually turned out kinda nice. Definitely gives you pretty unique looking planets.


Replaced the Perlin noise with Simplex noise, which tends to be much more hilly and “regular”. This planet was such a fuck that I just had to include it :P


Floating green squash generator! I started adding terrain features such as hills and mountains, but got one of the coordinates wrong. Also added the starry background + sun which looks quite nice.


Added a coloring method that takes a look at the slopes of various places and tries to color them differently. My goal was to make cliffs look worn out and rocky instead of nice and green. It didn’t really work. I added huge crater features in combination with the Simplex noise and lots of small pokey mountains to get… some evil alien meteor. I really started to lose hope of this sketch ever looking the way I wanted it to.


Plateaus. Change. Everything. Early on I added the ability to render the map in a rectangular coordinates as to help debug various rendering bugs, but this image was particularly pleasing since it has many “nice” features – nice terrain and interplay between the land and the ocean (particularly with regards to those little pointy mountains), multiple levels of terrain with the plateaus, and good coloring (the cliffs actually look yellow, and the very top of the mountain is capped with snow).


Now THAT was what I was looking for. It definitely looks a little cartoony (actually it reminds me of the planets in Spore) but the features are there. I like the way the shoreline looks, especially with regards to that half-white half-blue tone near the center of the image implying a nice shallow pool area. The cliffs also stand out quite nicely.


I wondered what would happen if I took a bitmap image and made a heightmap and colormap out of the pixels. I took my desktop background, a screenshot of the gorgeous multiscale turing pattern, and mapped each pixel’s brightness into a corresponding height point on the planet and each pixel’s color into a color point (obviously). The result wasn’t as beautiful and awe-inspiring as I had hoped but I’m still quite pleased with it. You can make out the valleys and larger features.


Added primitive tree textures; also abstracted out the rendering to let any arbitrary coordinate system draw the heightmap (e.g. into torodial coordinates, as shown).



Change the color of “ocean” to transparent, to interesting effect.

See the sketch here.

I actually wrote a simple framework with which to easily populate the world with “things” – e.g. plants and animals, man-made features like towers or little villages, flocks of birds, giant turtles, clouds, floating land masses, moons, etc. Unfortunately I never got the time to actually IMPLEMENT all of those ideas. Perhaps I’ll come back to the code later on and give my planets some life.

One thing that really bothers me is that I never fixed the rectangular -> spherical projection problem. There is no perfect way to project a rectangle onto the surface of a sphere, which creates a bunch of issues. What I’d really like is some way to be able to tile the surface of the sphere regularly; perhaps with hexagons or triangles. But this is a whole other field that deserves its own sketch entirely…

Advertisements

8 Comments on “Planet Generator”

  1. […] been getting the feeling that my random planet generator isn’t finished yet. I’d really have liked to polish it up and make it look really nice, […]

  2. Brendan ☼ says:

    Dude this is really cool. I’ve been doing some procedural world stuff as well, and funnily enough, thinking about moving to scala (the verbosity of Java is highly annoying). I’m still having trouble getting the applet to work in Intellij however. Do you use Maven for managing your projects? If so, how do you set up your Processing projects with it?

    • hellochar says:

      Thanks again :) I do not use Maven or SBT. I feel like it’d be good to learn one of them sooner or later but right now I really don’t feel a need. Although I said the same thing about version control and now it’s pretty much indispensable. Anyways, here’s what I do:

      1) Create a project with a Scala facet.
      2) Have a module in the project that has both Processing and Scala listed as dependencies.
      3) Create a class that extends PApplet, write whatever code, and then press shift+f6 – this creates an Appletviewer configuration in IntelliJ and runs your applet.

      Does that help?

      Also, I looked at your tumblr. I really like those little villages that you’ve got going on!

      • Brendan ☼ says:

        Thanks! Yeah, I have loads of ideas and loads of drawings, but I’m horrible at programming so I’m pretty damn slow! I think the procedural stuff has big potential, I really envision it being an audio reactive landscape (ala Star Guitar) but there are many other possibilities. If you ever want to collaborate, I’d love to – I think it’s pretty cool finding somebody on the net interested in the same stuff as me. But I completely understand if you’re more interested working on your projects.

        And yes, I said the same thing about version control and eclipse. I know what you mean.

        I keep getting this:

        Exception in thread “main” java.lang.RuntimeException: Compiler classes not found: at org.jetbrains.plugins.scala.compiler.rt.ScalacRunner.main(ScalacRunner.java:69)
        Caused by: java.lang.ClassNotFoundException: scala.tools.nsc.Main
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.jetbrains.plugins.scala.compiler.rt.ScalacRunner.main(ScalacRunner.java:65)

        Must be something wrong with scala. I tried all the stuff in the Project Structure section, but it all seems like voodo magic at the moment.

      • Brendan ☼ says:

        Oh, and is shift+f6 meant to bring up the refractor window? Because that’s what it does for me…

      • Brendan ☼ says:

        Hooray! After enduring several days of pain I *finally* got it working!

        So this is what I did in real dummy steps:

        – read this page: http://www.scala-lang.org/node/345

        – open the terminal
        – `cd` to the folder that you want to put add your project to
        – enter: mvn archetype:generate
        – choose the `scala-archetype-simple` archetype from the list
        – enter in the project details
        – now manually import the processing library to maven by entering:

        mvn install:install-file -Dfile=/Applications/Processing.app/Contents/Resources/Java/core.jar -DgroupId=org.processing -Dversion=1.5.1 -Dpackaging=jar -DartifactId=processing

        NOTE: the file path is for mac osx, enter the path that fits your platform, and the version number is the version of processing you’ve currently got installed

        – open IntelliJ

        – got to to file>new project
        – select ‘Import from external model’ (the third option)
        – in the next screen choose maven
        – change the root directory to the root directory of the newly created project, leaving the rest of the options at their default values
        – the next two screens are self explanatory
        – click ‘finish’

        – open pom.xml in the new project and enter this into the dependencies section:

        org.processing
        core
        1.5.1

        that’ll automatically load the processing library into your project

        – in automatically generated scala class extend the automatically generated object with PApplet eg:

        object VillageGen extends PApplet {

        – add some basic processing code, eg:

        override def setup() {
        size(1000, 600)
        }

        override def draw() {
        background(100);
        }

        – replace the code in the main(args: Array[String]) function to:

        def main(args: Array[String]) {
        PApplet.runSketch(Array(“Test”), this)
        }

        (that was based off what I saw you do in another blog post)

        – go to Run > run… and choose ‘Edit configurations’ in the pop-up that appears
        – click the plus sign in the top left corner and choose ‘Java Application’
        – type the the name of the class with the main function into the relevant text box. In my case it was ‘net.voyager3.VillageGen’
        – then hit run!

        Sorry for being so specific, I just found the every single place I looked at left out steps. I think I’ll actually put together a blog post on this in the hope that it assists somebody else. :]

      • hellochar says:

        Nice tutorial! Specificity is good. This’ll definitely help those wanting to get set up with Maven. Shift+F6 on my computer runs the file I’ve selected instead of refactoring.

        I agree that procedural has so much potential! I feel like there’s a huge well of wonderful generative things that have yet to be explored (for instance, that procedural modelling of buildings paper is AMAZING). I’m very interested in collaborating with others! Shoot me an email at (zhangxiaohan at berkeley dot edu) and lets do something!

  3. […] previous explorations really taught me that I had absolutely NO CLUE how to spherical geometry, so I’ve spent these […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s