Exemple #1
0
def smooth(height, dim, rng):
	num_cells = dim[0] * dim[1]
	dx = (-1, -1, -1, 0, 0, 1, 1, 1)
	dy = (-1, 0, 1, -1, 1, -1, 0, 1)
	weight = tuple(1 / 8 for i in range(8))
	tcod.heightmap_kernel_transform(height, 8, dx, dy, weight, 0.0, 100)
	tcod.heightmap_rain_erosion(height, int(num_cells / 10), 1.0, 0.1, rng)
Exemple #2
0
    def kernel_transform(self, kernel_size, dx, dy, weight, min_level, max_level):
        """Apply a generic transformation to the heightmap.

        This function allows you to apply a generic transformation on
        the map, so that each resulting cell value is the weighted sum of
        several neighbour cells. This can be used to smooth/sharpen the
        map. 

        kernel_size = Size of transformation.  

        dx, dy = Array of kernel_size coordinates. The coordinates are
                 relative to the current cell (0,0) is current cell,
                 (-1,0) is west cell, (0,-1) is north cell, (1,0) is
                 east cell, (0,1) is south cell, ...

        weight = Array of kernel_size weights. The value of each
                 neighbour cell is scaled by its corresponding weight.

        min_level = The transformation is only applied to cells which
                    value is >= minLevel.

        max_level = The transformation is only applied to cells which
                    value is <= maxLevel."""
        tcod.heightmap_kernel_transform(self._data, kernel_size, dx, dy, weight,
                                        min_level, max_level)
Exemple #3
0
    def smooth_map(self):
        # 3x3 kernel for smoothing operations
        smooth_ks = 9
        smooth_dx = [-1, 0, 1, -1, 0, 1, -1, 0, 1]
        smooth_dy = [-1, -1, -1, 0, 0, 0, 1, 1, 1]
        smooth_weight = [2, 8, 2, 8, 20, 8, 2, 8, 2]

        tcod.heightmap_kernel_transform(self._hm, smooth_ks, smooth_dx,
                                        smooth_dy, smooth_weight, -1000, 1000)
        tcod.heightmap_kernel_transform(self._hm2, smooth_ks, smooth_dx,
                                        smooth_dy, smooth_weight, -1000, 1000)
        tcod.heightmap_normalize(self._hm)
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)
Exemple #5
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)
Exemple #6
0
 def kernel_transform(self, kernel_size, dx, dy, weight, min_level, max_level):
     tcod.heightmap_kernel_transform(self._data, kernel_size, dx, dy, weight, min_level, max_level)
     return self