예제 #1
0
def test_noise():
    noise = libtcodpy.noise_new(1)
    libtcodpy.noise_set_type(noise, libtcodpy.NOISE_SIMPLEX)
    libtcodpy.noise_get(noise, [0])
    libtcodpy.noise_get_fbm(noise, [0], 4)
    libtcodpy.noise_get_turbulence(noise, [0], 4)
    libtcodpy.noise_delete(noise)
예제 #2
0
파일: test.py 프로젝트: basp/haddock
def noise_example():
	noise1d = libtcod.noise_new(1)
	for s in range(10):
		x = s / float(5)
		v = libtcod.noise_get(noise1d, [x])
		print(v)	
	libtcod.noise_delete(noise1d)
예제 #3
0
    def __init__(self, mapsize, resources):
        self.world_width = mapsize
        self.world_height = self.world_width / 2
        self.grid = []
        self.world_noise = libtcod.noise_new(3)
        self.resource_noise = libtcod.noise_new(3)
        self.name = 'map_name'
        for x in xrange(self.world_width):
            row = []
            for y in xrange(self.world_height):
                row.append(
                    GridCoordinate(x, y, self.world_width, self.world_height,
                                   self.world_noise, self.resource_noise))
            self.grid.append(row)
        libtcod.noise_delete(self.world_noise)
        libtcod.noise_delete(self.resource_noise)
        for x in xrange(self.world_width):
            for y in xrange(self.world_height):
                self.grid[x][y].neighbors = get_neighbors(self, x, y)

        # Spawn resource nodes where the resource density is sufficiently high
        for x in xrange(self.world_width):
            for y in xrange(self.world_height):
                if self.grid[x][y].resource_density > self.RESOURCE_THRESHHOLD:
                    new_node = ResourceNode(x, y, resources)
                    print x, y

        # Pathfinding graph for all land tiles; remove sea tiles and delete
        # neighbor, cost entry in the neighbors list
        self.land_graph = self.grid
        for x in xrange(self.world_width):
            for y in xrange(self.world_height):
                cell = self.land_graph[x][y]
                if cell.elevation >= 0:
                    cell.neighbors = {}
                for key in cell.neighbors.copy():
                    if key.elevation >= 0:
                        if key in cell.neighbors:
                            del cell.neighbors[key]

        # Pathfinding graph for all sea tiles
        self.sea_graph = self.grid
        for x in xrange(self.world_width):
            for y in xrange(self.world_height):
                cell = self.sea_graph[x][y]
                if cell.elevation > 0:
                    cell.neighbors = {}
                for key in cell.neighbors.copy():
                    if key.elevation > 0:
                        if key in cell.neighbors:
                            del cell.neighbors[key]
예제 #4
0
 def _build_background(self):
     """
     Make a background noise that will more or less look like
     an old map.
     """
     noise = tcod.noise_new(2)
     tcod.noise_set_type(noise, tcod.NOISE_SIMPLEX)
     background = []
     for y in range(self.height):
         background.append([])
         for x in range(self.width):
             background[y].append(
                 tcod.noise_get_turbulence(noise, [y / 100.0, x / 100.0],
                                           32.0))
     tcod.noise_delete(noise)
     return background
예제 #5
0
 def _build_background(self):
     """
     Make a background noise that will more or less look like
     an old map.
     """
     noise = tcod.noise_new(2)
     tcod.noise_set_type(noise, tcod.NOISE_SIMPLEX)
     background = []
     for y in range(self.height):
         background.append([])
         for x in range(self.width):
             background[y].append(
                 tcod.noise_get_turbulence(noise,
                                           [y / 100.0, x / 100.0], 32.0))
     tcod.noise_delete(noise)
     return background
예제 #6
0
def get_cylindrical_projection(stars, width=360, height=180):
    """
    Return a tcod console instance of width and height that renders an equirectangular projection of the given list of stars.
    """
    console = tcod.console_new(width, height)

    for star in stars:
        azimuthal = int((star.azimuthal * width) / (2 * math.pi))
        polar = int((star.polar / math.pi) * height)

        # Color Work
        rgb = temperature_to_rgb(random.uniform(4000, 20000))
        brightness = 1.0 - star.radial * 0.75

        color = tcod.Color(rgb[0], rgb[1], rgb[2])
        (h, s, v) = tcod.color_get_hsv(color)
        tcod.color_set_hsv(color, h, s, brightness)

        tcod.console_put_char_ex(console, azimuthal, polar, star.sprite, color,
                                 tcod.black)

    # Background Texture
    noise3d = tcod.noise_new(3)
    for map_x in range(width):
        for map_y in range(height):
            azimuthal = (map_x / (width * 1.0)) * 2.0 * math.pi
            polar = (map_y / (height * 1.0)) * math.pi
            x = math.sin(polar) * math.cos(azimuthal)
            y = math.sin(polar) * math.sin(azimuthal)
            z = math.cos(polar)
            blue = int(
                tcod.noise_get_turbulence(noise3d, [x, y, z], 32.0) * 16.0 +
                16.0)
            green = int(tcod.noise_get(noise3d, [x, y, z]) * 8.0 + 8.0)
            red = int(tcod.noise_get_fbm(noise3d, [x, y, z], 32.0) * 4.0 + 4.0)
            background = tcod.Color(red, green, blue)

            if map_y == height / 2 or map_x == 0 or map_x == width / 2:
                background = tcod.darkest_yellow

            tcod.console_set_char_background(console, map_x, map_y, background)

    tcod.noise_delete(noise3d)
    return console
예제 #7
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)