Skip to content

Commit 91ebf28

Browse files
committed
Finished icecap generation and added option to write out an ice map.
1 parent 474609f commit 91ebf28

3 files changed

Lines changed: 30 additions & 15 deletions

File tree

worldengine/cli/main.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
from worldengine.common import array_to_matrix, set_verbose, print_verbose
88
from worldengine.draw import draw_ancientmap_on_file, draw_biome_on_file, draw_ocean_on_file, \
99
draw_precipitation_on_file, draw_grayscale_heightmap_on_file, draw_simple_elevation_on_file, \
10-
draw_temperature_levels_on_file, draw_riversmap_on_file, draw_scatter_plot_on_file, draw_satellite_on_file
10+
draw_temperature_levels_on_file, draw_riversmap_on_file, draw_scatter_plot_on_file, \
11+
draw_satellite_on_file, draw_icecaps_on_file
1112
from worldengine.plates import world_gen, generate_plates_simulation
1213
from worldengine.imex import export
1314
from worldengine.step import Step
@@ -87,6 +88,10 @@ def draw_satellite_map(world, filename):
8788
draw_satellite_on_file(world, filename)
8889
print("+ satellite map generated in '%s'" % filename)
8990

91+
def draw_icecaps_map(world, filename):
92+
draw_icecaps_on_file(world, filename)
93+
print("+ icecap map generated in '%s'" % filename)
94+
9095
def generate_plates(seed, world_name, output_dir, width, height,
9196
num_plates=10):
9297
"""
@@ -322,9 +327,10 @@ def main():
322327
default=True)
323328
g_generate.add_argument('--scatter', dest='scatter_plot',
324329
action="store_true", help="generate scatter plot")
325-
326330
g_generate.add_argument('--sat', dest='satelite_map',
327331
action="store_true", help="generate satellite map")
332+
g_generate.add_argument('--ice', dest='icecaps_map',
333+
action="store_true", help="generate ice caps map")
328334

329335
# -----------------------------------------------------
330336
g_ancient_map = parser.add_argument_group(
@@ -480,6 +486,7 @@ def main():
480486
print(' black and white maps : %s' % args.black_and_white)
481487
print(' step : %s' % step.name)
482488
print(' greyscale heightmap : %s' % args.grayscale_heightmap)
489+
print(' icecaps heightmap : %s' % args.icecaps_map)
483490
print(' rivers map : %s' % args.rivers_map)
484491
print(' scatter plot : %s' % args.scatter_plot)
485492
print(' satellite map : %s' % args.satelite_map)
@@ -543,7 +550,10 @@ def main():
543550
'%s/%s_scatter.png' % (args.output_dir, world_name))
544551
if args.satelite_map:
545552
draw_satellite_map(world,
546-
'%s/%s_satellite.png' % (args.output_dir, world_name))
553+
'%s/%s_satellite.png' % (args.output_dir, world_name))
554+
if args.icecaps_map:
555+
draw_icecaps_map(world,
556+
'%s/%s_icecaps.png' % (args.output_dir, world_name))
547557

548558
elif operation == 'plates':
549559
print('') # empty line

worldengine/draw.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,7 @@ def draw_satellite(world, target):
395395
target.set_pixel(x, y, (r, g, b, 255))
396396

397397
# Paint frozen areas.
398+
ice_color_variation = int(30) # 0 means perfectly white ice; must be in [0, 255]; only affects R- and G-channel
398399
for y in range(world.height):
399400
for x in range(world.width):
400401
if world.icecap[y, x] > 0.0:
@@ -817,3 +818,8 @@ def draw_satellite_on_file(world, filename):
817818
img = PNGWriter.rgba_from_dimensions(world.width, world.height, filename)
818819
draw_satellite(world, img)
819820
img.complete()
821+
822+
823+
def draw_icecaps_on_file(world, filename):
824+
img = PNGWriter.grayscale_from_array(world.icecap, filename, scale_to_range=True)
825+
img.complete()

worldengine/simulations/icecap.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ def is_applicable(world):
1515

1616
def execute(self, world, seed):
1717
world.icecap = self._calculate(world, seed)
18-
print("icecap written!!!!!!!!")
19-
print(hasattr(world, 'icecap'))
2018

2119
@staticmethod
2220
def _calculate(world, seed):
@@ -31,14 +29,14 @@ def _calculate(world, seed):
3129
temperature = world.temperature['data']
3230

3331
# primary constants (could be used as global variables at some point); all values should be in [0, 1]
34-
max_freeze_percentage = 0.50 # only the coldest x% of the cold area will freeze (0 = no ice, 1 = all ice)
35-
freeze_chance_window = 0.10 # the warmest x% of freezable area won't completely freeze (RNG decides)
32+
max_freeze_percentage = 0.60 # only the coldest x% of the cold area will freeze (0 = no ice, 1 = all ice)
33+
freeze_chance_window = 0.20 # the warmest x% of freezable area won't completely freeze (RNG decides)
3634
surrounding_tile_influence = 0.5 # chance-modifier to freeze a slightly warm tile when neighbors are frozen
3735

3836
# secondary constants
3937
temp_min = temperature.min() # coldest spot in the world
4038
freeze_threshold = world.temperature['thresholds'][0][1] # upper temperature-limit for freezing effects
41-
# Cold biomes:
39+
# Cold biomes: TODO: find and pick most appropriate threshold
4240
# polar: self.temperature['thresholds'][0][1]
4341
# alpine: self.temperature['thresholds'][1][1]
4442
# boreal: self.temperature['thresholds'][2][1]
@@ -65,13 +63,14 @@ def _calculate(world, seed):
6563
# *can* freeze for freeze_chance_threshold < t < freeze_threshold
6664

6765
# count number of frozen/solid tiles around this one
68-
surr_tiles = solid_map[max(y-1, 0):min(y+2, world.height), max(x-1, 0):min(x+2, world.width)]
69-
chance_mod = numpy.count_nonzero(surr_tiles)
70-
chance_mod -= 1 if solid_map[y, x] else 0 # remove center-tile (i.e. the current tile)
71-
72-
# map amount of tiles to chance-modifier, [-1.0, 1.0]
73-
chance_mod = numpy.interp(chance_mod, [0, 4, 8], [-1.0, 0.0, 1.0]) # 0 to 8 tiles are frozen
74-
chance += chance_mod * surrounding_tile_influence
66+
if 0 < x < world.width - 1 and 0 < y < world.height - 1: # exclude borders
67+
surr_tiles = solid_map[y-1:y+2, x-1:x+2]
68+
chance_mod = numpy.count_nonzero(surr_tiles)
69+
chance_mod -= 1 if solid_map[y, x] else 0 # remove center-tile (i.e. the current tile)
70+
71+
# map amount of tiles to chance-modifier, [-1.0, 1.0]
72+
chance_mod = numpy.interp(chance_mod, [0, surr_tiles.size - 1], [-1.0, 1.0])
73+
chance += chance_mod * surrounding_tile_influence
7574

7675
if rng.rand() <= chance: # always freeze for chance >= 1.0, never for <= 0.0
7776
solid_map[y, x] = True # mark tile as frozen

0 commit comments

Comments
 (0)