2D terrain generation using pseudorandom numbers

  • Login [optional]

  • Controls

In case you wanted to know about terrain generation using pseudorandom noise

The terrain is generated by creating a 2D random wave with frequency scale.

In this algorithm, the wave was created by using two pseudorandom generators one for x and one for y, and using these to set gradient vectors at the corner of each grid square. A Perlin-type process was used to generate the terrain-heights. Because the wave is pseudorandom, the terrain is the same each time it is generated. Because the random numbers can be generated infinitely, the terrain can scroll infinitely, being generated as needed*.

This same wave is used octave times, added to itself. Each added wave is compressed by lacunarity to increase its frequency, and its amplitude is multiplied by persistence to reduce it. This effectively adds smaller elements of terrain, possibly interpreted as boulders, then pebbles, etc. A key feature of this random terrain generation method is that the original random wave is not just random. It has an exact frequency of scale, and so is always zero at multiples of scale. This means that major terrain features (octave zero) repeat regularly.

[*Because the pseudorandom generators used here have periods 41 and 43 respectively, and with default 5 octaves and scale of 60, the terrain will in fact repeat at 41 × 43 × 60 × 25 = 3,384,960 units.]