Terrain Generator
I wrote a terrain generator in Java the other day, inspired by several discussions. Here are some screenshots:
The algorithm is roughly as follows:
- We start with a map comprised of large blocks. The default block size is 64 by 64. The state of each block (land or water) is entirely pseudorandom.
- Repeat until all blocks are 1 by 1 in size:
- Divide each block into four smaller blocks.
- For each derived block, decide on a probability for that block becoming a land block. This probability is based on the state of the block it was derived from, and the land mass of surrounding blocks. The probability computation can be configured in different ways with different weights.
- If a pseudorandom number between 0 and 1 is less than that probability, the derived block becomes a land block. Otherwise, it becomes a water block.
- Darken land blocks which are contiguous with water blocks.
Here is a runnable JAR to play around with. You can also view the source code, although it may be difficult to understand the algorithm from the code alone.
Posted in Java at December 25th, 2009. 18,710 Comments.

