def run_animation(self):
        FPS = 1 / 20
        with ManagedScreen() as screen:
            self.screen = screen
            while True:
                # clear self.screen
                self.screen.clear_buffer(self.screen.COLOUR_WHITE,
                                         self.screen.A_NORMAL,
                                         self.screen.COLOUR_BLACK)

                _continue = True
                self.handle_input()

                self.draw_load_error()

                if self.sprite and self.active_state and self.active_direction:
                    self.draw_states()
                    self.draw_directions()
                    self.draw_sprite()
                else:
                    self.iter_sprite_state()
                    self.change_sprite_direction()

                # draw the self.screen!
                self.screen.refresh()

                sleep(FPS)

                self.tick(FPS)
예제 #2
0
def display(layout):
    with ManagedScreen() as screen:
        for r in range(0, len(layout)):
            for c in range(0, len(layout[0])):
                screen.print_at(layout[r][c], r, c)

        screen.refresh()
        sleep(0.8)
예제 #3
0
파일: loopy.py 프로젝트: Filip98/tools
	def try_kb(func):
		def inner(self, screen):
			try:
				func(self, screen)
			except KeyboardInterrupt:
				pass
			finally:
				screen.clear()
		return ManagedScreen(inner)
예제 #4
0
    def test_context_manager(self):
        """
        Check ManagedScreen context manager works.
        """
        with ManagedScreen() as screen:
            canvas = Canvas(screen, 10, 40, 0, 0)

            # Check underflow and overflow work as expected
            canvas.print_at("ab", -1, 0)
            canvas.print_at("cd", canvas.width - 1, 0)
            self.assert_line_equals(canvas, "b                                      c")
예제 #5
0
파일: main.py 프로젝트: nios34/A-D-B-
def demo():
    with ManagedScreen() as screen:
        Command.Start_PREPAR(screen)
        Command.Start_CHECK(screen)
        Command.Wait_for_DEVICE(screen)

        screen.clear()
        screen.refresh()

        Command.Main_menu(screen)
        pass
예제 #6
0
 def start_render_loop(self):
     while True:
         try:
             with ManagedScreen() as screen:
                 while True:
                     self.render(screen=screen)
                     time.sleep(0.01667)
         except ResizeScreenError as e:
             continue
         except Exception as e:
             print(e)
             sys.exit(0)
예제 #7
0
def state_printer(pioneer: Pioneer):
    """Draws a box and fills it with information from the drone"""
    with ManagedScreen() as screen:
        effects = [
            Print(screen, Box(screen.width, 12, uni=screen.unicode_aware), 0,
                  0)
        ]
        screen.set_scenes([Scene(effects)])
        while True:
            screen.draw_next_frame()
            print_state(screen, pioneer)
            screen.refresh()
            sleep(0.2)
def visualize_maze_creation(grid: Grid):
    full_grid = np.copy(grid.to_ndarray())
    full_grid[:, :] = Grid.WALL
    with ManagedScreen() as screen:
        for point in grid.get_maze_history():
            full_grid[point] = Grid.EMPTY
            g = visualize_grid(grid=full_grid)

            for j, row in enumerate(g.split("\n")):
                screen.print_at(row, 0, j)
            screen.refresh()
            sleep(0.005)
    sleep(20)
예제 #9
0
    async def run(self):
        FPS = 1 / 20
        with ManagedScreen() as screen:
            self.screen = screen
            while True:
                _continue = True

                self.handle_input()

                self.tick(FPS)

                # clear screen
                self.screen.clear_buffer(self.screen.COLOUR_WHITE,
                                         self.screen.A_NORMAL,
                                         self.screen.COLOUR_BLACK)
                self.draw_hit_points()

                # render map, player is center
                for y_coord, row in current_room.tiles.items():
                    for x_coord, tile in row.items():
                        name = ' '
                        draw_colour = self.screen.COLOUR_WHITE
                        if tile.is_visible:
                            name = tile.name
                            draw_colour = self.screen.COLOUR_WHITE
                        elif tile.seen:
                            name = tile.name
                            draw_colour = self.screen.COLOUR_MAGENTA
                        self.draw_tile(name, x_coord, y_coord, draw_colour)

                self.draw_player(player)
                for uid, other_player in other_players.items():
                    self.draw_player(other_player)

                for uid, creature in creatures.items():
                    self.draw_creature(creature)
                '''
                for creature in self.player.room.creatures:
                    if creature.current_tile.is_visible:
                        creature.draw(self, dt=fps)'''

                # draw the screen!
                self.screen.refresh()
                await asyncio.sleep(FPS)
예제 #10
0
def stickbug():
    mixer.init()
    mixer.music.load('bg.mp3')
    mixer.music.play()
    with ManagedScreen() as screen:
        for t in range(9):
            for i in [1, 2, 3, 4, 3, 2]:
                screen.clear_buffer(2, 0, 0)
                coords = stick_bug_coordinates[i]
                screen.move(*coords[0][0])
                screen.draw(*coords[0][1], thin=False)
                for p in coords[1]:
                    thin_draw = p[0]
                    screen.move(*p[1])
                    for l in p[2:]:
                        screen.draw(*l, thin=thin_draw)
                screen.print_at('GET STICK BUGGED LOL', 27, 2)
                screen.refresh()
                sleep(0.15)
