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)
def confugur(screen): global timer global selection global logic path = Path() path.jump_to(50, 12) effects = [ NinjaRobotScroller(screen, path), Print(screen, SelectorBox(1), x=0, y=0), Print(screen, SelectorBox(3), x=18, y=0), Print(screen, SelectorBox(2), x=0, y=3), Print(screen, SelectorBox(4), x=18, y=3), Print(screen, SelectorBox(5), x=0, y=11), Print(screen, SelectorBox(7), x=18, y=11), Print(screen, SelectorBox(6), x=0, y=14), Print(screen, SelectorBox(8), x=18, y=14), Print(screen, NinjaMenu(), x=30, y=0), Print(screen, logic, 0, 0), KeyboardLogic(screen) ] scenes = [Scene(effects, -1)] # # if time.time()-timer > 1: # if selection+1 < 5: # selection+=1 # timer = time.time() screen.play(scenes)
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))
def test_jump_and_wait(self): """ Check basic movement of cursor works. """ path = Path() path.jump_to(10, 10) path.wait(3) self.assert_path_equals(path, [(10, 10), (10, 10), (10, 10), (10, 10)])
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))
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)
def test_spline(self): """ Check a path works with a spline curve. """ path = Path() path.jump_to(0, 10) path.move_round_to([(0, 10), (20, 0), (40, 10), (20, 20), (0, 10)], 20) self.assert_path_equals( path, [(0, 10), (0, 10), (0, 10), (0, 10), (0, 10), (5, 7), (10, 4), (15, 1), (20, 0), (25, 1), (30, 3), (35, 7), (40, 10), (35, 12), (30, 16), (25, 18), (20, 20), (15, 18), (10, 15), (5, 12), (0, 10)])
def jeer_demo(screen, narration0, narration1): scenes = [] centre = (screen.width // 2, screen.height // 2) podium0 = (16, 4) podium1 = (63, 7) # add some to be lower # Scene 1. path0 = Path() path1 = Path() path0.jump_to(podium0[0] - 8, podium0[1]) path1.jump_to(podium1[0] + 8, podium1[1] - 3) effects = [ Sam(screen, path0), Sam(screen, path1), # Print(screen, StaticRenderer(["X"]), podium0[1], podium0[0], speed=0), # Print(screen, StaticRenderer(["Y"]), podium1[1], podium1[0], speed=0), _speak(screen, narration0[1], podium0, 0), _speak(screen, narration1[1], podium1, 50, tail='R'), Print(screen, FigletText("Jeer!", "banner3"), (screen.height - 4) // 2, colour=Screen.COLOUR_RED, speed=1, stop_frame=100), ] scenes.append(Scene(effects, -1)) screen.play(scenes, stop_on_resize=True, repeat=False)
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))
def demo(screen): scenes = [] centre = (screen.width // 2, screen.height // 2) # Title effects = [ BannerText(screen, ColourImageFile(screen, "pacman.png", 16), (screen.height - 16) // 2, Screen.COLOUR_WHITE), Print(screen, StaticRenderer(images=["A tribute to the classic 80's " "video game by Namco."]), screen.height - 1) ] scenes.append(Scene(effects, 0)) # Scene 1 - run away, eating dots path = Path() path.jump_to(screen.width + 16, centre[1]) path.move_straight_to(-16, centre[1], (screen.width + 16) // 3) path.wait(100) if screen.colours <= 16: inky = 6 pinky = 5 blinky = 1 clyde = 2 else: inky = 14 pinky = 201 blinky = 9 clyde = 208 effects = [ PacMan(screen, path), Ghost(screen, deepcopy(path), inky, start_frame=40), Ghost(screen, deepcopy(path), pinky, start_frame=60), Ghost(screen, deepcopy(path), blinky, start_frame=80), Ghost(screen, deepcopy(path), clyde, start_frame=100), ] for x in range(5, screen.width, 16): effects.insert(0, Print(screen, StaticRenderer(images=[dot]), screen.height // 2, x=x, speed=1, stop_frame=4)) scenes.append(Scene(effects, 100 + screen.width)) # Scene 2 - Chase ghosts after a power pill scenes.append(EatingScene(screen)) screen.play(scenes, stop_on_resize=True)
def start(screen): centre = (screen.width // 2, screen.height // 2) fish = Fish() effects = [] colors = [ Screen.COLOUR_RED, Screen.COLOUR_CYAN, Screen.COLOUR_MAGENTA, Screen.COLOUR_GREEN, Screen.COLOUR_WHITE, Screen.COLOUR_YELLOW ] for _ in range(0, 50): path = Path() # Spawn object on scene. Or teleport it to that cords. path.jump_to(0, random.randint(5, screen.height)) # Move object to that cords in stright line. 3rd argument is how many steps it takes to complete this path. path.move_straight_to(screen.width, random.randint(5, screen.height), random.randint(100, 200)) # Create sprite. Sprite is an effect, which can follow path. sprite = Sprite( screen, renderer_dict={ "default": StaticRenderer(images=[fish.small_fish]) }, path=path, #) colour=random.choice(colors)) # Add effect to effect list. Effect is basically anything that will be displayed on scene. effects.append(sprite) # Add all effects yo this scene scene = [Scene(effects, -1)] screen.set_title('ASCIIQuarium') # Play scene, auto reprat, stop when window is resized. screen.play(scene, repeat=False)
def eaten(self): # Already eaten - just ignore if self._eaten: return # Allow one more iteration for this Sprite to clear itself up. self._eaten = True self._delete_count = 2 # Spawn the eyes to run away path = Path() path.jump_to(self._old_x + 12, self._old_y + 4) path.move_straight_to(self._old_x + 12, -8, (self._old_y + 12) // 2) path.wait(10000) self._scene.add_effect(Eyes(self._screen, path))
def test_jump_and_wait(self): """ Check basic movement of cursor works. """ path = Path() path.jump_to(10, 10) path.wait(3) self.assertPathEquals(path, [(10, 10), (10, 10), (10, 10), (10, 10)])
def eaten(self): # Already eaten - just ignore if self._eaten: return # Allow one more iteration for this Sprite to clear itself up. self._eaten = True self._delete_count = 2 # Spawn the eyes to run away path = Path() path.jump_to(self._old_x + 12, self._old_y + 4) path.move_straight_to( self._old_x + 12, -8, (self._old_y + 12) // 2) path.wait(100) self._scene.add_effect(Eyes(self._screen, path))
def test_spline(self): """ Check a path works with a spline curve. """ path = Path() path.jump_to(0, 10) path.move_round_to([(0, 10), (20, 0), (40, 10), (20, 20), (0, 10)], 20) self.assertPathEquals(path, [(0, 10), (0, 10), (0, 10), (0, 10), (0, 10), (5, 7), (10, 4), (15, 1), (20, 0), (25, 1), (30, 3), (35, 7), (40, 10), (35, 12), (30, 16), (25, 18), (20, 20), (15, 18), (10, 15), (5, 12), (0, 10)])
def move_animation(screen, ascii_obj): centre = (screen.width // 2, screen.height // 2) path = Path() # path.jump_to(screen.width + 16, centre[1]) obj_length = 64 path.jump_to(-obj_length, centre[1]) path.move_straight_to(screen.width + obj_length, centre[1], (screen.width + obj_length) // 5) sprite = Sprite( screen, renderer_dict={"default": StaticRenderer(images=[ascii_obj])}, path=path) effects = [sprite] return effects
def demo(screen): centre = (screen.width // 2, screen.height // 2) 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)))) path = Path() path.jump_to(centre[0], centre[1] - screen.height // 4) path.move_round_to(curve_path, 60) sprite = Sprite(screen, renderer_dict={"default": StaticRenderer(images=["X"])}, path=path, colour=Screen.COLOUR_RED, clear=False)
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)
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, "Secure TLS Deployment with LURK \n" +\ "-- Example: RSA Authentication --", centre, 30), ] scenes.append(Scene(effects)) # Scene 2 T = 0 path = Path() path.jump_to(podium[0], podium[1]) effects = [Arrow(screen, path, colour=Screen.COLOUR_GREEN)] Y = 8 speak = "In practice the line between Untrusted and " +\ "Trusted Domain does not exist..." labels = ["Untrusted Domain", "Trusted Domain"] colors = [Screen.COLOUR_RED, Screen.COLOUR_GREEN] effects += [_speak(screen, speak, podium, T)] effects += _background_display( screen, start=T, stop=T + TIC_SPEAK, labels=labels,\ colors=colors, y=Y, mode="header_plain") T += TIC_SPEAK speak = "Instead there is a continuum with Untrusted, \n" +\ "Exposed and Trusted Domain... " labels = ["Untrusted Domain", "Exposed Domain", "Trusted Domain"] colors = [ Screen.COLOUR_RED, Screen.COLOUR_YELLOW, \ Screen.COLOUR_GREEN ] effects += [_speak(screen, speak, podium, T)] effects += _background_display( screen, start=T, stop=T + 3 * TIC_SPEAK, labels=labels,\ colors=colors, y=Y, mode="header_plain") T += TIC_SPEAK speak = "For CDN: \n"+\ " * Untrusted Domain == Internet, \n" + \ " * Exposed Domain == delegated CDN, \n" +\ " * Trusted Domain == Your CDN... " effects += [_speak(screen, speak, podium, T)] T += TIC_SPEAK speak = "For vRAN: \n" +\ " * Untrusted Domain == Data Center, \n" +\ " * Exposed Domain == vRAN Software, \n" +\ " * Trusted Domain == Trusted Execution Environment..." effects += [_speak(screen, speak, podium, T)] T += TIC_SPEAK speak = "This can be extended to any case where TLS is used..." labels = ["TLS Client", "TLS Server", "Key Server"] effects += [_speak(screen, speak, podium, T)] effects += _background_display( screen, start=T, stop=END_OF_DEMO, labels=labels,\ colors=colors, y=Y, mode="header_plain") T += TIC_SPEAK Y += 2 speak = "A TLS Client terminates the session to the Exposed Environment" msg = "ClientHello \n" +\ " server_version \n" +\ " client_random \n" +\ " cipher_suite \n" +\ " TLS_RSA_*, ...\n" +\ "-------->" effects += move_h(screen, msg, Y, 'tls_clt', T) effects += [_speak(screen, speak, podium, T)] speak = "The TLS Server chose RSA authentication proposed by the \n" +\ "TLS Client " effects.append(_speak(screen, speak, podium, T + TIC_SPEAK)) T += max(TIC_MESSAGE, 2 * TIC_SPEAK) Y += msg.count('\n') + 1 speak = "The TLS Server knows RSA Authentication involves \n" +\ "interactions with the Key Server and obfuscates the \n" +\ "server_random to provide perfect forward secrecy. " effects.append(_speak(screen, speak, podium, T)) T += TIC_SPEAK speak = "The TLS Server: \n" +\ " - 1) Generates a server_random \n" +\ " - 2) Obfuscates the server_random \n" +\ " - 3) Sends the obfuscated value to the TLS Client \n" +\ " - 4) Sends the non obfuscated value to the Key Server" effects.append(_speak(screen, speak, podium, T)) txt = "LURK server_random: " txt_value = " gmt_unix_time \n" +\ " random " kwargs = { "colour" : Screen.COLOUR_YELLOW, "attr" : Screen.A_BOLD, \ "bg" : Screen.COLOUR_BLACK, "clear" : True, 'transparent' : True,\ 'x' : int( 1.1 * int(screen.width / 3 ) ), 'start_frame' : T, \ 'stop_frame' : END_OF_DEMO} y = Y - 2 # moving up to two lines the text args = [screen, s2r(txt), y] effects += [Print(*args, **kwargs)] kwargs['colour'] = Screen.COLOUR_RED args = [screen, s2r(txt_value), y + 1] effects += [Print(*args, **kwargs)] y += txt.count('\n') + 1 + txt_value.count('\n') txt = " Obfuscated TLS server_random: " txt_value= " gmt_unix_time \n" +\ " random " kwargs = { "colour" : Screen.COLOUR_YELLOW, "attr" : Screen.A_BOLD, \ "bg" : Screen.COLOUR_BLACK, "clear" : True, 'transparent' : True,\ 'x' : int( 1.1 * int(screen.width / 3 ) ), 'start_frame' : T, \ 'stop_frame' : END_OF_DEMO} args = [screen, s2r(txt), y] effects += [Print(*args, **kwargs)] kwargs['colour'] = Screen.COLOUR_WHITE args = [screen, s2r(txt_value), y + 1] effects += [Print(*args, **kwargs)] T += TIC_SPEAK speak = "The TLS Server responds with a ServerHello \n" +\ "That includes the obfuscated server_random " msg = "ServerHello \n" +\ " tls_version \n" +\ " server_random (TLS) \n" +\ " Cipher_suite=TLS_RSA \n" +\ "Certificate \n" +\ " RSA Public Key \n" +\ "ServerHelloDone \n" +\ "<-------- " effects += move_h(screen, msg, Y, 'tls_srv', T) effects += [_speak(screen, speak, podium, T)] T += max(TIC_MESSAGE, TIC_SPEAK) Y += msg.count('\n') + 1 speak = "The TLS Client sends a ClientKeyExchange \n" +\ "with the encrypted premaster " msg = "ClientKeyExchange \n" +\ " encrypted_premaster \n" +\ "-------->" effects += move_h(screen, msg, Y, 'tls_clt', T) effects += [_speak(screen, speak, podium, T)] T += max(TIC_MESSAGE, TIC_SPEAK) Y += msg.count('\n') + 1 speak = "Upon receiving the ClientKeyExchange, the \n" +\ "TLS Server initiates a LURK exchange with \n" +\ "the Key Server to: \n" +\ " - 1) Decyrpte the encrypted_premaster \n" +\ " - 2) Generate the master_secret " msg = "RSAMasterRequest \n" +\ " key_id \n" +\ " key_id_type \n" +\ " key_id \n" +\ " freshness_funct \n" +\ " client_random \n" +\ " gmt_unix_time \n" +\ " random = \n" +\ " server_random \n" +\ " gmt_unix_time \n" +\ " random = \n" +\ " encrypted_premaster\n" +\ "--------> " effects.append(_speak(screen, speak, podium, T)) effects += move_h(screen, msg, Y, 'lurk_clt', T) T += max(TIC_MESSAGE, TIC_SPEAK) Y += msg.count('\n') + 1 speak = "The Key Server : \n" +\ " - 1) Decrypts the encrypted_premaster \n" +\ " - 2) Generates the master secret " msg = "RSAMasterResponse\n" +\ " master \n" +\ "<-------- " effects.append(_speak(screen, speak, podium, T)) effects += move_h(screen, msg, Y, 'lurk_srv', T) T += max(TIC_MESSAGE, TIC_SPEAK) Y += msg.count('\n') + 1 speak = "With the master_secret, the TLS Server finalizes \n" +\ "the authenticated TLS Key Exchange. \n" +\ " \n" +\ "The TLS Server has not accessed the private key !" msg = "[ChangeCipherSpec] \n" +\ "Finishedit \n" +\ "--------> " effects += [_speak(screen, speak, podium, T)] effects += move_h(screen, msg, Y, 'tls_clt', T) T += max(TIC_MESSAGE, TIC_SPEAK) Y += msg.count('\n') + 1 msg = "[ChangeCipherSpec] \n" +\ " Finished \n" +\ "<-------- " effects += move_h(screen, msg, Y, 'tls_srv', T) T += max(TIC_SPEAK, TIC_SPEAK) Y += msg.count('\n') + 1 txt = "Application Data <-------> Application Data" kwargs = { "colour" : Screen.COLOUR_WHITE, "attr" : Screen.A_BOLD, \ "bg" : Screen.COLOUR_BLACK, "clear" : True, 'transparent' : True, \ 'x' : int( screen.width / 3 * ( 0.1 + 1 / 2) - len( txt ) / 2 ), \ 'start_frame' : T, 'stop_frame' : END_OF_DEMO } args = [screen, s2r(txt), Y] effects.append(Print(*args, **kwargs)) T += TIC_SPEAK Y += txt.count('\n') + 1 scenes.append(Scene(effects, duration=20000, clear=True)) #scenes.append(Scene(effects, -1)) screen.play(scenes, stop_on_resize=True)
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)
def demo(screen): scenes = [] centre = (screen.width // 2, screen.height // 2) podium = (38, 20, 30, 20) podium2 = (30, 20) # 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, "BIENVENIDO A ~~THE MINERS~~~ !!!", centre, 30), _speak(screen, "Tercera parte de Postdigital (Enrique Tomás).", podium, 110), _speak(screen, "Quiero explicarte algo sobre la obra.", podium, 180), ] scenes.append(Scene(effects)) # Scene 2. path = Path() path.jump_to(podium[0], podium[1]) path.wait(1000) effects = [ Arrow(screen, path, colour=Screen.COLOUR_GREEN), _speak(screen, "The Miners? ... ¿Los mineros?", podium, 10), _speak(screen, "Va sobre las criptomonedas y sus efectos...", podium, 80), #Print(screen, # Box(screen.width, screen.height, uni=screen.unicode_aware), # 0, 0, start_frame=90), _speak(screen, "Las criptomonedas son dinero electrónico.", podium, 150), _speak( screen, "Sirven para transferir dinero sin intermediarios (como los bancos).", podium, 220), _speak2( screen, "Las transacciones necesitan ser verificadas por otros ordenadores de la red", podium, 300), _speak(screen, "que resuelven un complejo problema matemático.", podium, 400), _speak(screen, "...consumiendo mucha electricidad.", podium, 480), _speak2(screen, "Al año, tanta como un paÃs como Irlanda o Suiza.", podium, 580), _speak(screen, "Por este motivo se recompensa económicamente a los nodos.", podium, 700), _speak2( screen, "El primero en resolverlo gana 12.5 bitcoins (1 bitcoin =~ 4200 euro) ", podium, 780), Stars(screen, (screen.width + screen.height) // 2, start_frame=360) ] scenes.append(Scene(effects, -1)) # Scene 3. path = Path() path.move_straight_to(podium[2], podium[3], 10) path.wait(800) effects = [ Arrow(screen, path, colour=Screen.COLOUR_GREEN), _speak(screen, "Durante esta obra, vamos a minar bitcoins...", podium2, 10), _speak2(screen, "Cada nota que tocará el Emsemble Container...", podium2, 70), _speak2( screen, "verificará (minará) una transaccion de bitcoins en tiempo real", podium2, 160), _speak(screen, " y si tenemos suerte (1 elevado a menos 36)...", podium2, 260), _speak(screen, "¡¡¡ganaremos 12.5 bitcoins en este concierto!!!", podium2, 340), _speak(screen, "El minado (ejem... el concierto) va a empezar...", podium2, 420), RandomNoise(screen, signal=Rainbow( screen, FigletText("El concierto... va a empezar...", font="term")), start_frame=490) ] scenes.append(Scene(effects, -1)) screen.play(scenes, stop_on_resize=True)
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), 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)
def kitty(screen, scene): scenes = [] effects = [ ProfileFrame(screen), ] scenes.append(Scene(effects, -1, name='Main')) # scene cell = ColourImageFile(screen, 'img/4.jpg', screen.height) effects = [ RandomNoise(screen, signal=cell), Print(screen, Rainbow(screen, FigletText('Kitty', font='banner')), screen.height - 6, start_frame=200, bg=0), Print(screen, Rainbow(screen, FigletText('Kitty', font='banner')), screen.height - 6, start_frame=200, bg=0) ] scenes.append(Scene(effects, 380, name='Begin')) # scene effects = [ShootScreen(screen, screen.width // 2, screen.height // 2, 100)] scenes.append(Scene(effects, 60, clear=False)) #scene centre = ((screen.width // 2) - 20, (screen.height // 2) - 3) podium = (8, 5) 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(180) effects = [ Arrow(screen, path, colour=Screen.COLOUR_GREEN), Snow(screen), Rain(screen, 340), Print(screen, StaticRenderer(images=tree), screen.height - 15, screen.width - 15, colour=Screen.COLOUR_GREEN), _speak( screen, u'This program write for the girl that i like, hope she will be happy!', centre, 30), _speak(screen, u'I like her at the first sight when i met her last year.', podium, 110), _speak( screen, u'I really like to chat with her, but afraid that she will be boring. ', podium, 180), Cycle(screen, Rainbow(screen, FigletText('Lovely', 'banner')), screen.height // 2 - 6, start_frame=220), Cycle(screen, Rainbow(screen, FigletText('Kitty', 'banner')), screen.height // 2 + 1, start_frame=220) ] scenes.append(Scene(effects, duration=340)) #scene cell = ColourImageFile(screen, 'img/10.jpg', screen.height, uni=screen.unicode_aware, dither=screen.unicode_aware) effects = [ Wipe(screen), Print(screen, cell, 0), Stars(screen, screen.height + screen.width) ] # for _ in range(20): # effects.append( # Explosion(screen, randint(0, screen.width), randint(screen.height//8, screen.height*3//4), randint(20, 150) ) # ) scenes.append(Scene(effects, 150, clear=False)) #scene cell = ColourImageFile(screen, 'img/3.jpg', screen.height, uni=screen.unicode_aware, dither=screen.unicode_aware) effects = [ DropScreen(screen, 100), BannerText(screen, cell, 0, Screen.COLOUR_YELLOW), Snow(screen) ] for _ in range(120): fireworks = [(PalmFirework, randint(25, 35)), (RingFirework, randint(25, 30)), (StarFirework, randint(30, 35)), (SerpentFirework, randint(28, 35))] firework, lifetime = choice(fireworks) effects.append( firework(screen, randint(0, screen.width), randint(screen.height // 8, screen.height * 3 // 4), lifetime, start_frame=randint(20, 250))) scenes.append(Scene(effects, 280, clear=False)) #scene cell = ColourImageFile(screen, 'img/1.jpg', screen.height, uni=screen.unicode_aware, dither=screen.unicode_aware) effects = [ Print(screen, cell, 0, speed=1), Scroll(screen, rate=10), Rain(screen, 200) ] scenes.append(Scene(effects, 180)) #scene text = Figlet(font="banner", width=200).renderText("Pretty Girl") width = max([len(x) for x in text.split("\n")]) effects = [ Print(screen, Fire(screen.height, 80, text, 0.4, 40, screen.colours), 0, speed=1), Print(screen, FigletText("Pretty Girl", 'banner'), screen.height - 9, x=(screen.width - width) // 2 + 1, colour=0, bg=0, speed=1), Print(screen, FigletText("Pretty Girl", 'banner'), screen.height - 9, x=(screen.width - width) // 2 + 1, colour=7, bg=7, speed=1) ] scenes.append(Scene(effects, 80)) #scene effects = [ Print(screen, Plasma(screen.height, screen.width, screen.colours), 0, speed=1, start_frame=50), Print(screen, Rainbow(screen, FigletText('Thats All')), screen.height // 2 - 5), Print(screen, Rainbow(screen, FigletText('My Kitty!')), screen.height // 2 + 5), ] scenes.append(Scene(effects, -1)) screen.play(scenes, stop_on_resize=True, start_scene=scene)
def test_straight_lines(self): """ Check a path works in straight lines. """ # Horizontal path = Path() path.jump_to(10, 10) path.move_straight_to(15, 10, 5) self.assert_path_equals( path, [(10, 10), (11, 10), (12, 10), (13, 10), (14, 10), (15, 10)]) # Vertical path = Path() path.jump_to(5, 5) path.move_straight_to(5, 10, 5) self.assert_path_equals( path, [(5, 5), (5, 6), (5, 7), (5, 8), (5, 9), (5, 10)]) # Diagonal spaced path = Path() path.jump_to(5, 5) path.move_straight_to(15, 15, 5) self.assert_path_equals( path, [(5, 5), (7, 7), (9, 9), (11, 11), (13, 13), (15, 15)])
def play_game(screen): scenes = [] centre = (screen.width // 2, screen.height // 2) title_effects = [ Cycle( screen, FigletText("SHELL"), screen.height // 2 - 6, ), Cycle( screen, FigletText("GAME!"), screen.height // 2 + 1, ), ] scenes.append(Scene(title_effects, -1)) middle_path = Path() middle_path.jump_to(centre[0], 0) middle_path.move_straight_to(centre[0], centre[1] + 2, 15), left_path = Path() left_path.jump_to(centre[0] - 9, y=centre[1] + 2) intro_effects = [ Print(screen, StaticRenderer(images=[ball]), x=centre[0], y=centre[1]), Shell(screen, left_path), Print(screen, StaticRenderer(images=[shell]), x=centre[0] + 7, y=centre[1]), Shell(screen, middle_path) ] scenes.append(Scene(intro_effects, 30)) # game scene game = get_game(random.randint(1, 4), centre, screen) global ball_location ball_location = game[1] scenes.append(game[0]) intro_effects = [ Print(screen, StaticRenderer(images=["1"]), x=centre[0] - 7, y=centre[1] - 1), Print(screen, StaticRenderer(images=[shell]), x=centre[0] + 9, y=centre[1]), Print(screen, StaticRenderer(images=["2"]), x=centre[0] + 2, y=centre[1] - 1), Print(screen, StaticRenderer(images=[shell]), x=centre[0], y=centre[1]), Print(screen, StaticRenderer(images=["3"]), x=centre[0] + 11, y=centre[1] - 1), Print(screen, StaticRenderer(images=[shell]), x=centre[0] - 9, y=centre[1]), X(screen) ] scenes.append(Scene(intro_effects, -1)) screen.play(scenes)
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()))
def test_straight_lines(self): """ Check a path works in straight lines. """ # Horizontal path = Path() path.jump_to(10, 10) path.move_straight_to(15, 10, 5) self.assertPathEquals(path, [(10, 10), (11, 10), (12, 10), (13, 10), (14, 10), (15, 10)]) # Vertical path = Path() path.jump_to(5, 5) path.move_straight_to(5, 10, 5) self.assertPathEquals(path, [(5, 5), (5, 6), (5, 7), (5, 8), (5, 9), (5, 10)]) # Diagonal spaced path = Path() path.jump_to(5, 5) path.move_straight_to(15, 15, 5) self.assertPathEquals(path, [(5, 5), (7, 7), (9, 9), (11, 11), (13, 13), (15, 15)])
def move_animation(screen, ascii_obj): centre = (screen.width // 2, screen.height // 2) path = Path() # path.jump_to(screen.width + 16, centre[1]) obj_len = 2 half_length = 8 for i in range(half_length): path.jump_to(centre[0] - i * 2, centre[1] - i) path.jump_to(centre[0] + i * 2, centre[1] - i) for i in range(half_length): path.jump_to(centre[0] - (half_length - 1) * 2 - 1 - i * 2, centre[1] - (half_length - 1) + i) path.jump_to(centre[0] + (half_length - 1) * 2 + 1 + i * 2, centre[1] - (half_length - 1) + i) for i in range(1, 2 * half_length - 1): path.jump_to(centre[0] - (half_length - 1) * 2 * 2 + i * 2, centre[1] + i) path.jump_to(centre[0] + (half_length - 1) * 2 * 2 - i * 2, centre[1] + i) # path.move_straight_to(screen.width+obj_length, centre[1], (screen.width + obj_length) // 2) """effects = [ Print(screen, # FigletText("ASCIIMATICS", font='big'), StaticRenderer(images=[bike_ascii]), int(screen.height / 2 - 8)) # Stars(screen, 200) ]""" sprite = Sprite( screen, renderer_dict={"default": StaticRenderer(images=[ascii_obj])}, path=path, colour=255, clear=False) effects = [sprite] return effects
def demo(screen): scenes = [] centre = (screen.width // 2, screen.height // 2) # Title effects = [ BannerText(screen, ColourImageFile(screen, "pacman.png", 16, 0, True), (screen.height - 16) // 2, Screen.COLOUR_WHITE), Print( screen, StaticRenderer(images=[ "A tribute to the classic 80's " "video game by Namco." ]), screen.height - 1) ] #scenes.append(Scene(effects, 0)) # Scene 1 - run away, eating dots path = Path() path.jump_to(screen.width + 16, centre[1]) path.move_straight_to(-16, centre[1], (screen.width + 16) // 3) path.wait(100) if screen.colours <= 16: inky = 6 pinky = 5 blinky = 1 clyde = 2 else: inky = 14 pinky = 201 blinky = 9 clyde = 208 effects = [ PacMan(screen, path), Ghost(screen, deepcopy(path), inky, start_frame=40), Ghost(screen, deepcopy(path), pinky, start_frame=60), Ghost(screen, deepcopy(path), blinky, start_frame=80), Ghost(screen, deepcopy(path), clyde, start_frame=100), ] for x in range(5, screen.width, 16): effects.insert( 0, Print(screen, StaticRenderer(images=[dot]), screen.height // 2, x=x, speed=1, stop_frame=4)) scenes.append(Scene(effects, 100 + screen.width)) # Scene 2 - Chase ghosts after a power pill scenes.append(EatingScene(screen)) # Scene 3 - Thanks... effects = [ Print(screen, FigletText("Thank you,"), screen.height // 3 - 3, colour=Screen.COLOUR_RED), Print(screen, StaticRenderer(images=[namco]), screen.height * 2 // 3 - 2, colour=Screen.COLOUR_RED), Print(screen, StaticRenderer(images=["< Press X to exit. >"]), screen.height - 1) ] scenes.append(Scene(effects, 0)) screen.play(scenes, stop_on_resize=True, repeat=False)
def reset(self, old_scene=None, screen=None): super(EatingScene, self).reset(old_scene, screen) # Recreate all the elements. centre = (self._screen.width // 2, self._screen.height // 2) path = Path() path.jump_to(-16, centre[1]) path.move_straight_to(self._screen.width + 16, centre[1], (self._screen.width + 16) // 3) path.wait(100) path2 = Path() path2.jump_to(-16, centre[1]) path2.move_straight_to(self._screen.width + 16, centre[1], self._screen.width + 16) path2.wait(100) # Take a copy of the list before using it to remove all effects. for effect in self.effects[:]: self.remove_effect(effect) self.add_effect(ScaredGhost(self._screen, deepcopy(path2))) self.add_effect( ScaredGhost(self._screen, deepcopy(path2), start_frame=60)) self.add_effect( ScaredGhost(self._screen, deepcopy(path2), start_frame=120)) self.add_effect( ScaredGhost(self._screen, deepcopy(path2), start_frame=180)) self.add_effect(PacMan(self._screen, path, start_frame=240))
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)
def reset(self, old_scene=None, screen=None): super(EatingScene, self).reset(old_scene, screen) # Recreate all the elements. centre = (self._screen.width // 2, self._screen.height // 2) path = Path() path.jump_to(-16, centre[1]) path.move_straight_to( self._screen.width + 16, centre[1], (self._screen.width + 16) // 3) path.wait(100) path2 = Path() path2.jump_to(-16, centre[1]) path2.move_straight_to( self._screen.width + 16, centre[1], self._screen.width + 16) path2.wait(100) for effect in self.effects: self.remove_effect(effect) self.add_effect( ScaredGhost(self._screen, deepcopy(path2))) self.add_effect( ScaredGhost(self._screen, deepcopy(path2), start_frame=60)) self.add_effect( ScaredGhost(self._screen, deepcopy(path2), start_frame=120)) self.add_effect( ScaredGhost(self._screen, deepcopy(path2), start_frame=180)) self.add_effect(PacMan(self._screen, path, start_frame=240))
def get_game(game_index, centre, screen): if game_index == 1: left_path = Path() left_path.jump_to(centre[0] - 9, centre[1] + 2) left_path.move_straight_to(centre[0] - 9, centre[1] - 1, 10), left_path.move_straight_to(centre[0], centre[1] - 1, 10), left_path.move_straight_to(centre[0], centre[1] + 2, 10), left_path.is_finished middle_path = Path() middle_path.jump_to(centre[0], centre[1] + 2) middle_path.wait(15) middle_path.move_straight_to(centre[0] - 9, centre[1] + 2, 10) middle_path.wait(50) middle_path.is_finished effects = [ Shell(screen, left_path), Shell(screen, middle_path), Print(screen, StaticRenderer(images=[shell]), x=centre[0] + 7, y=centre[1]) ] return (Scene(effects, 66), 1) elif game_index == 2: right_path = Path() right_path.jump_to(centre[0] + 7, centre[1] + 2) right_path.move_straight_to(centre[0] + 7, centre[1] - 1, 10), right_path.move_straight_to(centre[0], centre[1] - 1, 10), right_path.move_straight_to(centre[0], centre[1] + 2, 10), right_path.is_finished middle_path = Path() middle_path.jump_to(centre[0], centre[1] + 2) middle_path.wait(15) middle_path.move_straight_to(centre[0] + 7, centre[1] + 2, 10) middle_path.wait(50) middle_path.is_finished effects = [ Shell(screen, right_path), Shell(screen, middle_path), Print(screen, StaticRenderer(images=[shell]), x=centre[0] - 9, y=centre[1]) ] return (Scene(effects, 66), 3) elif game_index == 3: right_path = Path() right_path.jump_to(centre[0] + 7, centre[1] + 2) right_path.move_straight_to(centre[0] + 7, centre[1] - 1, 10), right_path.move_straight_to(centre[0] - 9, centre[1] - 1, 20), right_path.move_straight_to(centre[0] - 9, centre[1] + 2, 10), right_path.is_finished middle_path = Path() middle_path.jump_to(centre[0], centre[1] + 2) middle_path.wait(15) middle_path.move_straight_to(centre[0] + 7, centre[1] + 2, 10) middle_path.wait(50) middle_path.is_finished left_path = Path() left_path.jump_to(centre[0] - 9, centre[1] + 2) left_path.wait(15) left_path.move_straight_to(centre[0], centre[1] + 2, 10) left_path.wait(50) left_path.is_finished effects = [ Shell(screen, right_path), Shell(screen, middle_path), Shell(screen, left_path) ] return (Scene(effects, 85), 3) elif game_index == 4: right_path = Path() right_path.jump_to(centre[0] + 7, centre[1] + 2) right_path.wait(15) right_path.move_straight_to(centre[0], centre[1] + 2, 10), right_path.wait(50) right_path.is_finished middle_path = Path() middle_path.jump_to(centre[0], centre[1] + 2) middle_path.wait(15) middle_path.move_straight_to(centre[0] - 9, centre[1] + 2, 10) middle_path.wait(50) middle_path.is_finished left_path = Path() left_path.jump_to(centre[0] - 9, centre[1] + 2) left_path.move_straight_to(centre[0] - 9, centre[1] - 1, 10) left_path.move_straight_to(centre[0] + 7, centre[1] - 1, 20) left_path.move_straight_to(centre[0] + 7, centre[1] + 2, 10) left_path.wait(50) left_path.is_finished effects = [ Shell(screen, right_path), Shell(screen, middle_path), Shell(screen, left_path) ] return (Scene(effects, 85), 1)