Random Heightmap Generator

Until now I have been using perlin noise classes from other sources to make my procedural worlds. I didn’t really like the idea of using classes from others for it, so I made my own class from scratch to get the results I need, with a total different approach. I am unsure how I came up with this idea, I just did, and it worked. It needs a lot of tweaking still, but it’s starting to look like what I hoped it would do.

I found this picture, which basically explains what I am trying to do.


Theory (not practice): Step 1:

Create a small 2D array, with random integers, this is done at the point you make the class instance. The class takes 3 parameters, Seed, Resolution, and Height, Seed is the seed for the randomizer, Resolution is the width and height for the default array (a resolution of either 4 or 8 works best, but for this example we use 2.) and last, height. Height is the upper bound of the randomizer. The lower bound is always zero. So, lets initiate the class. The StartMap[][] is being made. The resolution is 2 and the height is 10.

Depending on the seed, the output may look something like this:

step 1

Step 2:

Give it the first pass, what the pass does, is make a new array, with double the resolution of the previous pass. Because we didn’t have a pass before, we are going to use the startmap. Call pass(startmap). It creates the new array with double the resolution, and applies a simple formula to fill the array relative to the old array. The relative positions for the old values look like this.

step 2

Now, for each int, in the 2 dimensional array, it’s going to take the average between the two closest relative locations. On top of the average, it’s going to add (or substract) a slight random value. The outcome should look something like this.

step 3

So, when you apply several passes, the resolution of the map gets bigger and bigger. After 3 or 4 passes you will have a coherent random map of the size like the screenshot above.

I still have a lot of thinking to do to let it do exactly this, but I am getting there. The code as is, could be used as a heightmap, you get a 2D array of integers, which could be translated to the z axis for points in a plane, so you get procedural terrain :).