Skip to main content

Heightmap landscape generator which allows to generate and modify infinite size 2d worlds.

Project description

world map generator

Main idea

Fractal heightmap generator allows you to create infinite self-linked maps generated randomly from seed.

Main advantages:

  • borderless transitions in maps generated with different versions of this program or different seeds
  • automatic smooth transitions between biomes
  • customizable biomes impact
  • biomes distribution can be generated according to your own conditions

How to use

Basic heightmap generation

To generate basic heightmap you can use fractal generator based on diamond square algorithm. Generators will return information in chunks:

generator = FractalGenerator(seed, chunk_width, base_grid_distance, base_grid_max_value)
height_map_chunk = generator.generate_chunk(x, y)

Chunks could be packed in Maps for better manipulations with them:

height_map = Map(seed, chunk_width)
height_map.set_chunk(height_map_chunk)

Bounding can be used to generate rectangle of chunks:

bounding = Bounding(0, 0, 8, 8)
bounding.for_each(lambda x, y: height_map.set_chunk(generator.generate_chunk(x, y)))

It will generate heightmap like this:

Basic biome generation

Biomes can be used to modify generated heightmaps. In biome maps single tile can be part of few biomes with different weights. A single tile can belong to multiple biomes with corresponding weights.

Default biomes generation is based on voronoi diagram. In this realisation each cell of voronoi diagram will be placed close to corresponding biome grid nodes. Neighbouring cells will be automatically blended near separation line with a little bit of noise (dithering).

To make separation lines between neighbouring cells not as sharp biomes generator use additional shift_map. Shift map is analog of heightmap but scaled from 0 to 1. Also shift map is 1 chunk wider to the right to use it as shift map for both axes. So shift map could be generated like this:

shift_map = Map(height_map.seed + 1, chunk_width=chunk_width)
shift_generator = FractalGenerator(shift_map.seed, chunk_width, base_grid_distance, 1)
wider_bounding = Bounding(0, 0, 1, 0)
wider_bounding.add_bounding(bounding)
wider_bounding.for_each(lambda x, y: shift_map.set_chunk(shift_generator.generate_chunk(x, y)))

Ofcourse you need to set up biome types before generating biome map. Mainly biome parameters will affect function of biome distribution and heightmap modification process later.

biome_example_1 = BiomeType(title='biome 1',
                            biome_parameters={'appearance_weight': 2},
                            height_modification=your_modifier_1)
biome_example_2 = BiomeType(title='biome 2',
                            biome_parameters={'appearance_weight': 0.5},
                            height_modification=your_modifier_2)

Also, you need to set your own function of biome distribution. For example random biome distribution according to weights:

biome_types_pool = [biome_example_1, biome_example_2]
biomes_weights = [b.biome_parameters['appearance_weight'] for b in biome_types_pool]
biomes_cumulative_distribution = get_cumulative_distribution_list(biomes_weights)


def get_random_biome_example(biome_node_x: int, biome_node_y: int, seed: int) -> BiomeType:
    pos_seed = get_position_seed(biome_node_x, biome_node_y, seed + 69)
    biome_index = weighted_random_selection(biomes_cumulative_distribution, pos_seed)
    return biome_types_pool[biome_index]

Then you can finally generate biome map using your own get_biome_type method to set biome distribution:

biome_map = Map(seed, chunk_width=chunk_width)
biome_generator = BiomeGenerator(biome_map.seed, chunk_width, biome_grid_step, biome_blend_radios,
                                 get_biome_type)
bounding.for_each(lambda x, y: biome_map.set_chunk(biome_generator.generate_chunk(x, y, [shift_map])))

It will generate biome map like this:

Using biomes to modify heightmaps

When you have biome map you can modify any heightmap with height_modification function set in each biome.

modifier = MapModifier(biome_map.seed, chunk_width)
bounding.for_each(modify_heightmap_chunk)
bounding.for_each(lambda x, y: height_map.set_chunk(modifier.modify_heightmap_chunk(x, y,
                                                    height_map.get_chunk(x, y),
                                                    biome_map.get_chunk(x, y))))

If there are few biomes at handling tile so the resulting value will be the summ of weighted results for all biomes.

Modified heightmap will look like this:

Applied to 3D mesh modified heightmap will look like this:

For more details, see this example: biome usage example.

Your modification methods can use another maps like in this example: value maps in modifiers example.

Saving maps as images

You can save height maps and biome maps as png for better result representation:

save_height_map_as_image(height_map, 'heightmap', max_color_value=1.5*base_grid_max_value)
save_biome_map_as_image(biome_map, 'biomes_map')

Map composing

You can use MapComposer to combine few maps into one new: map composing example.

Map distortion

You can distort maps with DistortionGenerator using any shift map you want: distortion maps example.

Round structures maps

You can generate round structures with DotsGenerator: round structures example.

More examples

One of the common noise realizations is ridged noise. It's realization with distortion will look like this:

See realization here: ridged noise example.

You can see more code examples here: examples

Contact

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

world_map_generator-0.3.0.tar.gz (29.5 kB view details)

Uploaded Source

Built Distribution

world_map_generator-0.3.0-py3-none-any.whl (32.6 kB view details)

Uploaded Python 3

File details

Details for the file world_map_generator-0.3.0.tar.gz.

File metadata

  • Download URL: world_map_generator-0.3.0.tar.gz
  • Upload date:
  • Size: 29.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.0 CPython/3.12.4

File hashes

Hashes for world_map_generator-0.3.0.tar.gz
Algorithm Hash digest
SHA256 a3e067fb4a6e2aa8a9decd1c506521ed39702e0c4a0ece5b672d738c658cde36
MD5 2e3e16ca079fed42cdab5e2c92b0a93f
BLAKE2b-256 8a1b6c185a95e3b35e5101f46f940588169abff0610d74cdbb76ce510c173981

See more details on using hashes here.

File details

Details for the file world_map_generator-0.3.0-py3-none-any.whl.

File metadata

File hashes

Hashes for world_map_generator-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9106de1eafc338d3b1bcbc45c71b70cc96a537d6ea2af9d3cbe9d6bca275907b
MD5 306fb2b60bc9ae7504f4968f26ae0e12
BLAKE2b-256 39c76d33bfa05e90fef34ced33da723c2635ac1e2b8644fc9e78d0501fe4edac

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page