コード例 #1
0
def test_image(console, tmpdir):
    img = libtcodpy.image_new(16, 16)
    libtcodpy.image_clear(img, libtcodpy.Color(0, 0, 0))
    libtcodpy.image_invert(img)
    libtcodpy.image_hflip(img)
    libtcodpy.image_rotate90(img)
    libtcodpy.image_vflip(img)
    libtcodpy.image_scale(img, 24, 24)
    libtcodpy.image_set_key_color(img, libtcodpy.Color(255, 255, 255))
    libtcodpy.image_get_alpha(img, 0, 0)
    libtcodpy.image_is_pixel_transparent(img, 0, 0)
    libtcodpy.image_get_size(img)
    libtcodpy.image_get_pixel(img, 0, 0)
    libtcodpy.image_get_mipmap_pixel(img, 0, 0, 1, 1)
    libtcodpy.image_put_pixel(img, 0, 0, libtcodpy.Color(255, 255, 255))
    libtcodpy.image_blit(img, console, 0, 0, libtcodpy.BKGND_SET, 1, 1, 0)
    libtcodpy.image_blit_rect(img, console, 0, 0, 16, 16, libtcodpy.BKGND_SET)
    libtcodpy.image_blit_2x(img, console, 0, 0)
    libtcodpy.image_save(img, tmpdir.join('test.png').strpath)
    libtcodpy.image_delete(img)

    # Not portable.
    #img = libtcodpy.image_from_console(console)
    #libtcodpy.image_refresh_console(img, console)
    #libtcodpy.image_delete(img)

    libtcodpy.image_delete(libtcodpy.image_load('../data/img/circle.png'))
コード例 #2
0
ファイル: interfaces.py プロジェクト: frogbotherer/DalekRL
 def reset_map(self, pos=None):
     """Reset light map.
     If pos is a list of Positions, only reset those areas"""
     if self.light_enabled:
         assert not self.pos is None and not self.map is None, "resetting LightSource that is not placed on map"
         libtcod.image_clear(self.__tcod_light_image, self.raw_light_colour * self.intensity)
         libtcod.image_set_key_color(self.__tcod_light_image, libtcod.black)
     else:
         libtcod.image_clear(self.__tcod_light_image, libtcod.black)
         libtcod.image_set_key_color(self.__tcod_light_image, libtcod.black)
コード例 #3
0
ファイル: libbluebox.py プロジェクト: jarcane/BlueBox
 def set_graphics(self, flag=None):
     # if the graphics layer hasn't been initialized, start it
     # if called with no arguments, switches the state of graphics mode
     # otherwise, switches to the designated state (True for on, False for off)
     if flag is None:
         flag = not self.graphics_mode
     self.graphics_mode = flag
     if self.graphics_mode:
         self.img = libtcod.image_new(self.width * 2, self.height * 2)
         libtcod.image_clear(self.img, self.background)
コード例 #4
0
 def reset_map(self, pos=None):
     """Reset light map.
     If pos is a list of Positions, only reset those areas"""
     if self.light_enabled:
         assert not self.pos is None and not self.map is None, "resetting LightSource that is not placed on map"
         libtcod.image_clear(self.__tcod_light_image,
                             self.raw_light_colour * self.intensity)
         libtcod.image_set_key_color(self.__tcod_light_image, libtcod.black)
     else:
         libtcod.image_clear(self.__tcod_light_image, libtcod.black)
         libtcod.image_set_key_color(self.__tcod_light_image, libtcod.black)
コード例 #5
0
ファイル: hhmessage.py プロジェクト: jarcane/handhRL
def generate_starpic():
    # Generates a random starfield pattern and stores it in img
    img = libtcod.image_new(160, 100)
    libtcod.image_clear(img, libtcod.black)
    colors = [libtcod.lightest_yellow, libtcod.lightest_grey, libtcod.white, libtcod.white, libtcod.light_orange,
              libtcod.darker_red]

    for x in range(100):
        x = libtcod.random_get_int(0, 0, 159)
        y = libtcod.random_get_int(0, 0, 99)
        c = libtcod.random_get_int(0, 0, len(colors) - 1)
        libtcod.image_put_pixel(img, x, y, colors[c])

    return img
