terrain generator

  scripts
  sprites
See inside
Notes and Credits

Updated, to make use of Scratch 2 blocks. It is probably quick enough to generate terrain on the fly for a game now.

Stop press - as it is featured: this project is made for remixing. Use it in a game of your own!

Once again, a technique for anybody to pick up: this is an algorithm for randomly generating a realistic terrain.

How it works:
first, it chooses a height at both ends, for example, -100 and +200.

Then the height in the middle would be 50 (the average). Instead it changes that height randomly, let's say to 0. We see a line broken in two.

The first half of the broken line, its middle is at height -50. The generator changes that, randomly, by a few pixels - to -30 let's say.

The second half of the broken line was between 0 and 200. The normal height would be 100; change that randomly to 130.

Now the line is broken in four pieces, giving an overall irregular shape - bu not too irregular. To make it in more detail, we can break the sections in the middle again, giving 8 parts, and break it again, in 16 parts, etc. The algorithm repeats the same pattern as the level of detail increases: it is fractal.

The "ruggedness" decides the range for picking up the height of the terrain. If it is set to 200, the heights are picked between -200 and +200 at first. At the next level of detail, the height is changed by somewhere between -100 to +100, at the next level changed by between -50 to +50, etc.

The calculation takes time - this is scratch! You can change how much detail to calculate, and less detail is quicker.

Enjoy,
Charles

Shared: 29 Apr 2009 Modified: 17 Apr 2014
Favorite this project 33
Love this project 41
Total views 754
View the remix tree  8
  
More projects by boisvert