def animation(stdscr): for frame in fn(*args, **kwargs): stdscr.erase() for pxl in frame: if len(pxl) == 4: x,y,c,s = pxl canvas.set_text(x,y,s,c) col, row = get_pos(x,y) color = c color_pair = curses.color_pair(0) if color in palette.colors: color_pair = curses.color_pair(palette.colors[color]) stdscr.addnstr(row,col,s,len(s),color_pair) else: x,y,c = pxl canvas.set(x, y) canvas.set_color(x, y, c) col, row = get_pos(x, y) color = canvas.colors[row][col] color_pair = curses.color_pair(0) if color in palette.colors: color_pair = curses.color_pair(palette.colors[color]) stdscr.addstr(row, col, unichr(braille_char_offset+canvas.chars[row][col]).encode('utf-8'), color_pair) stdscr.refresh() if delay: sleep(delay) canvas.clear()
def set_color(self,x,y,color): """Set color to the given coords. :param x: x coordinate of the char to be colored :param y: y coordinate of the char to be colored """ col,row = get_pos(x,y) self.colors[row][col] = color
def set_text(self, x, y, text): """Set text to the given coords. :param x: x coordinate of the text start position :param y: y coordinate of the text start position """ col, row = get_pos(x, y) for i,c in enumerate(text): self.chars[row][col+i] = c
def set(self, x, y): """Set a pixel of the :class:`Canvas` object. :param x: x coordinate of the pixel :param y: y coordinate of the pixel """ x = normalize(x) y = normalize(y) col, row = get_pos(x, y) if type(self.chars[row][col]) != int: return self.chars[row][col] |= pixel_map[y % 4][x % 2]
def toggle(self, x, y): """Toggle a pixel of the :class:`Canvas` object. :param x: x coordinate of the pixel :param y: y coordinate of the pixel """ x = normalize(x) y = normalize(y) col, row = get_pos(x, y) if type(self.chars[row][col]) != int or self.chars[row][col] & pixel_map[y % 4][x % 2]: self.unset(x, y) else: self.set(x, y)
def animation(stdscr): for frame in fn(*args, **kwargs): stdscr.erase() for pxl in frame: if len(pxl) == 4: x, y, c, s = pxl canvas.set_text(x, y, s, c) col, row = get_pos(x, y) color = c color_pair = curses.color_pair(0) if color in palette.colors: color_pair = curses.color_pair(palette.colors[color]) stdscr.addnstr(row, col, s, len(s), color_pair) else: x, y, c = pxl canvas.set(x, y) canvas.set_color(x, y, c) col, row = get_pos(x, y) color = canvas.colors[row][col] color_pair = curses.color_pair(0) if color in palette.colors: color_pair = curses.color_pair(palette.colors[color]) stdscr.addstr( row, col, unichr(braille_char_offset + canvas.chars[row][col]).encode('utf-8'), color_pair) stdscr.refresh() if delay: sleep(delay) canvas.clear()
def unset(self, x, y): """Unset a pixel of the :class:`Canvas` object. :param x: x coordinate of the pixel :param y: y coordinate of the pixel """ x = normalize(x) y = normalize(y) col, row = get_pos(x, y) if type(self.chars[row][col]) == int: self.chars[row][col] &= ~pixel_map[y % 4][x % 2] if type(self.chars[row][col]) != int or self.chars[row][col] == 0: del(self.chars[row][col]) if not self.chars.get(row): del(self.chars[row])
def get(self, x, y): """Get the state of a pixel. Returns bool. :param x: x coordinate of the pixel :param y: y coordinate of the pixel """ x = normalize(x) y = normalize(y) dot_index = pixel_map[y % 4][x % 2] col, row = get_pos(x, y) char = self.chars.get(row, {}).get(col) if not char: return False if type(char) != int: return True return bool(char & dot_index)