def _watermap(world, n): def droplet(world, pos, q, _watermap): if q < 0: return x, y = pos pos_elev = world.elevation['data'][y, x] + _watermap[y, x] lowers = [] min_higher = None min_lower = None # pos_min_higher = None # TODO: no longer used? tot_lowers = 0 for p in world.tiles_around((x, y)): #TODO: switch to numpy px, py = p e = world.elevation['data'][py, px] + _watermap[py, px] if e < pos_elev: dq = int(pos_elev - e) << 2 if min_lower is None or e < min_lower: min_lower = e if dq == 0: dq = 1 lowers.append((dq, p)) tot_lowers += dq else: if min_higher is None or e > min_higher: min_higher = e # pos_min_higher = p if lowers: f = q / tot_lowers for l in lowers: s, p = l if not world.ocean[p[1], p[0]]: px, py = p ql = f * s # ql = q going = ql > 0.05 _watermap[py, px] += ql if going: droplet(world, p, ql, _watermap) else: _watermap[y, x] += q _watermap_data = numpy.zeros((world.height, world.width), dtype=float) for i in range(n): x, y = world.random_land() if True and world.precipitation['data'][y, x] > 0: droplet(world, (x, y), world.precipitation['data'][y, x], _watermap_data) _watermap = dict() _watermap['data'] = _watermap_data _watermap['thresholds'] = dict() _watermap['thresholds']['creek'] = find_threshold_f(_watermap_data, 0.05, ocean=world.ocean) _watermap['thresholds']['river'] = find_threshold_f(_watermap_data, 0.02, ocean=world.ocean) _watermap['thresholds']['main river'] = \ find_threshold_f(_watermap_data, 0.007, ocean=world.ocean) return _watermap
def _watermap(world, n): def droplet(world, pos, q, _watermap): if q < 0: return x, y = pos pos_elev = world.elevation['data'][y, x] + _watermap[y, x] lowers = [] min_higher = None min_lower = None # pos_min_higher = None # TODO: no longer used? tot_lowers = 0 for p in world.tiles_around((x, y)):#TODO: switch to numpy px, py = p e = world.elevation['data'][py, px] + _watermap[py, px] if e < pos_elev: dq = int(pos_elev - e) << 2 if min_lower is None or e < min_lower: min_lower = e if dq == 0: dq = 1 lowers.append((dq, p)) tot_lowers += dq else: if min_higher is None or e > min_higher: min_higher = e # pos_min_higher = p if lowers: f = q / tot_lowers for l in lowers: s, p = l if not world.ocean[p[1], p[0]]: px, py = p ql = f * s # ql = q going = ql > 0.05 _watermap[py, px] += ql if going: droplet(world, p, ql, _watermap) else: _watermap[y, x] += q _watermap_data = numpy.zeros((world.height, world.width), dtype=float) for i in range(n): x, y = world.random_land() if True and world.precipitation['data'][y, x] > 0: droplet(world, (x, y), world.precipitation['data'][y, x], _watermap_data) _watermap = dict() _watermap['data'] = _watermap_data _watermap['thresholds'] = dict() _watermap['thresholds']['creek'] = find_threshold_f(_watermap_data, 0.05, ocean=world.ocean) _watermap['thresholds']['river'] = find_threshold_f(_watermap_data, 0.02, ocean=world.ocean) _watermap['thresholds']['main river'] = \ find_threshold_f(_watermap_data, 0.007, ocean=world.ocean) return _watermap
def execute(self, world, seed): perm = self._calculate(seed, world.width, world.height) perm_th = [ ('low', find_threshold_f(perm, 0.75, world.ocean)), ('med', find_threshold_f(perm, 0.25, world.ocean)), ('hig', None) ] world.set_permeability(perm, perm_th)
def execute(self, world, seed): perm = self._calculate(seed, world.width, world.height) ocean = world.layers['ocean'].data perm_th = [ ('low', find_threshold_f(perm, 0.75, ocean)), ('med', find_threshold_f(perm, 0.25, ocean)), ('hig', None) ] world.permeability = (perm, perm_th)
def execute(self, world, seed): if get_verbose(): start_time = time.time() pre_calculated = self._calculate(seed, world.width, world.height) ths = [('low', find_threshold_f(pre_calculated, 0.75, world.ocean)), ('med', find_threshold_f(pre_calculated, 0.3, world.ocean)), ('hig', None)] world.set_precipitation(pre_calculated, ths) if get_verbose(): elapsed_time = time.time() - start_time print("...precipitations calculated. Elapsed time %f seconds." % elapsed_time)
def _watermap(world, n): def droplet(world, pos, q, _watermap): if q < 0: return x, y = pos pos_elev = world.layers['elevation'].data[y, x] + _watermap[y, x] lowers = [] min_higher = None min_lower = None # pos_min_higher = None # TODO: no longer used? tot_lowers = 0 for p in world.tiles_around((x, y)):#TODO: switch to numpy px, py = p e = world.layers['elevation'].data[py, px] + _watermap[py, px] if e < pos_elev: dq = int(pos_elev - e) << 2 if min_lower is None or e < min_lower: min_lower = e if dq == 0: dq = 1 lowers.append((dq, p)) tot_lowers += dq else: if min_higher is None or e > min_higher: min_higher = e # pos_min_higher = p if lowers: f = q / tot_lowers for l in lowers: s, p = l if not world.is_ocean(p): px, py = p ql = f * s # ql = q going = ql > 0.05 _watermap[py, px] += ql if going: droplet(world, p, ql, _watermap) else: _watermap[y, x] += q _watermap_data = numpy.zeros((world.height, world.width), dtype=float) for i in range(n): x, y = world.random_land() # will return None for x and y if no land exists if x is not None and world.precipitations_at((x, y)) > 0: droplet(world, (x, y), world.precipitations_at((x, y)), _watermap_data) ocean = world.layers['ocean'].data thresholds = dict() thresholds['creek'] = find_threshold_f(_watermap_data, 0.05, ocean=ocean) thresholds['river'] = find_threshold_f(_watermap_data, 0.02, ocean=ocean) thresholds['main river'] = find_threshold_f(_watermap_data, 0.007, ocean=ocean) return _watermap_data, thresholds
def execute(self, world, seed): if get_verbose(): start_time = time.time() pre_calculated = self._calculate(seed, world) ths = [ ('low', find_threshold_f(pre_calculated, 0.75, world.ocean)), ('med', find_threshold_f(pre_calculated, 0.3, world.ocean)), ('hig', None) ] world.set_precipitation(pre_calculated, ths) if get_verbose(): elapsed_time = time.time() - start_time print( "...precipitations calculated. Elapsed time %f seconds." % elapsed_time)
def execute(self, world, seed): if get_verbose(): start_time = time.time() pre_calculated = self._calculate(seed, world) ocean = world.layers['ocean'].data ths = [ ('low', find_threshold_f(pre_calculated, 0.75, ocean)), ('med', find_threshold_f(pre_calculated, 0.3, ocean)), ('hig', None) ] world.precipitation = (pre_calculated, ths) if get_verbose(): elapsed_time = time.time() - start_time print( "...precipitations calculated. Elapsed time %f seconds." % elapsed_time)
def initialize_ocean_and_thresholds(world, ocean_level=1.0): """ Calculate the ocean, the sea depth and the elevation thresholds :param world: a world having elevation but not thresholds :param ocean_level: the elevation representing the ocean level :return: nothing, the world will be changed """ e = world.elevation['data'] ocean = fill_ocean(e, ocean_level) hl = find_threshold_f(e, 0.10) ml = find_threshold_f(e, 0.03) e_th = [('sea', ocean_level), ('plain', hl), ('hill', ml), ('mountain', None)] world.set_ocean(ocean) world.set_elevation(e, e_th) world.sea_depth = sea_depth(world, ocean_level)
def _calculate(world): humids = world.humids humidity = dict() precipitationWeight = 1.0 irrigationWeight = 3 humidity['data'] = numpy.zeros((world.height, world.width), dtype=float) humidity['data'] = (world.precipitation['data'] * precipitationWeight - world.irrigation * irrigationWeight)/(precipitationWeight + irrigationWeight) # These were originally evenly spaced at 12.5% each but changing them # to a bell curve produced better results humidity['quantiles'] = {} humidity['quantiles']['12'] = find_threshold_f(humidity['data'], humids[6], world.ocean) humidity['quantiles']['25'] = find_threshold_f(humidity['data'], humids[5], world.ocean) humidity['quantiles']['37'] = find_threshold_f(humidity['data'], humids[4], world.ocean) humidity['quantiles']['50'] = find_threshold_f(humidity['data'], humids[3], world.ocean) humidity['quantiles']['62'] = find_threshold_f(humidity['data'], humids[2], world.ocean) humidity['quantiles']['75'] = find_threshold_f(humidity['data'], humids[1], world.ocean) humidity['quantiles']['87'] = find_threshold_f(humidity['data'], humids[0], world.ocean) return humidity
def _calculate(world): humidity = dict() humidity['data'] = [[0 for x in xrange(world.width)] for y in xrange(world.height) ] # TODO: replace with numpy for y in xrange(world.height): for x in xrange(world.width): humidity['data'][y][x] = world.precipitation['data'][y][x] + \ world.irrigation[y][x] # These were originally evenly spaced at 12.5% each but changing them # to a bell curve produced better results humidity['quantiles'] = {} humidity['quantiles']['12'] = find_threshold_f(humidity['data'], 0.02, world.ocean) humidity['quantiles']['25'] = find_threshold_f(humidity['data'], 0.09, world.ocean) humidity['quantiles']['37'] = find_threshold_f(humidity['data'], 0.26, world.ocean) humidity['quantiles']['50'] = find_threshold_f(humidity['data'], 0.50, world.ocean) humidity['quantiles']['62'] = find_threshold_f(humidity['data'], 0.74, world.ocean) humidity['quantiles']['75'] = find_threshold_f(humidity['data'], 0.91, world.ocean) humidity['quantiles']['87'] = find_threshold_f(humidity['data'], 0.98, world.ocean) return humidity
def _calculate(world): humidity = dict() temperatureWeight = 2.3 precipitationWeight = 1.0 irrigationWeight = 3 humidity['data'] = [[0 for x in range(world.width)] for y in range(world.height)] # TODO: replace with numpy for y in range(world.height): for x in range(world.width): humidity['data'][y][x] = (((world.precipitation['data'][y][x] * precipitationWeight - world.irrigation[y][x] * irrigationWeight)+1) * ((world.temperature_at((x, y)) * temperatureWeight + 1.0)/(temperatureWeight + 1.0))) # These were originally evenly spaced at 12.5% each but changing them # to a bell curve produced better results humidity['quantiles'] = {} humidity['quantiles']['12'] = find_threshold_f(humidity['data'], 0.002, world.ocean) humidity['quantiles']['25'] = find_threshold_f(humidity['data'], 0.014, world.ocean) humidity['quantiles']['37'] = find_threshold_f(humidity['data'], 0.073, world.ocean) humidity['quantiles']['50'] = find_threshold_f(humidity['data'], 0.236, world.ocean) humidity['quantiles']['62'] = find_threshold_f(humidity['data'], 0.507, world.ocean) humidity['quantiles']['75'] = find_threshold_f(humidity['data'], 0.778, world.ocean) humidity['quantiles']['87'] = find_threshold_f(humidity['data'], 0.941, world.ocean) return humidity
def _calculate(world): humidity = dict() humidity['data'] = [[0 for x in xrange(world.width)] for y in xrange(world.height)] # TODO: replace with numpy for y in xrange(world.height): for x in xrange(world.width): humidity['data'][y][x] = world.precipitation['data'][y][x] + \ world.irrigation[y][x] # These were originally evenly spaced at 12.5% each but changing them # to a bell curve produced better results humidity['quantiles'] = {} humidity['quantiles']['12'] = find_threshold_f(humidity['data'], 0.02, world.ocean) humidity['quantiles']['25'] = find_threshold_f(humidity['data'], 0.09, world.ocean) humidity['quantiles']['37'] = find_threshold_f(humidity['data'], 0.26, world.ocean) humidity['quantiles']['50'] = find_threshold_f(humidity['data'], 0.50, world.ocean) humidity['quantiles']['62'] = find_threshold_f(humidity['data'], 0.74, world.ocean) humidity['quantiles']['75'] = find_threshold_f(humidity['data'], 0.91, world.ocean) humidity['quantiles']['87'] = find_threshold_f(humidity['data'], 0.98, world.ocean) return humidity
def _calculate(world): humidity = dict() temperatureWeight = 2.3 precipitationWeight = 1.0 irrigationWeight = 3 humidity['data'] = numpy.zeros((world.height, world.width), dtype=float) humidity['data'] = (((world.precipitation['data'] * precipitationWeight - world.irrigation * irrigationWeight) + 1) * ((world.temperature['data'] * temperatureWeight + 1) / (temperatureWeight + 1))) # These were originally evenly spaced at 12.5% each but changing them # to a bell curve produced better results humidity['quantiles'] = {} humidity['quantiles']['12'] = find_threshold_f(humidity['data'], 0.002, world.ocean) humidity['quantiles']['25'] = find_threshold_f(humidity['data'], 0.014, world.ocean) humidity['quantiles']['37'] = find_threshold_f(humidity['data'], 0.073, world.ocean) humidity['quantiles']['50'] = find_threshold_f(humidity['data'], 0.236, world.ocean) humidity['quantiles']['62'] = find_threshold_f(humidity['data'], 0.507, world.ocean) humidity['quantiles']['75'] = find_threshold_f(humidity['data'], 0.778, world.ocean) humidity['quantiles']['87'] = find_threshold_f(humidity['data'], 0.941, world.ocean) return humidity
def initialize_ocean_and_thresholds(world, ocean_level=1.0): """ Calculate the ocean, the sea depth and the elevation thresholds :param world: a world having elevation but not thresholds :param ocean_level: the elevation representing the ocean level :return: nothing, the world will be changed """ e = world.layers['elevation'].data ocean = fill_ocean(e, ocean_level) hl = find_threshold_f( e, 0.10) # the highest 10% of all (!) land are declared hills ml = find_threshold_f(e, 0.03) # the highest 3% are declared mountains e_th = [('sea', ocean_level), ('plain', hl), ('hill', ml), ('mountain', None)] harmonize_ocean(ocean, e, ocean_level) world.set_ocean(ocean) world.set_elevation(e, e_th) world.set_sea_depth(sea_depth(world, ocean_level))
def initialize_ocean_and_thresholds(world, ocean_level=1.0): """ Calculate the ocean, the sea depth and the elevation thresholds :param world: a world having elevation but not thresholds :param ocean_level: the elevation representing the ocean level :return: nothing, the world will be changed """ e = world.layers['elevation'].data ocean = fill_ocean(e, ocean_level) hl = find_threshold_f(e, 0.10) # the highest 10% of all (!) land are declared hills ml = find_threshold_f(e, 0.03) # the highest 3% are declared mountains e_th = [('sea', ocean_level), ('plain', hl), ('hill', ml), ('mountain', None)] harmonize_ocean(ocean, e, ocean_level) world.ocean = ocean world.elevation = (e, e_th) world.sea_depth = sea_depth(world, ocean_level)
def execute(self, world, seed): e = world.elevation['data'] ml = world.start_mountain_th() ocean = world.ocean t = self._calculate(world, seed, e, ml) t_th = [('polar', find_threshold_f(t, 0.90, ocean)), ('alpine', find_threshold_f(t, 0.76, ocean)), ('boreal', find_threshold_f(t, 0.59, ocean)), ('cool', find_threshold_f(t, 0.38, ocean)), ('warm', find_threshold_f(t, 0.26, ocean)), ('subtropical', find_threshold_f(t, 0.14, ocean)), ('tropical', None)] world.set_temperature(t, t_th)
def execute(self, world, seed): e = world.layers['elevation'].data ml = world.start_mountain_th( ) # returns how many percent of the world are mountains ocean = world.layers['ocean'].data t = self._calculate(world, seed, e, ml) t_th = [('polar', find_threshold_f(t, world.temps[0], ocean)), ('alpine', find_threshold_f(t, world.temps[1], ocean)), ('boreal', find_threshold_f(t, world.temps[2], ocean)), ('cool', find_threshold_f(t, world.temps[3], ocean)), ('warm', find_threshold_f(t, world.temps[4], ocean)), ('subtropical', find_threshold_f(t, world.temps[5], ocean)), ('tropical', None)] world.temperature = (t, t_th)
def execute(self, world, seed): e = world.layers['elevation'].data ml = world.start_mountain_th() # returns how many percent of the world are mountains ocean = world.layers['ocean'].data t = self._calculate(world, seed, e, ml) t_th = [ ('polar', find_threshold_f(t, world.temps[0], ocean)), ('alpine', find_threshold_f(t, world.temps[1], ocean)), ('boreal', find_threshold_f(t, world.temps[2], ocean)), ('cool', find_threshold_f(t, world.temps[3], ocean)), ('warm', find_threshold_f(t, world.temps[4], ocean)), ('subtropical', find_threshold_f(t, world.temps[5], ocean)), ('tropical', None) ] world.temperature = (t, t_th)
def execute(self, world, seed): e = world.elevation['data'] ml = world.start_mountain_th() ocean = world.ocean t = self._calculate(world, seed, e, ml) t_th = [ ('polar', find_threshold_f(t, 0.874, ocean)), ('alpine', find_threshold_f(t, 0.765, ocean)), ('boreal', find_threshold_f(t, 0.594, ocean)), ('cool', find_threshold_f(t, 0.439, ocean)), ('warm', find_threshold_f(t, 0.366, ocean)), ('subtropical', find_threshold_f(t, 0.124, ocean)), ('tropical', None) ] world.set_temperature(t, t_th)
def _calculate(world): humids = world.humids precipitationWeight = 1.0 irrigationWeight = 3 data = numpy.zeros((world.height, world.width), dtype=float) data = (world.layers['precipitation'].data * precipitationWeight - world.layers['irrigation'].data * irrigationWeight)/(precipitationWeight + irrigationWeight) # These were originally evenly spaced at 12.5% each but changing them # to a bell curve produced better results ocean = world.layers['ocean'].data quantiles = {} quantiles['12'] = find_threshold_f(data, humids[6], ocean) quantiles['25'] = find_threshold_f(data, humids[5], ocean) quantiles['37'] = find_threshold_f(data, humids[4], ocean) quantiles['50'] = find_threshold_f(data, humids[3], ocean) quantiles['62'] = find_threshold_f(data, humids[2], ocean) quantiles['75'] = find_threshold_f(data, humids[1], ocean) quantiles['87'] = find_threshold_f(data, humids[0], ocean) return data, quantiles
def _calculate(world): humids = world.humids precipitationWeight = 1.0 irrigationWeight = 3 data = numpy.zeros((world.height, world.width), dtype=float) data = (world.layers['precipitation'].data * precipitationWeight - world.layers['irrigation'].data * irrigationWeight) / ( precipitationWeight + irrigationWeight) # These were originally evenly spaced at 12.5% each but changing them # to a bell curve produced better results ocean = world.layers['ocean'].data quantiles = {} quantiles['12'] = find_threshold_f(data, humids[6], ocean) quantiles['25'] = find_threshold_f(data, humids[5], ocean) quantiles['37'] = find_threshold_f(data, humids[4], ocean) quantiles['50'] = find_threshold_f(data, humids[3], ocean) quantiles['62'] = find_threshold_f(data, humids[2], ocean) quantiles['75'] = find_threshold_f(data, humids[1], ocean) quantiles['87'] = find_threshold_f(data, humids[0], ocean) return data, quantiles
def execute(self, world, seed): perm = self._calculate(seed, world.width, world.height) perm_th = [('low', find_threshold_f(perm, 0.75, world.ocean)), ('med', find_threshold_f(perm, 0.25, world.ocean)), ('hig', None)] world.set_permeability(perm, perm_th)
def _watermap(world, n): def droplet(world, pos, q, _watermap): if q < 0: return x, y = pos pos_elev = world.layers['elevation'].data[y, x] + _watermap[y, x] lowers = [] min_higher = None min_lower = None # pos_min_higher = None # TODO: no longer used? tot_lowers = 0 for p in world.tiles_around((x, y)): #TODO: switch to numpy px, py = p e = world.layers['elevation'].data[py, px] + _watermap[py, px] if e < pos_elev: dq = int(pos_elev - e) << 2 if min_lower is None or e < min_lower: min_lower = e if dq == 0: dq = 1 lowers.append((dq, p)) tot_lowers += dq else: if min_higher is None or e > min_higher: min_higher = e # pos_min_higher = p if lowers: f = q / tot_lowers for l in lowers: s, p = l if not world.is_ocean(p): px, py = p ql = f * s # ql = q going = ql > 0.05 _watermap[py, px] += ql if going: droplet(world, p, ql, _watermap) else: _watermap[y, x] += q _watermap_data = numpy.zeros((world.height, world.width), dtype=float) for i in range(n): x, y = world.random_land( ) # will return None for x and y if no land exists if x is not None and world.precipitations_at((x, y)) > 0: droplet(world, (x, y), world.precipitations_at((x, y)), _watermap_data) ocean = world.layers['ocean'].data thresholds = dict() thresholds['creek'] = find_threshold_f(_watermap_data, 0.05, ocean=ocean) thresholds['river'] = find_threshold_f(_watermap_data, 0.02, ocean=ocean) thresholds['main river'] = find_threshold_f(_watermap_data, 0.007, ocean=ocean) return _watermap_data, thresholds
def _watermap(world, n): def droplet(world, pos, q, _watermap): if q < 0: return x, y = pos pos_elev = world.layers['elevation'].data[y, x] + _watermap[y, x] lowers = [] min_higher = None min_lower = None # pos_min_higher = None # TODO: no longer used? tot_lowers = 0 for p in world.tiles_around((x, y)):#TODO: switch to numpy px, py = p e = world.layers['elevation'].data[py, px] + _watermap[py, px] if e < pos_elev: dq = int(pos_elev - e) << 2 if min_lower is None or e < min_lower: min_lower = e if dq == 0: dq = 1 lowers.append((dq, p)) tot_lowers += dq else: if min_higher is None or e > min_higher: min_higher = e # pos_min_higher = p if lowers: f = q / tot_lowers for l in lowers: s, p = l if not world.is_ocean(p): px, py = p ql = f * s # ql = q going = ql > 0.05 _watermap[py, px] += ql if going: droplet(world, p, ql, _watermap) else: _watermap[y, x] += q _watermap_data = numpy.zeros((world.height, world.width), dtype=float) # This indirectly calls the global rng. # We want different implementations of _watermap # and internally called functions (especially random_land) # to show the same rng behaviour and not contamine the state of the global rng # should anyone else happen to rely on it. land_sample = world.random_land(n) if land_sample[0] is not None: for i in range(n): x, y = land_sample[2*i], land_sample[2*i+1] if world.precipitations_at((x, y)) > 0: droplet(world, (x, y), world.precipitations_at((x, y)), _watermap_data) ocean = world.layers['ocean'].data thresholds = dict() thresholds['creek'] = find_threshold_f(_watermap_data, 0.05, ocean=ocean) thresholds['river'] = find_threshold_f(_watermap_data, 0.02, ocean=ocean) thresholds['main river'] = find_threshold_f(_watermap_data, 0.007, ocean=ocean) return _watermap_data, thresholds