예제 #1
0
def generateRainmap(map):
    print("Rainfall Generation...")

    altMap = tcod.heightmap_new(map.width, map.height)
    latMap = tcod.heightmap_new(map.width, map.height)

    rainMap = tcod.heightmap_new(map.width, map.height)

    for y in range(0, map.height):
        for x in range(0, map.width):

            # Cosine wave, dipping to -5 at the poles and the tropics
            latRain = 40 - (50 * (math.cos(math.pi * y / (map.height / 10))))
            tcod.heightmap_set_value(rainMap, x, y, latRain)

    tcod.heightmap_add_voronoi(rainMap, int(map.height * map.width / 256), 3,
                               [0.1, 0.1, 0.1])

    tcod.heightmap_normalize(rainMap, 0, 150)
    tcod.heightmap_clamp(rainMap, 0, 100)

    for y in range(0, map.height):
        for x in range(0, map.width):

            map.setRain(x, y, tcod.heightmap_get_value(rainMap, x, y))
예제 #2
0
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)
예제 #3
0
    def build_atmosphere(self, width, height):
        if self.planet_class in ['terran', 'ocean', 'jungle', 'tundra', 'artic'] :
            atmosphere = self.spherical_noise(
                    noise_dx=10.0,
                    noise_dy=10.0,
                    noise_dz=10.0,
                    noise_octaves=4.0,
                    noise_zoom=2.0,
                    noise_hurst=self.noise_hurst,
                    noise_lacunarity=self.noise_lacunarity,
                    width=width,
                    height=height )

            libtcod.heightmap_normalize(atmosphere, 0, 1.0)
            libtcod.heightmap_add(atmosphere,0.30)
            libtcod.heightmap_clamp(atmosphere,0.4,1.0)
            return atmosphere

        elif self.planet_class in ['arid', 'desert']:
            atmosphere = self.spherical_noise(
                    noise_dx=10.0,
                    noise_dy=10.0,
                    noise_dz=10.0,
                    noise_octaves=4.0,
                    noise_zoom=2.0,
                    noise_hurst=self.noise_hurst,
                    noise_lacunarity=self.noise_lacunarity,
                    width=width,
                    height=height )
            libtcod.heightmap_normalize(atmosphere, 0, 1.0)
            libtcod.heightmap_add(atmosphere,0.7)
            libtcod.heightmap_clamp(atmosphere,0.8,1.0)
            return atmosphere

        else:
            return None
def generateRainmap(map):
    print("Rainfall Generation...");
    
    altMap = tcod.heightmap_new(map.width, map.height)
    latMap = tcod.heightmap_new(map.width, map.height)
    
    rainMap = tcod.heightmap_new(map.width, map.height)
    
    for y in range(0, map.height):
        for x in range(0, map.width):
            
            # Cosine wave, dipping to -5 at the poles and the tropics
            latRain = 40-(50*(math.cos(math.pi*y/(map.height/10))))
            tcod.heightmap_set_value(rainMap, x, y, latRain)
    
    tcod.heightmap_add_voronoi(rainMap, int(map.height * map.width / 256), 3, [0.1,0.1, 0.1] )
    
    tcod.heightmap_normalize(rainMap, 0,150)
    tcod.heightmap_clamp(rainMap, 0,100)
    
    for y in range(0, map.height):
        for x in range(0, map.width):
            
            map.setRain(x, y, tcod.heightmap_get_value(rainMap, x, y))
