The algorithm starts with a flat heightmap, i.e. every cell of the map has a height of 0. Then in a number of iterations it modifies the heightmap, creating the final terrain. In every iteration step a line is generated which crosses the map region, this is achieved by randomly choosing two defining points in the map area. Then the height of every cell of the map on one side of the line is increased by a given value (practically by 1). That is, we repeatedly cut the map into two halves randomly, and raise the level of one of them.

After several iterations the heightmap has enough variation. The height values are between 0 and the number of iterations. After finding the minimum and maximum values we can interpolate the height values into any range we want. The number of iterations required to get a good looking terrain depends on the size of the map, larger maps usually require more iterations.

Advantages of this algorithm:

- simplicity
- works for any map size
- scalable (the quality of the terrain can be controlled with the number of iterations)

- high computational cost ( for an W*H sized map and N lines it is O(W*H*N) )
- not "infinite" like perlin noise

The source code is also available: download.

A 256x256 map generated with 1024 lines |

This comment has been removed by the author.

ReplyDelete