コード例 #6
0
ファイル: libbluebox.py プロジェクト: jarcane/BlueBox
    def __init__(self, win_name='BlueBox', boot_msg=True, graphics_mode=False, img=None,
                 width=40, height=24, fps=24, foreground=color_on, background=color_off):
        # declare initial graphics colors and resolution (40 or 80 column modes)
        self.win_name = win_name
        self.boot_msg = boot_msg
        self.graphics_mode = graphics_mode
        self.img = img
        self.width = width
        self.height = height
        self.fps = fps
        self.foreground = foreground
        self.background = background

        # initialize libtcod console and store to self.con
        if width >= 80:
            libtcod.console_set_custom_font('bluebox80.png',
                                            libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)
        else:
            libtcod.console_set_custom_font('bluebox.png',
                                            libtcod.FONT_TYPE_GREYSCALE | libtcod.FONT_LAYOUT_ASCII_INROW)
        libtcod.console_init_root(self.width, self.height, self.win_name, False)
        libtcod.sys_set_fps(self.fps)
        self.con = libtcod.console_new(self.width, self.height)

        # set console colors and alignment
        libtcod.console_set_default_foreground(self.con, self.foreground)
        libtcod.console_set_default_background(self.con, self.background)
        libtcod.console_set_alignment(self.con, libtcod.LEFT)

        # create the cursor
        self.cursor = Cursor()

        # create an array containing the screen contents
        self.screen = [[' ' for y in range(self.height)] for x in range(self.width)]

        # if graphics layer is enabled, initialize it.
        if graphics_mode:
            self.img = libtcod.image_new(self.width * 2, self.height * 2)
            libtcod.image_clear(self.img, self.background)

        # Display the default boot message, disable with boot_msg=False
        if boot_msg:
            self.text_out('BUTTECH CAI-1 (C) 1987')
            self.text_out('PRODUCED UNDER CONTRACT FOR THE BUTTE')
            self.text_out('COUNTY BOARD OF EDUCATION')
            self.text_out('')
コード例 #7
0
    def reset_map(self, pos=None):
        """Reset light map.
        If pos is a list of Positions, only reset those areas"""
        if not self.light_enabled:
            libtcod.image_clear(self.__tcod_light_image, libtcod.black)
            libtcod.image_set_key_color(self.__tcod_light_image, libtcod.black)
            return
        assert not self.pos is None and not self.map is None, "resetting LightSource that is not placed on map"

        # [re-]calculating FOV of light within its map
        if pos is None:
            libtcod.map_clear(self.__tcod_light_map, False, False)
            cov = {}
            for o in self.map.find_all_within_r(self, Transparent,
                                                self.radius):
                # if there's something here already and it blocks light, light is blocked at pos
                if cov.get(o.pos, True):
                    cov[o.pos] = not o.blocks_light()

            for (p, is_transparent) in cov.items():
                # we're using the walkable bit to show that there is a tile that could be lit
                libtcod.map_set_properties(self.__tcod_light_map,
                                           self.radius + p.x - self.pos.x,
                                           self.radius + p.y - self.pos.y,
                                           is_transparent, True)

        else:
            if not isinstance(pos, list):
                pos = [pos]
            skip_calc = True
            for p in pos:
                if self.pos.distance_to(p) > self.radius:
                    # pos isn't covered by this light; do nothing
                    pass

                else:
                    skip_calc = False
                    is_transparent = True
                    for o in self.map.find_all_at_pos(p):
                        if isinstance(o, Transparent) and o.blocks_light():
                            is_transparent = False
                            break
                    libtcod.map_set_properties(self.__tcod_light_map,
                                               self.radius + p.x - self.pos.x,
                                               self.radius + p.y - self.pos.y,
                                               is_transparent, True)

            if skip_calc:
                # all pos were outside of light radius!
                return

        self.prepare_fov(
            False
        )  # TODO: calculate both True and False; use True only if light in LOS of player

        # use FOV data to create an image of light intensity, masked by opaque tiles
        # can optimise based on pos P: only need to recalculate area X
        #   ---        ---XX            ---        --XXX
        #  /   \      /   XX           /   \      /  XXX     do this by splitting into quarters
        # |    P|    |    PX          |     |    |   XXX     and working out which to recalculate
        # |  L  |    |  L  |          |  LP |    |  LPXX     based on P-L
        # |     |    |     |          |     |    |   XXX
        #  \   /      \   /            \   /      \  XXX
        #   ---        ---              ---        --XXX
        libtcod.image_clear(self.__tcod_light_image, libtcod.black)
        libtcod.image_set_key_color(self.__tcod_light_image, libtcod.black)
        r = self.radius
        rd2 = r / 2
        i1 = self.raw_light_colour * self.intensity
        for x in range(r * 2 + 1):
            for y in range(r * 2 + 1):
                #print("(%d,%d)"%(x,y))
                if libtcod.map_is_in_fov(self.__tcod_light_map, x, y):
                    d = hypot(r - x, r - y)
                    if d > rd2:
                        libtcod.image_put_pixel(self.__tcod_light_image, x, y,
                                                i1 * (1.0 - (d - rd2) / rd2))
                        #print("  %s %s"%(d,i1*(1.0-(d-rd2)/rd2)))
                    else:
                        libtcod.image_put_pixel(self.__tcod_light_image, x, y,
                                                i1)