예제 #5
0
파일: world_gen.py 프로젝트: Relvius/Drake
def make_heightmap(size, seed):

    # Gradient generated by distance to the northeast corner (creates northeast ocean).
    gradient1 = lt.heightmap_new(size, size)
    for col in xrange(size):
        for row in xrange(size):
            distance = ((row - size) ** 2 + col ** 2) ** 0.5
            lt.heightmap_set_value(gradient1, row, col, distance)
    lt.heightmap_clamp(gradient1, mi=0, ma=WORLD_SIZE)
    lt.heightmap_scale(gradient1, 2)
    # Similar gradient, but cube root (creates mountains around edge).
    gradient2 = lt.heightmap_new(size, size)
    for col in xrange(size):
        for row in xrange(size):
            distance = ((row - size) ** 2 + col ** 2) ** 0.33
            lt.heightmap_set_value(gradient2, row, col, distance)
    lt.heightmap_clamp(gradient2, mi=0, ma=WORLD_SIZE / 6)
    lt.heightmap_scale(gradient2, 5)

    # Height map based on Perlin noise.
    heightmap = lt.heightmap_new(size, size)
    random = lt.random_new()
    if seed:
        random = lt.random_new_from_seed(seed)
    perlin = lt.noise_new(2, h=2, l=2, random=random)

    lt.heightmap_add_fbm(heightmap, perlin, mulx=3, muly=3, addx=0, addy=0, octaves=8, delta=50, scale=100)

    # Add in gradients.
    lt.heightmap_add_hm(heightmap, gradient1, heightmap)
    lt.heightmap_add_hm(heightmap, gradient2, heightmap)

    lt.heightmap_normalize(heightmap, mi=-100, ma=105)
    lt.heightmap_clamp(heightmap, mi=-50, ma=100)
    lt.heightmap_normalize(heightmap, mi=-100, ma=100)
    visualize(heightmap)

    return heightmap
예제 #6
0
    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
예제 #7
0
def MasterWorldGen(
):  #------------------------------------------------------- * MASTER GEN * -------------------------------------------------------------

    print ' * World Gen START * '
    starttime = time.time()

    #Heightmap
    hm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)

    for i in range(50):
        libtcod.heightmap_add_hill(
            hm, randint(WORLD_WIDTH / 10, WORLD_WIDTH - WORLD_WIDTH / 10),
            randint(WORLD_HEIGHT / 10, WORLD_HEIGHT - WORLD_HEIGHT / 10),
            randint(12, 16), randint(6, 10))
    print '- Main Hills -'

    for i in range(200):
        libtcod.heightmap_add_hill(
            hm, randint(WORLD_WIDTH / 10, WORLD_WIDTH - WORLD_WIDTH / 10),
            randint(WORLD_HEIGHT / 10, WORLD_HEIGHT - WORLD_HEIGHT / 10),
            randint(2, 4), randint(6, 10))
    print '- Small Hills -'

    libtcod.heightmap_normalize(hm, 0.0, 1.0)

    noisehm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    noise2d = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST,
                                libtcod.NOISE_DEFAULT_LACUNARITY)
    libtcod.heightmap_add_fbm(noisehm, noise2d, 4, 4, 0, 0, 32, 1, 1)
    libtcod.heightmap_normalize(noisehm, 0.0, 1.0)
    libtcod.heightmap_multiply_hm(hm, noisehm, hm)
    print '- Apply Simplex -'

    PoleGen(hm, 0)
    print '- South Pole -'

    PoleGen(hm, 1)
    print '- North Pole -'

    TectonicGen(hm, 0)
    TectonicGen(hm, 1)
    print '- Tectonic Gen -'

    libtcod.heightmap_rain_erosion(hm, WORLD_WIDTH * WORLD_HEIGHT, 0.07, 0, 0)
    print '- Erosion -'

    libtcod.heightmap_clamp(hm, 0.0, 1.0)

    #Temperature
    temp = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    Temperature(temp, hm)
    libtcod.heightmap_normalize(temp, 0.0, 0.8)
    print '- Temperature Calculation -'

    #Precipitation

    preciphm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    Percipitaion(preciphm, temp)
    libtcod.heightmap_normalize(preciphm, 0.0, 0.8)
    print '- Percipitaion Calculation -'

    #Drainage

    drainhm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    drain = libtcod.noise_new(2, libtcod.NOISE_DEFAULT_HURST,
                              libtcod.NOISE_DEFAULT_LACUNARITY)
    libtcod.heightmap_add_fbm(drainhm, drain, 2, 2, 0, 0, 32, 1, 1)
    libtcod.heightmap_normalize(drainhm, 0.0, 0.8)
    print '- Drainage Calculation -'

    # VOLCANISM - RARE AT SEA FOR NEW ISLANDS (?) RARE AT MOUNTAINS > 0.9 (?) RARE AT TECTONIC BORDERS (?)

    elapsed_time = time.time() - starttime
    print ' * World Gen DONE *    in: ', elapsed_time, ' seconds'

    #Initialize Tiles with Map values
    World = [[0 for y in range(WORLD_HEIGHT)]
             for x in range(WORLD_WIDTH)]  #100x100 array
    for x in xrange(WORLD_WIDTH):
        for y in xrange(WORLD_HEIGHT):
            World[x][y] = Tile(libtcod.heightmap_get_value(hm, x, y),
                               libtcod.heightmap_get_value(temp, x, y),
                               libtcod.heightmap_get_value(preciphm, x, y),
                               libtcod.heightmap_get_value(drainhm, x, y), 0)

    print '- Tiles Initialized -'

    #Prosperity

    Prosperity(World)
    print '- Prosperity Calculation -'

    #Biome info to Tile

    for x in xrange(WORLD_WIDTH):
        for y in xrange(WORLD_HEIGHT):

            if World[x][y].height > 0.2:
                World[x][y].biomeID = 3
                if randint(1, 10) < 3:
                    World[x][y].biomeID = 5
            if World[x][y].height > 0.4:
                World[x][y].biomeID = 14
                if randint(1, 10) < 3:
                    World[x][y].biomeID = 5
            if World[x][y].height > 0.5:
                World[x][y].biomeID = 8
                if randint(1, 10) < 3:
                    World[x][y].biomeID = 14

            if World[x][y].temp <= 0.5 and World[x][y].precip >= 0.5:
                World[x][y].biomeID = 5
                if randint(1, 10) < 3:
                    World[x][y].biomeID = 14
            if World[x][y].temp >= 0.5 and World[x][y].precip >= 0.7:
                World[x][y].biomeID = 6

            if World[x][y].precip >= 0.7 and World[x][
                    y].height > 0.2 and World[x][y].height <= 0.4:
                World[x][y].biomeID = 2

            if World[x][y].temp > 0.75 and World[x][y].precip < 0.35:
                World[x][y].biomeID = 4

            if World[x][y].temp <= 0.22 and World[x][y].height > 0.2:
                World[x][y].biomeID = randint(11, 13)
            if World[x][y].temp <= 0.3 and World[x][y].temp > 0.2 and World[x][
                    y].height > 0.2 and World[x][y].precip >= 0.6:
                World[x][y].biomeID = 7

            if World[x][y].height > 0.75:
                World[x][y].biomeID = 9
            if World[x][y].height > 0.999:
                World[x][y].biomeID = 10
            if World[x][y].height <= 0.2:
                World[x][y].biomeID = 0
            if World[x][y].height <= 0.1:
                World[x][y].biomeID = 0

    print '- BiomeIDs Atributed -'

    #River Gen

    for x in range(5):
        RiverGen(World)
    print '- River Gen -'

    #Free Heightmaps
    libtcod.heightmap_delete(hm)
    libtcod.heightmap_delete(temp)
    libtcod.heightmap_delete(noisehm)

    print ' * Biomes/Rivers Sorted *'

    return World
