Terrainer: terrain generator

  • about  
  • 0/
    Passes
  • Seed size
  • Water chance
  • "smoothing"
  • speed

I stumbled over a thread on a forum about terrain generation using "cellular automata" type algorithms, which, owing to my past flirtings in the area, I found most interesting. Here's an implementation of it in Canvas. The options are:

  • stop/go: make it go and not go!
  • default: drop down with some presets. I like "luna lander".
  • Passes: how many "refinements" the algorithm makes. Because each pass doubles the size of the array to process, don't make this too high!
  • Seed size: the initial size of the array. Smaller arrays make it easier to see what's going on - and provde more "sparse" land shapes
  • Water chance: the chance (from 0 to 1) that an initial cell will contain water
  • "Smoothing": gets rid of some "jaggies" on the coasts by only allowing it to be water if it's surrounded by X other water's (something like that... I forget)
  • Speed: how fast to do each iteration (in ms).

I can't for the life of me find that forum thread, but the basic idea went like this:

  1. Create a small matrix and seed with either water or land
  2. Double the size of the matrix so that each cell now takes up 4 cells
  3. Refine the new big map, selecting land or water based on how many surrounding cells are land or water
  4. Jump back to 2 for a few iterations.

The results are pretty interesting - I love how simple rules can create such intricate fractal-y outcomes. I've put the terrain generation code on GitHub if you want to take a look (beware: it's pretty "loopy")!