Ejemplo n.º 1
0
    def test_sprite(self):
        """
        Check that Sprites work.
        """
        # Check that we can move a Sprite around the screen.
        screen = MagicMock(spec=Screen, colours=8)
        canvas = Canvas(screen, 10, 40, 0, 0)
        path = Path()
        path.jump_to(10, 5)
        path.move_straight_to(20, 10, 5)
        path.move_straight_to(30, 5, 5)
        path.move_straight_to(20, 0, 5)
        path.move_straight_to(10, 5, 5)
        effect = Sam(canvas, path)
        effect.reset()
        self.assert_blank(canvas)
        buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)]
        for i in range(30):
            effect.update(i)
            self.assertEqual(self.check_canvas(
                canvas,
                buffer,
                lambda value: self.assertLess(value[0], 129)),
                i % 2 == 0, "Bad update on frame %d" % i)

        # Check there is no stop frame by default.
        self.assertEqual(effect.stop_frame, 0)
Ejemplo n.º 2
0
    def test_sprite(self):
        """
        Check that Sprites work.
        """
        # Check that we can move a Sprite around the screen.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        path = Path()
        path.jump_to(10, 5)
        path.move_straight_to(20, 10, 5)
        path.move_straight_to(30, 5, 5)
        path.move_straight_to(20, 0, 5)
        path.move_straight_to(10, 5, 5)
        effect = Sam(canvas, path)
        effect.reset()
        self.assert_blank(canvas)
        my_buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)]
        for i in range(30):
            effect.update(i)
            self.assertEqual(
                self.check_canvas(
                    canvas, my_buffer,
                    lambda value: self.assertLess(value[0], 129)), i % 2 == 0,
                "Bad update on frame %d" % i)

        # Check there is no stop frame by default.
        self.assertEqual(effect.stop_frame, 0)

        # Static paths should pay no attention to events.
        event = object()
        self.assertEqual(event, effect.process_event(event))
Ejemplo n.º 3
0
    def test_sprite(self):
        """
        Check that Sprites work.
        """
        # Check that we can move a Sprite around the screen.
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        path = Path()
        path.jump_to(10, 5)
        path.move_straight_to(20, 10, 5)
        path.move_straight_to(30, 5, 5)
        path.move_straight_to(20, 0, 5)
        path.move_straight_to(10, 5, 5)
        effect = Sam(canvas, path)
        effect.reset()
        self.assert_blank(canvas)
        my_buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)]
        for i in range(30):
            effect.update(i)
            self.assertEqual(self.check_canvas(
                canvas,
                my_buffer,
                lambda value: self.assertLess(value[0], 129)),
                i % 2 == 0, "Bad update on frame %d" % i)

        # Check there is no stop frame by default.
        self.assertEqual(effect.stop_frame, 0)

        # Static paths should pay no attention to events.
        event = object()
        self.assertEqual(event, effect.process_event(event))
Ejemplo n.º 4
0
    def test_sprite(self):
        """
        Check that Sprites work.
        """
        # Check that we can move a Sprite around the screen.
        screen = MagicMock(spec=Screen, colours=8)
        canvas = Canvas(screen, 10, 40, 0, 0)
        path = Path()
        path.jump_to(10, 5)
        path.move_straight_to(20, 10, 5)
        path.move_straight_to(30, 5, 5)
        path.move_straight_to(20, 0, 5)
        path.move_straight_to(10, 5, 5)
        effect = Sam(canvas, path)
        effect.reset()
        self.assert_blank(canvas)
        buffer = [[(32, 7, 0, 0) for _ in range(40)] for _ in range(10)]
        for i in range(30):
            effect.update(i)
            self.assertEqual(
                self.check_canvas(
                    canvas, buffer,
                    lambda value: self.assertLess(value[0], 129)), i % 2 == 0,
                "Bad update on frame %d" % i)

        # Check there is no stop frame by default.
        self.assertEqual(effect.stop_frame, 0)
Ejemplo n.º 5
0
    def test_sprite_overlap(self):
        """
        Check that Sprites detect overlap.
        """
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        path = Path()
        path.jump_to(10, 5)
        effect1 = Sam(canvas, path)
        effect2 = Sam(canvas, path)

        # These 2 sprites should overlap!
        effect1.reset()
        effect1.update(0)
        effect2.reset()
        effect2.update(0)
        self.assertTrue(effect1.overlaps(effect2))

        # Now create a sprite that shouldn't quite overlap
        width = effect1.last_position()[2]
        path = Path()
        path.jump_to(10 + width, 5)
        effect2 = Sam(canvas, path)
        effect2.reset()
        effect2.update(0)
        self.assertFalse(effect1.overlaps(effect2))
