Skip to content

An experiment with adapting my world map generator to create height maps using cellular automata.

Notifications You must be signed in to change notification settings

dylanpruitt/topographic-map-generator

Repository files navigation

Topographic Map Generator

This project uses a simple algorithim to generate an array of height values, which is then displayed in text format.

Height map render


Generation Process

A max height value is given to the generator; in this project, it is set to 9.

The generator starts at height 0 and works its way up to 9, and for each height value:

The generator goes through every tile in the map (a vector of integers), and if the tile is that height value, there is a chance that the tile will be elevated.

for (int i = 0; i < map_size; i++) {
    for (int j = 0; j < map_size; j++) {
        int height_update_chance = base_chance * ((double) get_number_of_surrounding_tiles_at_height(i, j, height) / 9);
        int random = rand () % 100 + 1;
        int index = i + j * map_size;

        if (random <= height_update_chance && height_map [index] == height) {
            height_map [index] = height + 1;
        }
    }
}

After the map is updated, the generator looks at each tile again to smooth out the map.

for (int i = 0; i < map_size; i++) {
    for (int j = 0; j < map_size; j++) {
        int index = i + j * map_size;
        if (height_map [index] == height - 1 && get_number_of_surrounding_tiles_at_height (i, j, height) >= 6) {
            height_map [index] = height;
        }

        if (height_map [index] == height && get_number_of_surrounding_tiles_at_height (i, j, height) < 2) {
            height_map [index] = height - 1;
        }
    }
}

This is what the process looks like for each step:

Generation part 1
Generation part 2
Generation part 3

About

An experiment with adapting my world map generator to create height maps using cellular automata.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages