def update_visual(screen: Screen, inputs: list[int], cursor_one: int, cursor_two: int): x, y, index = 0, 0, 0 row = 20 for number in inputs: if cursor_one == index: bg = 3 colour = 0 elif cursor_two == index: bg = 13 colour = 0 else: bg = 0 colour = 10 screen.print_at(text=f'{number}', x=x, y=y, colour=colour, bg=bg) index += 1 if (index % row) == 0: y = 0 x += 7 else: y += 1 screen.refresh()
def render_fullchars(screen: Screen, vm: VM, x_start: int = 0, y_start: int = 1, colours=DEFAULT_COLORS, block_char: str = FULL) -> None: """ Helper to render the screen using full-height characters. Unless the user has set up a square font for their console, this will likely show up as non-square pixels in the terminal. Not very fancy, but it's probably compatible with everything. If for some reason you are using this on a system that doesn't support unicode characters or background colors, you can set block_char to something like '#' and the display should still work. :param screen: asciimatics screen to draw to :param vm: the Chip 8 VM to source vram from :param x_start: where to start drawing the display area :param y_start: where to to start drawing the display area :param colours: a list of asciimatics colors to draw in :param block_char: what tile to use for showing a full pixel. """ vram = vm.video_ram for x, y in screen_coordinates(vm): screen.print_at(block_char if vram[x, y] else ' ', x + x_start, y + y_start, colour=colours[1], bg=colours[0])
def print_region_icons(self, screen: Screen): while True: y_index = 0 for i in self.world: x_index = 0 for j in i: screen.print_at(f'{j.icon}', x_index * 2, y_index) x_index += 1 y_index += 1 ev = screen.get_key() if ev in (ord('Q'), ord('q')): return screen.refresh()
def print_world_tile_types(self, screen: Screen): while True: y_index = 0 for i in self.world: x_index = 0 for j in i: if j.type == 'Land': color = Screen.COLOUR_GREEN else: color = Screen.COLOUR_BLUE screen.print_at(f'{j.height}', x_index * 2, y_index, color) x_index += 1 y_index += 1 ev = screen.get_key() if ev in (ord('Q'), ord('q')): return screen.refresh()
def print_world_heights(self, screen: Screen): for c in self.continents: c.set_tile_icons_to_continent_icon() forest_colors = [23, 29, 22, 28, 34, 40, 46, 83, 85] ocean_colors = [17, 18, 19, 20, 21, 33, 45, 201, 201, 201] mountain_colors = [201, 201, 201, 233, 235, 237, 241, 248, 252, 255] desert_colors = [ 3, 186, 190, 226, 227, 228, 229, 230, 252, 255 ] # [130, 136, 172, 178, 220, 226, 228, 230, 252, 255] color_table = [201, 201, 201, 201, 201, 201, 201, 201, 201] while True: y_index = 0 for i in self.world: x_index = 0 for j in i: if j.type is not 'Land': color_table = ocean_colors elif j.terrain is 'Desert': color_table = desert_colors elif j.height < 6: color_table = forest_colors elif j.height >= 6: color_table = mountain_colors color = color_table[j.height] screen.print_at(f'{j.height}{j.icon}', x_index * 2, y_index, colour=16, bg=color) x_index += 1 y_index += 1 ev = screen.get_key() if ev in (ord('Q'), ord('q')): # for c in self.continents: # c.set_tile_icons_to_region_icon() return screen.refresh()
def print_continent_icons(self, screen: Screen): for c in self.continents: c.set_tile_icons_to_continent_icon() while True: y_index = 0 for i in self.world: x_index = 0 for j in i: screen.print_at(f'{j.icon}', x_index * 2, y_index) x_index += 1 y_index += 1 ev = screen.get_key() if ev in (ord('Q'), ord('q')): for c in self.continents: c.set_tile_icons_to_region_icon() return screen.refresh()
def render_halfchars(screen: Screen, vm: VM, x_start: int = 0, y_start: int = 1, colours=DEFAULT_COLORS) -> None: """ Render the screen with half-height block characters. :param screen: which screen to draw to :param vm: a chip 8 VM to render the screen of :param x_start: where to start drawing the display area :param y_start: where to to start drawing the display area :param colours: a list of asciimatics colors to draw with. """ vram = vm.video_ram for x, y in screen_coordinates(vm, y_step=2): screen.print_at(HALF_TOP, x_start + x, y_start + y // 2, colour=colours[vram[x, y]], bg=colours[vram[x, y + 1]])
def pyre(screen: Screen): screen.clear() screen.print_at('Hello world!', 0, 0) screen.refresh() sleep(10) pass
def choose_build_type_with_screen( screen: Screen, build_type_options: List[BuildTypeOption] ) -> Optional[BuildTypeDecision]: ''' TODOCUMENT :param screen : TODOCUMENT :param build_type_options : TODOCUMENT ''' # Seem to need to do this to prevent the first printed line always using white foreground color screen.print_at( '.', 0, 0, ) screen.refresh() screen.print_at( ' ', 0, 0, ) build_types = [x.build_type for x in build_type_options] active_index = 0 cmake_it = False if 'BUILDTYPE' in os.environ and os.environ['BUILDTYPE'] in build_types: active_index = build_types.index(os.environ['BUILDTYPE']) # Run the event loop while True: # Print the build_type_options for option_idx, build_type_option in enumerate(build_type_options): max_build_type_len = max(len(x) for x in build_types) is_active = option_idx == active_index screen.print_at( (f' { build_type_option.build_type:{max_build_type_len}} ' + (' ' if build_type_option.presence == BuildPresence.ABSENT else '?' if build_type_option.presence == BuildPresence.HAS_DIR else u'\u2713') + (' ' if build_type_option.is_standard else ' [not-in-standard-list] ')), x=4, y=option_idx, bg=(COLOUR_BRIGHT_RED if cmake_it else Screen.COLOUR_WHITE) if is_active else Screen.COLOUR_BLACK, colour=Screen.COLOUR_BLACK if is_active else Screen.COLOUR_WHITE, ) for y_val, text in enumerate( ('', '[up/down] : change selection', '[enter] : select', '[spacebar] : toggle whether to also (re)run conan/cmake (indicated by red)', '[q] : quit with no change', '', u'\u2713' + ' : ninja file exists in directory', '? : directory exists'), len(build_type_options)): screen.print_at( text, x=0, y=y_val, ) # Get any event and respond to relevant keys event = screen.get_event() if isinstance(event, KeyboardEvent): if event.key_code == ord("\n"): return BuildTypeDecision( build_type=build_type_options[active_index].build_type, cmake_it=cmake_it) if event.key_code in (Screen.KEY_ESCAPE, ord('Q'), ord('q')): return None if event.key_code == Screen.KEY_DOWN: active_index = active_index + 1 if active_index + 1 < len( build_type_options) else 0 elif event.key_code == Screen.KEY_UP: active_index = active_index - 1 if active_index > 0 else len( build_type_options) - 1 elif event.key_code == ord(' '): cmake_it = not cmake_it # Refresh screen screen.refresh()