예제 #8
0
def MasterWorldGen():    #------------------------------------------------------- * MASTER GEN * -------------------------------------------------------------

    print ' * World Gen START * '
    starttime = time.time()

    #Heightmap
    hm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)

    for i in range(50):
        libtcod.heightmap_add_hill(hm, randint(WORLD_WIDTH/10,WORLD_WIDTH- WORLD_WIDTH/10), randint(WORLD_HEIGHT/10,WORLD_HEIGHT- WORLD_HEIGHT/10), randint(12,16), randint(6,10))
    print '- Main Hills -'

    for i in range(200):
        libtcod.heightmap_add_hill(hm, randint(WORLD_WIDTH/10,WORLD_WIDTH- WORLD_WIDTH/10), randint(WORLD_HEIGHT/10,WORLD_HEIGHT- WORLD_HEIGHT/10), randint(2,4), randint(6,10))
    print '- Small Hills -'

    libtcod.heightmap_normalize(hm, 0.0, 1.0)

    noisehm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    noise2d = libtcod.noise_new(2,libtcod.NOISE_DEFAULT_HURST, libtcod.NOISE_DEFAULT_LACUNARITY)
    libtcod.heightmap_add_fbm(noisehm, noise2d,4, 4, 0, 0, 64, 1, 1)
    libtcod.heightmap_normalize(noisehm, 0.0, 1.0)
    libtcod.heightmap_multiply_hm(hm, noisehm, hm)
    print '- Apply Simplex -'

    PoleGen(hm, 0)
    print '- South Pole -'

    PoleGen(hm, 1)
    print '- North Pole -'

    TectonicGen(hm,0)
    TectonicGen(hm,1)
    print '- Tectonic Gen -'

    libtcod.heightmap_rain_erosion(hm, WORLD_WIDTH*WORLD_HEIGHT ,0.07,0,0)
    print '- Erosion -'

    libtcod.heightmap_clamp(hm, 0.0, 1.0)
      
    #Temperature
    temp = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)   
    Temperature(temp,hm)
    libtcod.heightmap_normalize(temp, 0.0, 0.8)
    print '- Temperature Calculation -'     

    #Precipitation

    preciphm = libtcod.heightmap_new(WORLD_WIDTH, WORLD_HEIGHT)
    Percipitaion(preciphm)
    libtcod.heightmap_normalize(preciphm, 0.0, 0.8)
    print '- Percipitaion Calculation -'  
      
    # VOLCANISM - RARE AT SEA FOR NEW ISLANDS (?) RARE AT MOUNTAINS > 0.9 (?) RARE AT TECTONIC BORDERS (?)

    #Initialize Tiles with Map values
    World = [[0 for y in range(WORLD_HEIGHT)] for x in range(WORLD_WIDTH)] #100x100 array
    for x in xrange(WORLD_WIDTH):
        for y in xrange(WORLD_HEIGHT):
                World[x][y] = Tile(libtcod.heightmap_get_value(hm, x, y),
                                    libtcod.heightmap_get_value(temp, x, y),
                                    libtcod.heightmap_get_value(preciphm, x, y),
                                    0)      

    print '- Tiles Initialized -'

    # - Biome info to Tiles -

    for x in xrange(WORLD_WIDTH):
        for y in xrange(WORLD_HEIGHT):
            
            if World[x][y].height > 0.2:
                World[x][y].biomeID = 3
                if randint(1,10) < 3:
                    World[x][y].biomeID = 5
            if World[x][y].height > 0.4:
                World[x][y].biomeID = 14
                if randint(1,10) < 3:
                    World[x][y].biomeID = 5
            if World[x][y].height > 0.5:
                World[x][y].biomeID = 8
                if randint(1,10) < 3:
                    World[x][y].biomeID = 14

            if World[x][y].temp <= 0.5 and World[x][y].precip >= 0.5:
                World[x][y].biomeID = 5
                if randint(1,10) < 3:
                    World[x][y].biomeID = 14
            if World[x][y].temp >= 0.5 and World[x][y].precip >= 0.7:
                World[x][y].biomeID = 6

            if World[x][y].precip >= 0.7 and World[x][y].height > 0.2 and World[x][y].height <= 0.4:
                World[x][y].biomeID = 2

            if World[x][y].temp > 0.75 and World[x][y].precip < 0.35:
                World[x][y].biomeID = 4

            if World[x][y].temp <= 0.22 and World[x][y].height > 0.2:
                World[x][y].biomeID = randint(11,13)
            if World[x][y].temp <= 0.3 and World[x][y].temp > 0.2 and World[x][y].height > 0.2 and World[x][y].precip >= 0.6:
                World[x][y].biomeID = 7
                  
            if World[x][y].height > 0.75:
                World[x][y].biomeID = 9
            if World[x][y].height > 0.999:
                World[x][y].biomeID = 10                  
            if World[x][y].height <= 0.2:
                World[x][y].biomeID = 0
            if World[x][y].height <= 0.1:
                World[x][y].biomeID = 0                  

    print '- BiomeIDs Atributed -'
      
    #River Gen
      
    for x in range(2):
        RiverGen(hm, World)
    print '- River Gen -'

    #Free Heightmaps
    libtcod.heightmap_delete(hm)
    libtcod.heightmap_delete(temp)
    libtcod.heightmap_delete(noisehm)                       

    elapsed_time = time.time() - starttime
    print ' * World Gen DONE *    in: ',elapsed_time,' seconds'

    return World