コード例 #8
0
ファイル: interfaces.py プロジェクト: frogbotherer/DalekRL
    def reset_map(self, pos=None):
        """Reset light map.
        If pos is a list of Positions, only reset those areas"""
        if not self.light_enabled:
            libtcod.image_clear(self.__tcod_light_image, libtcod.black)
            libtcod.image_set_key_color(self.__tcod_light_image, libtcod.black)
            return
        assert not self.pos is None and not self.map is None, "resetting LightSource that is not placed on map"

        # [re-]calculating FOV of light within its map
        if pos is None:
            libtcod.map_clear(self.__tcod_light_map, False, False)
            cov = {}
            for o in self.map.find_all_within_r(self, Transparent, self.radius):
                # if there's something here already and it blocks light, light is blocked at pos
                if cov.get(o.pos, True):
                    cov[o.pos] = not o.blocks_light()

            for (p, is_transparent) in cov.items():
                # we're using the walkable bit to show that there is a tile that could be lit
                libtcod.map_set_properties(self.__tcod_light_map,
                                           self.radius + p.x - self.pos.x,
                                           self.radius + p.y - self.pos.y,
                                           is_transparent, True)

        else:
            if not isinstance(pos, list):
                pos = [pos]
            skip_calc = True
            for p in pos:
                if self.pos.distance_to(p) > self.radius:
                    # pos isn't covered by this light; do nothing
                    pass

                else:
                    skip_calc      = False
                    is_transparent = True
                    for o in self.map.find_all_at_pos(p):
                        if isinstance(o, Transparent) and o.blocks_light():
                            is_transparent = False
                            break
                    libtcod.map_set_properties(self.__tcod_light_map,
                                               self.radius + p.x - self.pos.x,
                                               self.radius + p.y - self.pos.y,
                                               is_transparent, True)

            if skip_calc:
                # all pos were outside of light radius!
                return

        self.prepare_fov(False) # TODO: calculate both True and False; use True only if light in LOS of player

        # use FOV data to create an image of light intensity, masked by opaque tiles
        # can optimise based on pos P: only need to recalculate area X
        #   ---        ---XX            ---        --XXX
        #  /   \      /   XX           /   \      /  XXX     do this by splitting into quarters
        # |    P|    |    PX          |     |    |   XXX     and working out which to recalculate
        # |  L  |    |  L  |          |  LP |    |  LPXX     based on P-L
        # |     |    |     |          |     |    |   XXX
        #  \   /      \   /            \   /      \  XXX
        #   ---        ---              ---        --XXX
        libtcod.image_clear(self.__tcod_light_image, libtcod.black)
        libtcod.image_set_key_color(self.__tcod_light_image, libtcod.black)
        r   = self.radius
        rd2 = r / 2
        i1  = self.raw_light_colour * self.intensity
        for x in range(r * 2 + 1):
            for y in range(r * 2 + 1):
                #print("(%d,%d)"%(x,y))
                if libtcod.map_is_in_fov(self.__tcod_light_map, x, y):
                    d = hypot(r - x, r - y)
                    if d > rd2:
                        libtcod.image_put_pixel(self.__tcod_light_image,
                                                x, y,
                                                i1 * (1.0 - (d - rd2) / rd2))
                        #print("  %s %s"%(d,i1*(1.0-(d-rd2)/rd2)))
                    else:
                        libtcod.image_put_pixel(self.__tcod_light_image,
                                                x, y,
                                                i1)
コード例 #9
0
ファイル: libbluebox.py プロジェクト: jarcane/BlueBox
 def clear_graphics(self):
     # wipes the current graphics layer
     if self.img is not None:
         libtcod.image_clear(self.img, self.background)
コード例 #10
0
ファイル: gEngine.py プロジェクト: GrishdaFish/Ascension
 def image_clear(self,i,r,g,b):
     col = libtcod.Color(r,g,b)
     libtcod.image_clear(self.mImages[i-1],col)