February 10, 2013

I've been doing some research on terrain generation algorithms, and they are defined here as an algorithm that generates a random "heightmap". A heightmap is an image which is black and white, where the difference between the black and white is the height of the map. You could do these in some random paint-software, but if you need them to be random each time, you have to make an algorithm. For example, the game environment in Minecraft is random each time the game begins.

Random

This is the random version:

Sparks

This was the first algorithm I tried, I don't believe it has a name, but I named it Sparks. The idea is that you generate several random points and to each point you say that the area surrounding the point should be either land or sea. This was the result:

Particle Deposition

This algorithm uses the same algorithm as a volcano uses when a volcano generates terrain, but without the volcano. The idea is that you fire the rocks from the volcano on to your map, each time a rock lands on the current ground, you have to check if the rock can continue to roll down, if so roll it down, and if not, don't move the rock. This image explains the process:

Value Noise

I believe that this is the algorithm used in Minecraft. Markus "Notch" Persson, the creator of Minecraft, has written a shorter post on the terrain generation in Minecraft. According to the blog post, he claims that he used Perlin Noise, but Perlin Noise and Value Noise are similar and are often confused with each other. Anyway, here's the result from Value Noise:

More details and higher resolution. The resolution here is 320x240 and it took about 5 seconds to generate this image (about 1-2 seconds to generate the heightmap itself, the rest of the time is what it took to display the heightmap with Python), so the algorithm is so far the fastest one:

A heightmap generated with the same algorithm:

Diamond Square

If you would like to see Notch code a random terrain algorithm, you can watch him code one when he is creating the game "Minicraft" here: Twitch (begins at around 3:28:00). I believe that he was coding some kind of modified Diamond Square algorithm and I decided to make a similar algorithm. Here's the result:

And here's the island-version compared with an island from Google Maps, the size is 512x512 and it took about 2.6 seconds to generate the coordinates:

You can easily create a more smoother map by taking the average of the height of the 9 surrounding coordinates at each coordinate. The smooth version with smaller beaches:

Other algorithms

If you are not satisfied with Value Noise, you might want to check out:

Perlin Noise (make sure the author of the articles you find has not confused Perlin Noise with Value Noise)

Social media

Follow me on Twitter

Disclaimer

This blog and website are for informational, educational and discussion purposes only. Even though topics may be discussed on this blog that involve legal or investment issues, nothing on this blog shall be deemed to constitute the practice of law, legal advice or investment advice. If any reader takes action or makes decisions based solely on the information on this blog, the reader does so at his or her own risk.

Habrador will on occasion post links to information on other websites. Such links and the information thereon are not under Habrador’s control. Merely because a link to a third party site appears in this blog does not mean that Habrador has reviewed or approved of the link and its content.