Water & Earth

Thus far, I’ve explained the basic premise of SagaSim and described how to generate a basic landscape through fractal noise. Now, it’s time to put that noise to work and create land masses!

One of the input parameters to the world generator is “water percentage.” Maybe you want a world that’s like Earth, where roughly 70% of the surface is covered by water. Maybe you want much more land, so you go down to 50%. Maybe you want no ocean at all, so you put in 0%. There is no point in putting in 100%, though, since it means no biomes or climate data would be generated (sorry.) Anyway, let’s start with 70%. I’m generating a larger map this time, so you can really see the features of the landscape.

[caption id=“attachment_32” align=“alignnone” width=“600”]basic noise map Perlin noise before any additional processing.[/caption]

Where does the land end and the water begin? You can’t tell from this map. Instead, I have an algorithm that “normalizes” the map. What it does is go through each pixel, put it in an array (a list), and then it slices the array at whatever point you entered as your water percentage. So, if you chose 70% and had an image that’s 10,000 pixels in total (100x100), the value of the pixel at index 7000 would represent our new “base” color. All pixels below that will be turned to black, then all the pixels above index 7000 get adjusted. Since the sea level value will likely be some shade of gray, and we’re turning it into black, we therefore need to tweak all the lighter-colored pixels so that they now start just one shade above black. In computer graphics parlance, this is known as “stretching the histogram.“ Let’s see what the map looks like after this processing has been done:

[caption id=“attachment_33” align=“alignnone” width=“600”]normalized noise map Map after normalizing the sea level.[/caption]

Now, the locations of land masses are much clearer. But the world generator takes one more step to make clear the distinction between ocean and land: it creates a “mask” where all land is white, and all water is black. That way, it’s never ambiguous as to whether a given pixel is meant to be land or ocean. (Rivers are another story, and will be covered in a future post.)

[caption id=“attachment_34” align=“alignnone” width=“600”]water mask Map converted to water mask. White is land, black is water.[/caption]

Much clearer, isn’t it? You can also see that there are five distinct continents, as well as some smaller islands. Here are a few more water masks to illustrate the variety of landforms you can get just by tweaking some of the world generation parameters:

[caption id=“attachment_35” align=“alignnone” width=“600”]water mask example Water mask generated from 0.2 persistence, 4 octaves, lacunarity of 8, 70% water coverage.[/caption]

[caption id=“attachment_36” align=“alignnone” width=“600”]water mask example Water mask generated from 0.8 persistence, 8 octaves, lacunarity of 2, 30% water coverage.[/caption]

[caption id=“attachment_37” align=“alignnone” width=“600”]water mask example Water mask generated from 0.2 persistence, 4 octaves, lacunarity of 16, 50% water coverage.[/caption]

As you can see, there’s plenty of variety to be had by messing with the world generation parameters.

So, now we’ve got our land and oceans set up. Next time, we move on to terrain and climate!