Skip to content

Commit 4382928

Browse files
committed
Fixes to make the ocean_level-variable work properly.
1 parent 85891b4 commit 4382928

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

worldengine/cli/main.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pickle
66
import random
77
import worldengine.generation as geo
8+
from worldengine.simulations.basic import find_threshold_f
89
from worldengine.common import array_to_matrix, set_verbose, print_verbose
910
from worldengine.draw import draw_ancientmap_on_file, draw_biome_on_file, draw_ocean_on_file, \
1011
draw_precipitation_on_file, draw_grayscale_heightmap_on_file, draw_simple_elevation_on_file, \
@@ -80,7 +81,7 @@ def generate_rivers_map(world, filename):
8081

8182

8283
def generate_plates(seed, world_name, output_dir, width, height,
83-
num_plates=10):
84+
ocean_level, num_plates=10):
8485
"""
8586
Eventually this method should be invoked when generation is called at
8687
asked to stop at step "plates", it should not be a different operation
@@ -93,6 +94,7 @@ def generate_plates(seed, world_name, output_dir, width, height,
9394
:return:
9495
"""
9596
elevation, plates = generate_plates_simulation(seed, width, height,
97+
ocean_level=ocean_level,
9698
num_plates=num_plates)
9799

98100
world = World(world_name, width, height, seed, num_plates, -1.0, "plates")
@@ -101,8 +103,9 @@ def generate_plates(seed, world_name, output_dir, width, height,
101103

102104
# Generate images
103105
filename = '%s/plates_%s.png' % (output_dir, world_name)
104-
# TODO calculate appropriate sea_level
105-
sea_level = 1.0
106+
sea_level = find_threshold_f(world.elevation['data'], 1.0 - ocean_level,
107+
ocean=None, max=1.0, mindist=0.000005)
108+
106109
draw_simple_elevation_on_file(world.elevation['data'], filename, width,
107110
height, sea_level)
108111
print("+ plates image generated in '%s'" % filename)
@@ -300,7 +303,7 @@ def main():
300303
g_generate.add_argument('--ocean_level', dest='ocean_level', type=float,
301304
help='amount of surface covered by ocean " +'
302305
'[default = %(default)s]',
303-
metavar="N", default=1.0)
306+
metavar="N", default=0.65)
304307

305308
# -----------------------------------------------------
306309
g_ancient_map = parser.add_argument_group(
@@ -463,7 +466,8 @@ def main():
463466
print('starting (it could take a few minutes) ...')
464467

465468
generate_plates(seed, world_name, args.output_dir, args.width,
466-
args.height, num_plates=args.number_of_plates)
469+
args.height, args.ocean_level,
470+
num_plates=args.number_of_plates)
467471

468472
elif operation == 'ancient_map':
469473
print('') # empty line

worldengine/generation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ def initialize_ocean_and_thresholds(world, ocean_level=0.65):
127127
e = world.elevation['data']
128128
#Calculate the height of the ocean relative to the geometry
129129
ocean_maxlevel = find_threshold_f(e, 1.0 - ocean_level,
130-
ocean=None, max=1.0, mindist=0.00001)
130+
ocean=None, max=100.0, mindist=0.00001)
131131
ocean = fill_ocean(e, ocean_maxlevel)
132132

133133
#TODO: The thresholds (and amounts of e.g. mountains) could change for every world, depending on the height above the ocean.

worldengine/plates.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ def world_gen(name, width, height, seed, num_plates=10, ocean_level=0.65,
7575
if verbose:
7676
start_time = time.time()
7777
place_oceans_at_map_borders(world)
78-
initialize_ocean_and_thresholds(world)
78+
initialize_ocean_and_thresholds(world, ocean_level)
7979
if verbose:
8080
elapsed_time = time.time() - start_time
8181
print("...plates.world_gen: oceans initialized. Elapsed time " +

0 commit comments

Comments
 (0)