def generateTempmap(_map): print("Temperature Generation...") _rand = tcod.random_get_instance() _tm = tcod.heightmap_new(_map.width, _map.height) _altMap = tcod.heightmap_new(_map.width, _map.height) _latMap = tcod.heightmap_new(_map.width, _map.height) for y in range(0, _map.height): for x in range(0, _map.width): latitude = -int(180*y/_map.height - 90) latTemp = int(-(latitude*latitude)/51 + 128) tcod.heightmap_set_value(_latMap, x, y, latTemp) alt = _map.heightmap(x, y) if (alt > 0): # expect alt to peak out around 255-320 altTemp = -alt/4 else: altTemp = tcod.random_get_int(_rand,-10, 10) tcod.heightmap_set_value(_altMap, x, y, altTemp) tcod.heightmap_add_hm(_altMap, _latMap, _tm) tcod.heightmap_rain_erosion( _tm, _map.width*_map.height/2, #number of raindrops 0.2, #erosion cooef (f) 0.2) #sediment cooef (f) tcod.heightmap_normalize(_tm, -32, 128) dx = [-1,1,0] dy = [0,0,0] weight = [0.33,0.33,0.33] tcod.heightmap_kernel_transform(_tm,3,dx,dy,weight,-32,128); for y in range(0, _map.height): for x in range(0, _map.width): _map.coords[x][y].setTemp(tcod.heightmap_get_value(_tm, x, y)) return True
def test_heightmap(): hmap = libtcodpy.heightmap_new(16, 16) repr(hmap) noise = libtcodpy.noise_new(2) # basic operations libtcodpy.heightmap_set_value(hmap, 0, 0, 1) libtcodpy.heightmap_add(hmap, 1) libtcodpy.heightmap_scale(hmap, 1) libtcodpy.heightmap_clear(hmap) libtcodpy.heightmap_clamp(hmap, 0, 0) libtcodpy.heightmap_copy(hmap, hmap) libtcodpy.heightmap_normalize(hmap) libtcodpy.heightmap_lerp_hm(hmap, hmap, hmap, 0) libtcodpy.heightmap_add_hm(hmap, hmap, hmap) libtcodpy.heightmap_multiply_hm(hmap, hmap, hmap) # modifying the heightmap libtcodpy.heightmap_add_hill(hmap, 0, 0, 4, 1) libtcodpy.heightmap_dig_hill(hmap, 0, 0, 4, 1) libtcodpy.heightmap_rain_erosion(hmap, 1, 1, 1) libtcodpy.heightmap_kernel_transform(hmap, 3, [-1, 1, 0], [0, 0, 0], [.33, .33, .33], 0, 1) libtcodpy.heightmap_add_voronoi(hmap, 10, 3, [1, 3, 5]) libtcodpy.heightmap_add_fbm(hmap, noise, 1, 1, 1, 1, 4, 1, 1) libtcodpy.heightmap_scale_fbm(hmap, noise, 1, 1, 1, 1, 4, 1, 1) libtcodpy.heightmap_dig_bezier(hmap, [0, 16, 16, 0], [0, 0, 16, 16], 1, 1, 1, 1) # read data libtcodpy.heightmap_get_value(hmap, 0, 0) libtcodpy.heightmap_get_interpolated_value(hmap, 0, 0) libtcodpy.heightmap_get_slope(hmap, 0, 0) libtcodpy.heightmap_get_normal(hmap, 0, 0, 0) libtcodpy.heightmap_count_cells(hmap, 0, 0) libtcodpy.heightmap_has_land_on_border(hmap, 0) libtcodpy.heightmap_get_minmax(hmap) libtcodpy.noise_delete(noise) libtcodpy.heightmap_delete(hmap)
def build_heightmap(self, width, height): hm = self.spherical_noise( self.noise_dx, self.noise_dy, self.noise_dz, self.noise_octaves, self.noise_zoom, self.noise_hurst, self.noise_lacunarity, width, height) if self.planet_class == 'terran': libtcod.heightmap_normalize(hm, 0, 1.0) libtcod.heightmap_add(hm,-0.40) libtcod.heightmap_clamp(hm,0.0,1.0) raindrops = 1000 if width == self.detail_heightmap_width else 100 libtcod.heightmap_rain_erosion(hm,1000,0.46,0.12,self.rnd) libtcod.heightmap_normalize(hm, 0, 255) elif self.planet_class == 'ocean': libtcod.heightmap_normalize(hm, 0, 1.0) libtcod.heightmap_add(hm,-0.40) libtcod.heightmap_clamp(hm,0.0,1.0) raindrops = 3000 if width == self.detail_heightmap_width else 1000 libtcod.heightmap_rain_erosion(hm,3000,0.46,0.12,self.rnd) libtcod.heightmap_normalize(hm, 0, 200) elif self.planet_class == 'jungle': libtcod.heightmap_normalize(hm, 0, 1.0) libtcod.heightmap_add(hm,0.20) libtcod.heightmap_clamp(hm,0.0,1.0) raindrops = 3000 if width == self.detail_heightmap_width else 1000 libtcod.heightmap_rain_erosion(hm,raindrops,0.25,0.05,self.rnd) libtcod.heightmap_normalize(hm, 0, 255) elif self.planet_class == 'lava': libtcod.heightmap_normalize(hm, 0, 1.0) raindrops = 1000 if width == self.detail_heightmap_width else 500 libtcod.heightmap_rain_erosion(hm,raindrops,0.65,0.05,self.rnd) libtcod.heightmap_normalize(hm, 0, 255) elif self.planet_class == 'tundra': libtcod.heightmap_normalize(hm, 0, 1.0) # libtcod.heightmap_add(hm,0.20) # libtcod.heightmap_clamp(hm,0.0,1.0) raindrops = 2000 if width == self.detail_heightmap_width else 50 libtcod.heightmap_rain_erosion(hm,raindrops,0.45,0.05,self.rnd) libtcod.heightmap_normalize(hm, 0, 255) elif self.planet_class == 'arid': libtcod.heightmap_normalize(hm, 0, 1.0) libtcod.heightmap_add(hm,0.20) libtcod.heightmap_clamp(hm,0.0,1.0) raindrops = 2000 if width == self.detail_heightmap_width else 50 libtcod.heightmap_rain_erosion(hm,raindrops,0.45,0.05,self.rnd) libtcod.heightmap_normalize(hm, 0, 255) elif self.planet_class == 'desert': libtcod.heightmap_normalize(hm, 0, 1.0) libtcod.heightmap_add(hm,0.15) libtcod.heightmap_clamp(hm,0.0,1.0) raindrops = 1000 if width == self.detail_heightmap_width else 50 libtcod.heightmap_rain_erosion(hm,raindrops,0.10,0.10,self.rnd) libtcod.heightmap_normalize(hm, 0, 255) elif self.planet_class == 'artic': libtcod.heightmap_normalize(hm, 0, 1.0) libtcod.heightmap_add(hm,0.40) libtcod.heightmap_clamp(hm,0.0,1.0) raindrops = 1000 if width == self.detail_heightmap_width else 100 libtcod.heightmap_rain_erosion(hm,raindrops,0.45,0.05,self.rnd) libtcod.heightmap_normalize(hm, 0, 255) elif self.planet_class == 'barren': libtcod.heightmap_normalize(hm, 0, 1.0) # libtcod.heightmap_add(hm,0.40) # libtcod.heightmap_clamp(hm,0.0,1.0) raindrops = 2000 if width == self.detail_heightmap_width else 500 libtcod.heightmap_rain_erosion(hm,raindrops,0.45,0.05,self.rnd) libtcod.heightmap_normalize(hm, 0, 255) elif self.planet_class == 'gas giant': libtcod.heightmap_normalize(hm, 0, 1.0) # libtcod.heightmap_add(hm,0.40) # libtcod.heightmap_clamp(hm,0.0,1.0) # # 3x3 kernel for smoothing operations smoothKernelSize = 9 smoothKernelDx = [ -1, 0, 1, -1, 0, 1, -1, 0, 1 ] # smoothKernelDy = [ # -1, -1, -1, # 0, 0, 0, # 1, 1, 1 # ] smoothKernelDy = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, ] smoothKernelWeight = [ 1.0, 2.0, 1.0, 4.0, 20.0, 4.0, 1.0, 2.0, 1.0 ] for i in range(20,-1,-1) : libtcod.heightmap_kernel_transform(hm,smoothKernelSize,smoothKernelDx,smoothKernelDy,smoothKernelWeight,0,1.0) libtcod.heightmap_normalize(hm, 0, 255) else: libtcod.heightmap_normalize(hm, 0, 255) return hm
def generateHeightmap(_map): print("Particle Deposition Generation...") _rand = tcod.random_get_instance() _hm = tcod.heightmap_new(_map.width, _map.height) #half-width and -height _hw = _map.width / 2 _hh = _map.height / 2 #quarter-width and -height _qw = _map.width / 4 _qh = _map.height / 4 #define our four "continental centers" _continents = [ (_qw, _qh), #top-left (_map.width - _qw, _qh), #top-right (_qw, _map.height - _qh), #btm-left (_map.width - _qw, _map.height - _qh) ] #btm-right print("Continents:", _continents) _avg = min(_map.width, _map.height) _maxHillHeight = _avg / 4 _maxHillRad = _avg / 8 _iterations = _avg * 32 for i in range(0, _iterations): _quadrant = tcod.random_get_int(_rand, 0, 3) _qx = _continents[_quadrant][0] _qy = _continents[_quadrant][1] _minX = _qx - ((_qw * CONT_SIZE) / 10) _maxX = _qx + ((_qw * CONT_SIZE) / 10) _minY = _qy - _qh _maxY = _qy + _qh x = tcod.random_get_int(_rand, _minX, _maxX) y = tcod.random_get_int(_rand, _minY, _maxY) height = tcod.random_get_int(_rand, -1 * _maxHillHeight, _maxHillHeight) rad = tcod.random_get_int(_rand, 0, _maxHillRad) tcod.heightmap_add_hill(_hm, x, y, rad, height) #"dig out" the space around the edge of the map x = _hw for y in range(0, _map.height, max(1, _maxHillRad / 8)): height = tcod.random_get_int(_rand, _maxHillHeight / -2, -1 * _maxHillHeight) rad = tcod.random_get_int(_rand, 0, _maxHillRad * 2) tcod.heightmap_add_hill(_hm, 0, y, rad, height) tcod.heightmap_add_hill(_hm, _map.width - 1, y, rad, height) for x in range(0, _map.width, max(1, _maxHillRad / 4)): height = tcod.random_get_int(_rand, _maxHillHeight / -2, -1 * _maxHillHeight) rad = tcod.random_get_int(_rand, 0, _maxHillRad * 2) tcod.heightmap_add_hill(_hm, x, 0, rad, height) tcod.heightmap_add_hill(_hm, x, _map.height - 1, rad, height) tcod.heightmap_rain_erosion( _hm, _map.width * _map.height, #number of raindrops 0.2, #erosion cooef (f) 0.2) #sediment cooef (f) _dx = [-2, -1, 0, 1, 2] _dy = [-2, -1, 0, 1, 2] _weight = [0.1, 0.1, 0.2, 0.3, 0.3] tcod.heightmap_kernel_transform(_hm, 5, _dx, _dy, _weight, -64, 255) tcod.heightmap_normalize(_hm, -255, 392) for y in range(0, _map.height): for x in range(0, _map.width): _map.coords[x][y].setAltitude(tcod.heightmap_get_value(_hm, x, y)) return True