예제 #11
0
def print_colors():
    print('...')
    with ManagedScreen() as screen:
        screen.clear_buffer(screen.COLOUR_WHITE, screen.A_NORMAL,
                            screen.COLOUR_BLACK)
        col = 0
        for color in range(254):
            if color >= screen.height * col:
                col += 1
            screen.print_at("## %s" % color,
                            col * 10,
                            color % screen.height,
                            colour=color)

        screen.refresh()
        while True:
            event = screen.get_event()
            if event:
                exit(0)
            sleep(.5)
def visualize_asciimatics(res):
    with ManagedScreen() as screen:
        # print visited one by one
        for i in range(1, len(res["visited"])):
            grid = visualize_grid(res["grid"],
                                  visited=res["visited"][:i + 1],
                                  start=res["start"],
                                  goal=res["goal"])
            for j, row in enumerate(grid.split("\n")):
                screen.print_at(row, 0, j)
            screen.refresh()
            sleep(0.03)
        # print path
        grid = visualize_grid(res["grid"],
                              visited=res["visited"],
                              path=res["path"],
                              start=res["start"],
                              goal=res["goal"])
        for j, row in enumerate(grid.split("\n")):
            screen.print_at(row, 0, j)

        screen.refresh()
        sleep(20)
예제 #13
0
    Instruction(9, 1, rel),
    Instruction(99, 0, lambda _: 1)
]
instructions = {i.opcode: i for i in instruction_list}


def setup():
    intcode = Intcode(opcodes, instructions, [])
    screen = [[0 for x in range(50)] for y in range(50)]
    maze = Maze(screen, intcode)
    maze.traverse()
    # delete robot from screen
    maze.screen[maze.y][maze.x] = 4
    maze.flood_from_oxygen()
    return maze


if PRETTY:
    with ManagedScreen() as term:
        terminal = term
        terminal.clear()
        maze = setup()
        sleep(3)
else:
    maze = setup()

# 1st
print(maze.flooded_start_pos_step + 2)

# 2nd
print(maze.flood_step)
예제 #14
0
    def run(self):
        """The main drawing loop."""
        try:
            # outer loop to support screen resize
            while True:
                with ManagedScreen() as screen:
                    logger.debug(f"Created new screen {screen}")
                    self.set_screen(screen)
                    self.frame = 0
                    # break (and re-enter) when screen has been resized
                    while not screen.has_resized():
                        # keep previous sort in memory to know if we have to re-sort the rows
                        # once all events are processed (to avoid useless/redundant sort passes)
                        previous_sort = (self.sort, self.reverse)

                        # we only refresh when explicitly asked for
                        self.refresh = False

                        # process all events before refreshing screen,
                        # otherwise the reactivity is slowed down a lot with fast inputs
                        event = screen.get_event()
                        logger.debug(f"Got event {event}")
                        while event:
                            # avoid crashing the interface if exceptions occur while processing an event
                            try:
                                self.process_event(event)
                            except Exit:
                                logger.debug(f"Received exit command")
                                return True
                            except Exception as error:
                                # TODO: display error in status bar
                                logger.exception(error)
                            event = screen.get_event()
                            logger.debug(f"Got event {event}")

                        # time to update data and rows
                        if self.frame == 0:
                            logger.debug(f"Tick! Updating data and rows")
                            self.update_data()
                            self.update_rows()
                            self.refresh = True

                        # time to refresh the screen
                        if self.refresh:
                            logger.debug(f"Refresh! Printing text")
                            # sort if needed, unless it was just done at frame 0 when updating
                            if (self.sort, self.reverse
                                ) != previous_sort and self.frame != 0:
                                self.sort_data()
                                self.update_rows()

                            # actual printing and screen refresh
                            for print_function in self.state_mapping[
                                    self.state]["print_functions"]:
                                print_function()
                            screen.refresh()

                        # sleep and increment frame
                        time.sleep(self.sleep)
                        self.frame = (self.frame + 1) % self.frames
                    logger.debug("Screen has resized")
                    self.post_resize()
        except Exception as error:
            logger.exception(error)
            return False
예제 #15
0
def print_state(screen: ManagedScreen, pioneer: Pioneer):
    """Updates and prints some of the information from the drone"""
    screen.print_at(f"Lights: {pioneer.lights * 100 // 255:3d} %", 2, 1)

    screen.print_at(
        f"Auto-depth: {'On' if pioneer.motion.auto_depth_active else 'Off':>5}",
        2, 3)
    screen.print_at(
        f"Auto-heading: {'On' if pioneer.motion.auto_heading_active else 'Off':>3}",
        2,
        4,
    )

    screen.print_at(f"Depth: {pioneer.depth} mm", 2, 6)

    screen.print_at(f"Roll: {pioneer.pose['roll']:7.2f}°", 2, 8)
    screen.print_at(f"Pitch: {pioneer.pose['pitch']:6.2f}°", 2, 9)
    screen.print_at(f"Yaw: {pioneer.pose['yaw']:8.2f}°", 2, 10)