Ejemplo n.º 6
0
def _credits(screen):
    scenes = []
    centre = (screen.width // 2, screen.height // 2)
    curve_path = []
    for i in range(0, 11):
        curve_path.append(
            (centre[0] + (screen.width / 3 * math.sin(i * math.pi / 5)),
             centre[1] - (screen.height / 3 * math.cos(i * math.pi / 5))))
    path = Path()
    path.jump_to(-20, centre[1] - screen.height // 3)
    path.move_straight_to(centre[0], centre[1] - screen.height // 3, 10),
    path.wait(30)
    path.move_round_to(curve_path, 80)
    path.wait(30)
    path.move_straight_to(7, 4, 10)
    path.wait(300)

    effects = [
        Sam(screen, path),
        Print(screen,
              SpeechBubble("WELCOME TO ASCIIMATICS", "L"),
              x=centre[0] + 12,
              y=(centre[1] - screen.height // 3) - 4,
              colour=Screen.COLOUR_CYAN,
              clear=True,
              start_frame=20,
              stop_frame=50),
        Print(screen,
              SpeechBubble("Wheeeeeee!"),
              y=centre[1],
              colour=Screen.COLOUR_CYAN,
              clear=True,
              start_frame=100,
              stop_frame=250),
        Print(screen,
              SpeechBubble("A world of possibilities awaits you...", "L"),
              x=18,
              y=0,
              colour=Screen.COLOUR_CYAN,
              clear=True,
              start_frame=350,
              stop_frame=400),
        Print(screen,
              ImageFile("globe.gif", colours=screen.colours),
              0,
              start_frame=400),
    ]
    scenes.append(Scene(effects, 600))

    effects = [
        Matrix(screen, stop_frame=200),
        Mirage(screen,
               FigletText("Asciimatics"),
               screen.height // 2 - 3,
               Screen.COLOUR_GREEN,
               start_frame=100,
               stop_frame=200),
        Wipe(screen, start_frame=150),
        Cycle(screen,
              FigletText("Asciimatics"),
              screen.height // 2 - 3,
              start_frame=200)
    ]
    scenes.append(Scene(effects, 250, clear=False))

    effects = [
        BannerText(
            screen,
            Rainbow(
                screen,
                FigletText("Reliving the 80s in glorious ASCII text...",
                           font='slant')), screen.height // 2 - 3,
            Screen.COLOUR_GREEN)
    ]
    scenes.append(Scene(effects))

    effects = [
        Mirage(screen, FigletText("Conceived and"), screen.height,
               Screen.COLOUR_GREEN),
        Mirage(screen, FigletText("written by:"), screen.height + 8,
               Screen.COLOUR_GREEN),
        Mirage(screen, FigletText("Peter Brittain"), screen.height + 16,
               Screen.COLOUR_GREEN),
        Scroll(screen, 3)
    ]
    scenes.append(Scene(effects, (screen.height + 24) * 3))

    effects = [
        Cycle(screen, FigletText("ASCIIMATICS", font='big'),
              screen.height // 2 - 8),
        Cycle(screen, FigletText("ROCKS!", font='big'),
              screen.height // 2 + 3),
        Stars(screen, (screen.width + screen.height) // 2)
    ]
    scenes.append(Scene(effects, 200))

    screen.play(scenes, stop_on_resize=True)
Ejemplo n.º 7
0
    def test_sprite_overlap(self):
        """
        Check that Sprites detect overlap.
        """
        screen = MagicMock(spec=Screen, colours=8, unicode_aware=False)
        canvas = Canvas(screen, 10, 40, 0, 0)
        path = Path()
        path.jump_to(10, 5)
        effect1 = Sam(canvas, path)
        effect2 = Sam(canvas, path)

        # These 2 sprites should overlap!
        effect1.reset()
        effect1.update(0)
        effect2.reset()
        effect2.update(0)
        self.assertTrue(effect1.overlaps(effect2))

        # Now create a sprite that shouldn't quite overlap
        width = effect1.last_position()[2]
        path = Path()
        path.jump_to(10 + width, 5)
        effect2 = Sam(canvas, path)
        effect2.reset()
        effect2.update(0)
        self.assertFalse(effect1.overlaps(effect2))
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 test_init(self):
     # Most of the function in these classes is actually in the Sprite
     # base Effect - so just check we can build these classes
     self.assertIsNotNone(Sam(None, Path()))
     self.assertIsNotNone(Arrow(None, Path()))
     self.assertIsNotNone(Plot(None, Path()))