GLBasic forum

Codesnippets => Code Snippets => Topic started by: Scott_AW on 2010-Oct-15

Title: Perlin-Free world generation
Post by: Scott_AW on 2010-Oct-15
I was somehow interested in world generation, while playing Dune 2000(its free now) and wasting time.  Then I had a bunch of thoughts that eventually led me to world generation.

I'll save you from the chain-like tangent that brought me to this....

Anyway I first started looking it, checking out perlin noise.  Now I kind of get it, but then not enough to feel comfortable using.  So I started looking for, then found a nice alternative.  Unfortunatly I can't recall the link, but it had a nice few sentences that described how you can generate semi-realistic worlds with a simple alogorithm.

You start out with a world array and a stack array for storing positions.

Fill in a few random places with land and water tiles, saving those locations in the stack.

Then scan through the stack, checking 8 direction around of tile and then setting them up either land or water.  If the home tile is water, all adjacent tiles turn to water.

Download (
Code attached at the bottom, references to images in the demo above.

Its not perfect perfect, but I'm sure with a little toying around you can get it to do what you want.

Oh, and add this line after //set grassy areas in sand
Code: GLBasic [Select]
// Remove sand from grass
      IF world[sx][sy] = 2 AND (range[0] > 1 AND range[1] > 1 AND range[2] > 1 AND range[3] > 1) ; world[sx][sy] = 3 ; CONTINUE ; ENDIF

Heres a more recent screenshot/demo, I plan on uploading the updated code sometime soon.

Download (

Photoshopped the mini map into that.

[attachment deleted by admin]
Title: Re: Perlin-Free world generation
Post by: Hatonastick on 2010-Oct-18
What would be interesting is to use a Perlin-like algorithm with a very low noise level as a first pass, then have this algorithm clean it all up.  Looking at your screen shot there are obvious patterns so it currently isn't really as random as it should be -- assuming that's due to the random number generator and not a fault in the algorithm.

Another possibility is to see whether the Mersenne Twister PRNG ( ( as a replacement RNG makes any difference to the output.

Pretty cool though what you've got there.  Generated content has long been an interest of mine.
Title: Re: Perlin-Free world generation
Post by: erico on 2010-Oct-18
that loooooks reaaaaly interesting! congrats!
Title: Re: Perlin-Free world generation
Post by: Scott_AW on 2010-Oct-19
Still needs some touching up, I'll wait til it produces a little better.

Might try it with other map generation types.