Ejemplo n.º 1
0
def run(screen):
    scenes = []
    centre = (screen.width // 2, screen.height // 2)

    # Intro
    effects = [
        Stars(screen, (screen.width + screen.height) // 2, start_frame=0),
        Print(
            screen,
            FigletText(
                """I’m afraid sometimes you’ll play lonely games too, games you can’t win because
              you’ll play against you."""),
            x=centre[0] - 100,
            y=centre[1] - 20,
            clear=True,
            start_frame=0,
            stop_frame=200),
        Print(screen,
              Rainbow(screen, FigletText("Press <SPACE> to start")),
              x=centre[0] - 100,
              y=centre[1] - 20,
              clear=True,
              start_frame=200,
              stop_frame=2000),
    ]

    scenes.append(Scene(effects, -1))

    # Scene 1, start the game
    side_panel = [
        Print(screen,
              Box(screen.width // 5, screen.height, uni=screen.unicode_aware),
              0,
              0,
              start_frame=0),
        Print(screen,
              FigletText("Side", font="big"),
              x=0,
              y=1,
              clear=True,
              start_frame=0,
              stop_frame=100),
    ]

    effects = [
        Print(screen,
              Box((screen.width // 5) * 4,
                  screen.height,
                  uni=screen.unicode_aware),
              0,
              screen.width // 5,
              start_frame=0),
    ]

    final = side_panel + effects
    scenes.append(Scene(final, -1))
    screen.refresh()
    # sleep(100)

    screen.play(scenes, stop_on_resize=True)
Ejemplo n.º 2
0
    def test_box(self):
        """
        Check that the Box renderer works.
        """
        renderer = Box(10, 3)
        self.assertEqual(str(renderer),
                         "+--------+\n" + "|        |\n" + "+--------+\n")

        # Unicode rendering.
        renderer = Box(10, 3, uni=True)
        self.assertEqual(str(renderer),
                         "┌────────┐\n" + "│        │\n" + "└────────┘\n")
Ejemplo n.º 3
0
 def test_box(self):
     """
     Check that the Box renderer works.
     """
     renderer = Box(10, 3)
     self.assertEqual(str(renderer),
                      "+--------+\n" + "|        |\n" + "+--------+\n")
Ejemplo n.º 4
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)
Ejemplo n.º 5
0
    def prepare_display(self):
        # Effects are all the stuff which will be shown on the display
        # Speed 0 means: Redraw only when draw_next_frame is executed
        effects = [
            self.preset_frame, self.sender_frame,
            Print(self.screen, Box(80, 8, True), x=0, y=17, speed=0),
            Print(self.screen,
                  ColourImageFile(self.screen, LOGO, 9, bg=7),
                  x=0,
                  y=0,
                  speed=0),
            Print(self.screen,
                  FigletText(self.asciisierer(self.akt_sender_str)),
                  x=1,
                  y=18,
                  speed=0),
            Print(self.screen,
                  BarChart(4,
                           80, [self.get_vol],
                           colour=2,
                           char=' ',
                           bg=7,
                           scale=100,
                           axes=BarChart.X_AXIS,
                           intervals=25,
                           labels=True,
                           border=False),
                  x=0,
                  y=26,
                  transparent=False,
                  speed=0)
        ]

        # Start displaying
        self.scenes.append(Scene(effects, -1))
        self.screen.set_scenes(self.scenes)

        # Update the screen for the first time
        self.screen.draw_next_frame()
Ejemplo n.º 6
0
def RenderScene(screen, positions_dict):
    snake_renderer = StaticRenderer(images=[r'${6}X'])
    apple_renderer = StaticRenderer(images=[r'${7}O'])

    #Establish grid
    width, height = positions_dict['shape']
    effects = [Print(screen, Box(width + 2, height + 2), x=0, y=0, speed=0)]
    #Add apple
    apple_x, apple_y = positions_dict['apple']
    effects.append(
        Print(screen, apple_renderer, x=apple_x + 1, y=apple_y + 1, speed=0))
    #Add snake
    snake_pos = positions_dict['snake']
    for segment in snake_pos:
        effects.append(
            Print(screen,
                  snake_renderer,
                  x=segment[0] + 1,
                  y=segment[1] + 1,
                  speed=0))
    #Adds and draws next frame.
    screen.set_scenes([Scene(effects)])
    screen.draw_next_frame(repeat=False)
Ejemplo n.º 7
0
def demo(screen):
    scenes = []
    preset_frame = Frame(screen,
                         11,
                         26,
                         can_scroll=False,
                         title="Tastenbelegung",
                         x=SF_X,
                         y=SF_Y,
                         reduce_cpu=True)
    pr_layout = Layout([10, 90], fill_frame=True)
    preset_frame.add_layout(pr_layout)

    sender_frame = Frame(screen,
                         11,
                         26,
                         can_scroll=False,
                         title="Senderliste",
                         x=27,
                         y=6,
                         reduce_cpu=True)
    sender_layout0 = Layout([10, 90, 10], fill_frame=True)

    sender_frame.add_layout(sender_layout0)

    optionen = [(" ", 1), ("Zweiter", 2), ("Dritter", 3), ("Vierter", 4),
                ("Deutschlandradio", 5), ("Absolut Relax", 6), ("Siebter", 7),
                ("hmm", 8)]

    sender = [
        "123456789012345678901", "Erster", "Zweiter", "Dritter", "Vierter",
        "Fünfter", "Sechster"
    ]
    Senderkiste = ListBox(8, optionen, False)
    sender_layout0.add_widget(Senderkiste, 1)
    Senderkiste.blur()
    Senderkiste.start_line = 1

    format_sl_layout(sender_layout0)
    # format_pr_layout(pr_layout)
    for i, s in zip(range(1, 6), sender):
        pr_layout.add_widget(Label(str(i), 1, align=u'^'))
        pr_layout.add_widget(Label(s, 1, align='^'), 1)

    preset_frame.fix()
    sender_frame.fix()

    effects = [
        preset_frame,
        sender_frame,
        Print(screen, Box(26, 15, True), x=UHR_K_X, y=UHR_K_Y),
        Print(screen, Box(80, 8, True), x=0, y=17),
        Clock(screen, 67, 7, 6),
        Print(screen, FigletText("Retroradio!"), x=0, y=0),
        #            Print(screen, BarChart(4, 80, [get_vol], colour=2, scale=100,
        #                axes=BarChart.X_AXIS, intervals=25, labels=True, border=False), x=0, y=26,
        #                transparent=False),
        # Print(screen, SpeechBubble("Lautstärke"), x=0, y=23),
        Print(screen, FigletText("Deutschlandradio"), x=1, y=18),
        Print(screen,
              BarChart(4,
                       80, [get_vol],
                       colour=2,
                       char=' ',
                       bg=7,
                       scale=100,
                       axes=BarChart.X_AXIS,
                       intervals=25,
                       labels=True,
                       border=False),
              x=0,
              y=26,
              transparent=False,
              speed=2)
    ]

    scenes.append(Scene(effects, -1))
    screen.play(scenes)
Ejemplo n.º 8
0
def demo(screen):
    scenes = []
    centre = (screen.width // 2, screen.height // 2)
    podium = (8, 5)

    # Scene 1.
    path = Path()
    path.jump_to(-20, centre[1])
    path.move_straight_to(centre[0], centre[1], 10)
    path.wait(30)
    path.move_straight_to(podium[0], podium[1], 10)
    path.wait(100)

    effects = [
        Arrow(screen, path, colour=Screen.COLOUR_GREEN),
        _speak(screen, "WELCOME TO ASCIIMATICS", centre, 30),
        _speak(screen, "My name is Aristotle Arrow.", podium, 110),
        _speak(screen, "I'm here to help you learn ASCIImatics.", podium, 180),
    ]
    scenes.append(Scene(effects))

    # Scene 2.
    path = Path()
    path.jump_to(podium[0], podium[1])

    effects = [
        Arrow(screen, path, colour=Screen.COLOUR_GREEN),
        _speak(screen, "Let's start with the Screen...", podium, 10),
        _speak(screen, "This is your Screen object.", podium, 80),
        Print(screen,
              Box(screen.width, screen.height, uni=screen.unicode_aware),
              0,
              0,
              start_frame=90),
        _speak(screen, "It lets you play a Scene like this one I'm in.",
               podium, 150),
        _speak(screen, "A Scene contains one or more Effects.", podium, 220),
        _speak(screen, "Like me - I'm a Sprite!", podium, 290),
        _speak(screen, "Or these Stars.", podium, 360),
        _speak(screen, "As you can see, the Screen handles them both at once.",
               podium, 430),
        _speak(screen, "It can handle as many Effects as you like.", podium,
               500),
        _speak(screen, "Please press <SPACE> now.", podium, 570),
        Stars(screen, (screen.width + screen.height) // 2, start_frame=360)
    ]
    scenes.append(Scene(effects, -1))

    # Scene 3.
    path = Path()
    path.jump_to(podium[0], podium[1])

    effects = [
        Arrow(screen, path, colour=Screen.COLOUR_GREEN),
        _speak(screen, "This is a new Scene.", podium, 10),
        _speak(
            screen, "The Screen stops all Effects and clears itself between "
            "Scenes.", podium, 70),
        _speak(screen, "That's why you can't see the Stars now.", podium, 130),
        _speak(screen, "(Though you can override that if you need to.)",
               podium, 200),
        _speak(screen, "Please press <SPACE> now.", podium, 270),
    ]
    scenes.append(Scene(effects, -1))

    # Scene 4.
    path = Path()
    path.jump_to(podium[0], podium[1])

    effects = [
        Arrow(screen, path, colour=Screen.COLOUR_GREEN),
        _speak(screen, "So, how do you design your animation?", podium, 10),
        _speak(screen, "1) Decide on your cinematic flow of Scenes.", podium,
               80),
        _speak(screen, "2) Create the Effects in each Scene.", podium, 150),
        _speak(screen, "3) Pass the Scenes to the Screen to play.", podium,
               220),
        _speak(screen, "It really is that easy!", podium, 290),
        _speak(screen, "Just look at this sample code.", podium, 360),
        _speak(screen, "Please press <SPACE> now.", podium, 430),
    ]
    scenes.append(Scene(effects, -1))

    # Scene 5.
    path = Path()
    path.jump_to(podium[0], podium[1])

    effects = [
        Arrow(screen, path, colour=Screen.COLOUR_GREEN),
        _speak(screen, "There are various effects you can use.  For "
               "example...", podium, 10),
        Cycle(screen,
              FigletText("Colour cycling"),
              centre[1] - 5,
              start_frame=100),
        Cycle(screen,
              FigletText("using Figlet"),
              centre[1] + 1,
              start_frame=100),
        _speak(screen, "Look in the effects module for more...", podium, 290),
        _speak(screen, "Please press <SPACE> now.", podium, 360),
    ]
    scenes.append(Scene(effects, -1))

    # Scene 6.
    path = Path()
    path.jump_to(podium[0], podium[1])
    curve_path = []
    for i in range(0, 11):
        curve_path.append(
            (centre[0] + (screen.width / 4 * math.sin(i * math.pi / 5)),
             centre[1] - (screen.height / 4 * math.cos(i * math.pi / 5))))
    path2 = Path()
    path2.jump_to(centre[0], centre[1] - screen.height // 4)
    path2.move_round_to(curve_path, 60)

    effects = [
        Arrow(screen, path, colour=Screen.COLOUR_GREEN),
        _speak(screen, "Sprites (like me) are also an Effect.", podium, 10),
        _speak(screen, "We take a pre-defined Path to follow.", podium, 80),
        _speak(screen, "Like this one...", podium, 150),
        Plot(screen,
             path2,
             colour=Screen.COLOUR_BLUE,
             start_frame=160,
             stop_frame=300),
        _speak(screen, "My friend Sam will now follow it...", podium, 320),
        Sam(screen, copy.copy(path2), start_frame=380),
        _speak(screen, "Please press <SPACE> now.", podium, 420),
    ]
    scenes.append(Scene(effects, -1))

    # Scene 7.
    path = Path()
    path.jump_to(podium[0], podium[1])
    path.wait(60)
    path.move_straight_to(-5, podium[1], 20)
    path.wait(300)

    effects = [
        Arrow(screen, path, colour=Screen.COLOUR_GREEN),
        _speak(screen, "Goodbye!", podium, 10),
        Cycle(screen, FigletText("THE END!"), centre[1] - 4, start_frame=100),
        Print(screen,
              SpeechBubble("Press X to exit"),
              centre[1] + 6,
              start_frame=150)
    ]
    scenes.append(Scene(effects, 500))

    screen.play(scenes, stop_on_resize=True)
Ejemplo n.º 9
0
def play(_screen):
    global screen

    screen = _screen
    spacerect = " " * (ARENA_DIMMS[0] - 2) + "\n"
    spacerect *= ARENA_DIMMS[1] - 2

    effects = [
        Stars(screen, (screen.width + screen.height) // 2 + 45,
              delete_count=1),
        # Blackout
        Print(
            screen,
            renderer=StaticRenderer(images=[spacerect]),
            colour=Screen.COLOUR_BLACK,
            x=GLOBALOFFSETS[0] + 1,
            y=GLOBALOFFSETS[1] + 1,
            transparent=False,
            delete_count=1,
        ),
        # Print(screen, renderer=Plasma(screen.height, screen.width, 8), y=0),
        # frame update
        Print(screen,
              renderer=UpdateFrame(0, 0),
              colour=Screen.COLOUR_RED,
              y=0),
        # Arena geo
        Print(
            screen,
            renderer=Box(ARENA_DIMMS[0], ARENA_DIMMS[1], uni=True),
            y=GLOBALOFFSETS[1],
            x=GLOBALOFFSETS[0],
        ),
        Print(
            screen,
            renderer=GeometryRenderer(),
            colour=Screen.COLOUR_WHITE,
            x=GLOBALOFFSETS[0] + 4,
            y=GLOBALOFFSETS[1] + 14,
        ),
        # clock
        Print(
            screen,
            renderer=ClockText(),
            colour=Screen.COLOUR_CYAN,
            x=GLOBALOFFSETS[0] + 38,
            y=GLOBALOFFSETS[1],
            transparent=False,
        ),
        # scores
        Print(
            screen,
            renderer=ScoreText(TEAM_ORANGE),
            colour=Screen.COLOUR_RED,
            x=GLOBALOFFSETS[0] - 14,
            y=GLOBALOFFSETS[1],
            speed=20,
            transparent=False,
        ),
        Print(
            screen,
            renderer=ScoreText(TEAM_BLUE),
            colour=Screen.COLOUR_BLUE,
            x=GLOBALOFFSETS[0] + ARENA_DIMMS[0] + 1,
            y=GLOBALOFFSETS[1],
            speed=20,
            transparent=False,
        ),
        # disc sprite
        Sprite(
            screen,
            {"default": StaticRenderer(images=["()"])},
            path=DiscPath(screen, 5, 5),
            colour=Screen.COLOUR_GREEN,
        ),
        # players
        Sprite(
            screen,
            {"default": StaticRenderer(images=["•"])},
            path=PlayerPath(screen, 5, 5, TEAM_BLUE, 0),
            colour=Screen.COLOUR_BLUE,
        ),
        Print(
            screen,
            renderer=PlayerNameText(TEAM_BLUE, 0),
            colour=Screen.COLOUR_BLUE,
            x=GLOBALOFFSETS[0] + ARENA_DIMMS[0] + 1,
            y=GLOBALOFFSETS[1] + 24,
            speed=20,
            transparent=False,
        ),
        Sprite(
            screen,
            {"default": StaticRenderer(images=["•"])},
            path=PlayerPath(screen, 5, 5, TEAM_BLUE, 1),
            colour=Screen.COLOUR_BLUE,
        ),
        Print(
            screen,
            renderer=PlayerNameText(TEAM_BLUE, 1),
            colour=Screen.COLOUR_BLUE,
            x=GLOBALOFFSETS[0] + ARENA_DIMMS[0] + 1,
            y=GLOBALOFFSETS[1] + 26,
            speed=20,
            transparent=False,
        ),
        Sprite(
            screen,
            {"default": StaticRenderer(images=["•"])},
            path=PlayerPath(screen, 5, 5, TEAM_BLUE, 2),
            colour=Screen.COLOUR_BLUE,
        ),
        Print(
            screen,
            renderer=PlayerNameText(TEAM_BLUE, 2),
            colour=Screen.COLOUR_BLUE,
            x=GLOBALOFFSETS[0] + ARENA_DIMMS[0] + 1,
            y=GLOBALOFFSETS[1] + 28,
            speed=20,
            transparent=False,
        ),
        Sprite(
            screen,
            {"default": StaticRenderer(images=["•"])},
            path=PlayerPath(screen, 5, 5, TEAM_BLUE, 3),
            colour=Screen.COLOUR_BLUE,
        ),
        Print(
            screen,
            renderer=PlayerNameText(TEAM_BLUE, 3),
            colour=Screen.COLOUR_BLUE,
            x=GLOBALOFFSETS[0] + ARENA_DIMMS[0] + 1,
            y=GLOBALOFFSETS[1] + 30,
            speed=20,
            transparent=False,
        ),
        Sprite(
            screen,
            {"default": StaticRenderer(images=["•"])},
            path=PlayerPath(screen, 5, 5, TEAM_ORANGE, 0),
            colour=Screen.COLOUR_RED,
        ),
        Print(
            screen,
            renderer=PlayerNameText(TEAM_ORANGE, 0),
            colour=Screen.COLOUR_RED,
            y=GLOBALOFFSETS[1] + 24,
            x=GLOBALOFFSETS[0] - 17,
            speed=20,
            transparent=False,
        ),
        Sprite(
            screen,
            {"default": StaticRenderer(images=["•"])},
            path=PlayerPath(screen, 5, 5, TEAM_ORANGE, 1),
            colour=Screen.COLOUR_RED,
        ),
        Print(
            screen,
            renderer=PlayerNameText(TEAM_ORANGE, 1),
            colour=Screen.COLOUR_RED,
            x=GLOBALOFFSETS[0] - 17,
            y=GLOBALOFFSETS[1] + 26,
            speed=20,
            transparent=False,
        ),
        Sprite(
            screen,
            {"default": StaticRenderer(images=["•"])},
            path=PlayerPath(screen, 5, 5, TEAM_ORANGE, 2),
            colour=Screen.COLOUR_RED,
        ),
        Print(
            screen,
            renderer=PlayerNameText(TEAM_ORANGE, 2),
            colour=Screen.COLOUR_RED,
            x=GLOBALOFFSETS[0] - 17,
            y=GLOBALOFFSETS[1] + 28,
            speed=20,
            transparent=False,
        ),
        Sprite(
            screen,
            {"default": StaticRenderer(images=["•"])},
            path=PlayerPath(screen, 5, 5, TEAM_ORANGE, 3),
            colour=Screen.COLOUR_RED,
        ),
        Print(
            screen,
            renderer=PlayerNameText(TEAM_ORANGE, 3),
            colour=Screen.COLOUR_RED,
            x=GLOBALOFFSETS[0] - 17,
            y=GLOBALOFFSETS[1] + 30,
            speed=20,
            transparent=False,
        ),
        # Hotness
        Print(
            screen,
            renderer=Fire(8, 125, "*" * 110, 0.8, 20, screen.colours),
            y=GLOBALOFFSETS[1] + ARENA_DIMMS[1],
            x=0,
        ),
        # Title
        Print(
            screen,
            renderer=FigletText("Echo Arena", font="big"),
            y=GLOBALOFFSETS[1] + ARENA_DIMMS[1],
            x=GLOBALOFFSETS[0] + 9,
        ),
        Print(
            screen,
            renderer=StaticRenderer(images=["by qlyoung"]),
            colour=Screen.COLOUR_YELLOW,
            y=GLOBALOFFSETS[1] + ARENA_DIMMS[1],
            x=GLOBALOFFSETS[0] + 50,
        ),
    ]

    scenes["main"] = Scene(effects, -1, clear=True)

    screen.play([scenes["main"]])
    sleep(10)
Ejemplo n.º 10
0
def run_display(screen):
    scenes = []
    AKT_SENDER = "Retro rockt!"

    # Prepare frame for the presets
    preset_frame = Frame(screen,
                         7,
                         29,
                         can_scroll=False,
                         title="Tastenbelegung",
                         x=0,
                         y=10,
                         reduce_cpu=True)
    pr_layout = Layout([10, 90], fill_frame=True)
    preset_frame.add_layout(pr_layout)

    # Prepare frame for the sender list
    sender_frame = Frame(screen,
                         17,
                         50,
                         can_scroll=False,
                         title="Senderliste",
                         x=30,
                         y=0,
                         reduce_cpu=True)
    sender_layout0 = Layout([10, 80, 10], fill_frame=True)
    sender_frame.add_layout(sender_layout0)

    # Load the json config-file
    cfg = load_config()

    # Prepare the layouts, add spaces etc
    format_sl_layout(sender_layout0)

    # Nicht mehr nötig nach aktuellem Stand
    # format_pr_layout(pr_layout)

    # Create the sender-labels and fill them initially. Return them for
    # later changing
    sender_labels = gen_and_add_sender_labels(sender_layout0,
                                              parse_sender(cfg, 0))
    preset_labels = gen_and_add_preset_labels(pr_layout, parse_presets(cfg))

    preset_frame.fix()
    sender_frame.fix()

    # Effects are all the stuff which will be shown on the display
    effects = [
        preset_frame,
        sender_frame,
        # Print(screen, Box(26, 15, True), x=54, y=0),
        Print(screen, Box(80, 8, True), x=0, y=17, speed=2),
        # Clock(screen, 68, 7, 5),
        Print(screen,
              ColourImageFile(screen, LOGO, 9, bg=7),
              x=0,
              y=0,
              speed=2),
        Print(screen, FigletText(asciisierer(AKT_SENDER)), x=1, y=18),
        Print(screen,
              BarChart(4,
                       80, [get_vol],
                       colour=2,
                       char=' ',
                       bg=7,
                       scale=100,
                       axes=BarChart.X_AXIS,
                       intervals=25,
                       labels=True,
                       border=False),
              x=0,
              y=26,
              transparent=False,
              speed=2)
    ]

    # Start displaying
    scenes.append(Scene(effects, -1))
    screen.play(scenes)