Friday, 29 January 2010

Terrain Generation

Time for another post and another experiment. I was just reading an interesting paper called Procedural Techniques For City Generation by some chaps in working at the ITB in ireland all about how to generate completely algorithmic city plans given a starting point and a landscape to build on. The image below shows an example of some of the stuff that can be produced with these algorithms and it truly is amazing!

Anyway I thought I'd step back a bit and try to produce some of my own landscapes to start with, and then move onto road generation and finally buildings. Its always nice to start with the easy stuff, that way I find at least I get something done!

Since the actionscript random function generates a new random seed each time a program is run I decided to use a custom random number function which could take a seed. The generator I used is the Park-Millar-Carter PRNG which is ideal for the job. I like the idea of using words (like in the original worms) as seeds so using an input string, eg "Terrain1" and then taking an MD5 hash of it, converting this into a number provided a constant seed for a word. The seed would generate every piece of information in the same way every time, very useful when you find an interesting image.

So I built this in then created several layers of bitmap data, each with different resolution with each pixel on each grid set to a random value (in the range [0,0xFF]). The resulting addition of all the bitmaps would produce the data for my final landscape. Here are a few examples of the kinds of landscapes I was able to produce:

To me the third image is a spitting image of europe, with spain, germany and france and even the UK to the very top left! I'm quite happy with the results all in all. To try out the app for yourselves just click here, enter a keyword, and press generate!

Next Step, build some roads!

No comments:

Post a Comment