def console_get_char_foreground(self,con,x,y): if con == 0: col = libtcod.console_get_char_foreground(0,x,y) return col else: col = libtcod.console_get_char_foreground(self.mConsole[con-1],x,y) return col
def assertConsolesEqual(a, b): for y in range(libtcodpy.console_get_height(a)): for x in range(libtcodpy.console_get_width(a)): assert libtcodpy.console_get_char(a, x, y) == \ libtcodpy.console_get_char(b, x, y) assert libtcodpy.console_get_char_foreground(a, x, y) == \ libtcodpy.console_get_char_foreground(b, x, y) assert libtcodpy.console_get_char_background(a, x, y) == \ libtcodpy.console_get_char_background(b, x, y)
def assert_char(console, x, y, ch=None, fg=None, bg=None): if ch is not None: try: ch = ord(ch) except TypeError: pass assert libtcodpy.console_get_char(console, x, y) == ch if fg is not None: assert libtcodpy.console_get_char_foreground(console, x, y) == fg if bg is not None: assert libtcodpy.console_get_char_background(console, x, y) == bg
def test_console_fill(console): width = libtcodpy.console_get_width(console) height = libtcodpy.console_get_height(console) fill = [i % 256 for i in range(width * height)] libtcodpy.console_fill_background(console, fill, fill, fill) libtcodpy.console_fill_foreground(console, fill, fill, fill) libtcodpy.console_fill_char(console, fill) # verify fill bg, fg, ch = [], [], [] for y in range(height): for x in range(width): bg.append(libtcodpy.console_get_char_background(console, x, y)[0]) fg.append(libtcodpy.console_get_char_foreground(console, x, y)[0]) ch.append(libtcodpy.console_get_char(console, x, y)) assert fill == bg assert fill == fg assert fill == ch
def test_console_fill_numpy(console): width = libtcodpy.console_get_width(console) height = libtcodpy.console_get_height(console) fill = numpy.zeros((height, width), dtype=numpy.intc) for y in range(height): fill[y, :] = y % 256 libtcodpy.console_fill_background(console, fill, fill, fill) libtcodpy.console_fill_foreground(console, fill, fill, fill) libtcodpy.console_fill_char(console, fill) # verify fill bg = numpy.zeros((height, width), dtype=numpy.intc) fg = numpy.zeros((height, width), dtype=numpy.intc) ch = numpy.zeros((height, width), dtype=numpy.intc) for y in range(height): for x in range(width): bg[y, x] = libtcodpy.console_get_char_background(console, x, y)[0] fg[y, x] = libtcodpy.console_get_char_foreground(console, x, y)[0] ch[y, x] = libtcodpy.console_get_char(console, x, y) fill = fill.tolist() assert fill == bg.tolist() assert fill == fg.tolist() assert fill == ch.tolist()
def get_color_fg(self, position): x, y = position return libtcod.console_get_char_foreground(x, y)
def console_invert_color(con, x, y): col1 = libtcod.console_get_char_foreground(con, x, y) col2 = libtcod.console_get_char_background(con, x, y) libtcod.console_set_char_foreground(con, x, y, color_invert(col1)) libtcod.console_set_char_background(con, x, y, color_invert(col2))
color_masks = [[0, 0, 255], [68,68,196], [66,66,193]] for angle in range(0, 360, 10): ship = libtcod.image_load('images/ship_{0}.png'.format(str(angle).zfill(3))) # libtcod.image_blit(ship, con, 8, 8, libtcod.BKGND_SET, 1.0, 1.0, 0) libtcod.image_blit_2x(ship, con, 0, 0) libtcod.console_blit(con, 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, 0, 0, 0) frame = [] for y in range(0, SCREEN_HEIGHT): row = [] for x in range(0, SCREEN_WIDTH): b = libtcod.console_get_char_background(con,x,y) f = libtcod.console_get_char_foreground(con,x,y) c = libtcod.console_get_char(con,x,y) if c == 32: f = b c = 219 if [b[0], b[1], b[2]] in color_masks or [f[0], f[1], f[2]] in color_masks: row.append( None ) elif [b[0], b[1], b[2]] == [0,0,0] and [f[0], f[1], f[2]] == [0,0,0]: row.append( None ) else: row.append( [b, f, c] ) frame.append(row) # pp(frame) frames.append(frame) libtcod.console_flush()
def set_color(color, x, y): if (tcod.console_get_char_foreground(0, x, y) == tcod.Color( color[0], color[1], color[2])): return else: tcod.console_set_char_foreground(0, x, y, color)