def test_print(self): """ Check that the Print Effect works. """ # Check that print only redraws on specified rate. screen = MagicMock(spec=Screen, colours=8, unicode_aware=False) effect = Print(screen, StaticRenderer(images=["hello"]), 2, 1) effect.reset() effect.update(0) screen.paint.assert_called_with( "hello", 1, 2, 7, attr=0, bg=0, colour_map=[(None, None, None) for _ in range(5)], transparent=True) screen.paint.reset_mock() effect.update(1) effect.update(2) effect.update(3) screen.paint.assert_not_called() # Check there is no stop frame by default. self.assertEqual(effect.stop_frame, 0) # This effect should ignore events. event = object() self.assertEqual(event, effect.process_event(event))
def _add_cheesy_comment(self): msg = FigletText(choice(self._comments), "banner3") self._effects.append( Print(self._screen, msg, (self._screen.height // 2) - 4, x=(self._screen.width - msg.max_width) // 2 + 1, colour=Screen.COLOUR_BLACK, stop_frame=80, speed=1)) self._effects.append( Print(self._screen, Rainbow(self._screen, msg), (self._screen.height // 2) - 4, x=(self._screen.width - msg.max_width) // 2, colour=Screen.COLOUR_BLACK, stop_frame=80, speed=1))
def _figlet(self, screen, text, pos, offset): return Print( screen, FigletText(text["text"], text["font"]), x=pos[0] - offset, y=pos[1], colour=Screen.COLOUR_WHITE, clear=False, bg=Screen.COLOUR_BLUE )
def _speak(screen, text, pos, start): return Print(screen, SpeechBubble(text, "L"), x=pos[0] + 4, y=pos[1] - 4, colour=Screen.COLOUR_CYAN, clear=True, start_frame=start, stop_frame=start + 50)
def fireworks(screen): scenes = [] # Leer xlsx y seleccionar un estudiante student = get_student_from_xlsx(generation) student_split = student.split() effects = [ Stars(screen, screen.width), Print(screen, SpeechBubble("Pulsa espacio para volver a ver"), y=screen.height - 3, start_frame=300) ] for _ in range(20): fireworks = [ (PalmFirework, 25, 30), (PalmFirework, 25, 30), (StarFirework, 25, 35), (StarFirework, 25, 35), (StarFirework, 25, 35), (RingFirework, 20, 30), (SerpentFirework, 30, 35), ] firework, start, stop = choice(fireworks) effects.insert( 1, firework(screen, randint(0, screen.width), randint(screen.height // 8, screen.height * 3 // 4), randint(start, stop), start_frame=randint(0, 250))) effects.append(Print(screen, Rainbow(screen, FigletText("{} {}".format(student_split[0], student_split[1]), font='big')), screen.height // 2 - 6, speed=1, start_frame=100)) effects.append(Print(screen, Rainbow(screen, FigletText("{} {}".format(student_split[2], student_split[3]), font='big')), screen.height // 2 + 1, speed=1, start_frame=100)) scenes.append(Scene(effects, -1)) screen.play(scenes, stop_on_resize=True)
def ui(screen): scenes = [] if screen.width != 70 or screen.height != 53: effects = [ Print(screen, FigletText("Resize to 70x53"), y=screen.height // 2 - 3) ] else: effects = [ Print(screen, FigletText("OptionsGAME"), y=0), Print(screen, BarChart(8, 68, [wvc(9, 8), wv(9, 8)], scale=100.0, labels=True, intervals=25.0, border=False, bg=[1, 2], colour=[1, 2], axes=BarChart.X_AXIS), x=1, y=7, transparent=False, speed=1), Print(screen, BarChart(20, 68, [wv(7), wv(8), wv(9)], char="x", scale=100.0, labels=True, intervals=25.0, axes=BarChart.X_AXIS, gradient=[(50, Screen.COLOUR_GREEN), (75, Screen.COLOUR_YELLOW), (100, Screen.COLOUR_RED)]), x=1, y=15, transparent=False, speed=1) ] scenes.append(Scene(effects, -1)) screen.play(scenes, stop_on_resize=True)
def demo(screen): scenes = [] effects = [ Stars(screen, screen.width), Print(screen, SpeechBubble("Press space to see it again"), y=screen.height - 3, start_frame=300) ] for _ in range(20): fireworks = [ (PalmFirework, 25, 30), (PalmFirework, 25, 30), (StarFirework, 25, 35), (StarFirework, 25, 35), (StarFirework, 25, 35), (RingFirework, 20, 30), (SerpentFirework, 30, 35), ] firework, start, stop = choice(fireworks) effects.insert( 1, firework(screen, randint(0, screen.width), randint(screen.height // 8, screen.height * 3 // 4), randint(start, stop), start_frame=randint(0, 250))) effects.append( Print(screen, Rainbow(screen, FigletText("HAPPY")), screen.height // 2 - 6, speed=1, start_frame=100)) effects.append( Print(screen, Rainbow(screen, FigletText("NEW YEAR!")), screen.height // 2 + 1, speed=1, start_frame=100)) scenes.append(Scene(effects, -1)) screen.play(scenes, stop_on_resize=True)
def internal_checks(screen): screen.play([ Scene([ MockEffect(count=5), Print(screen, FigletText("hello"), 2), Cycle(screen, FigletText("world"), 6), BannerText(screen, FigletText("world"), 10, 3), Mirage(screen, FigletText("huh?"), 14, 2) ], 0) ])
def flames(screen): scenes = [] effects = [ Print(screen, Fire(screen.height, 80, "*" * 70, 0.8, 60, screen.colours, bg=screen.colours >= 256), 0, speed=1, transparent=False), Print(screen, FigletText("JPM", "banner3"), (screen.height - 4) // 2, colour=Screen.COLOUR_BLACK, speed=1) ] scenes.append(Scene(effects)) screen.play(scenes, stop_on_resize=True, repeat=False)
def __init__(self, screen): self._screen = screen effects = [ Print(screen, Plasma(screen.height, screen.width, screen.colours), 0, speed=1, transparent=False), ] super(PlasmaScene, self).__init__(effects, 200, clear=False)
def whack(self, sound): global arrow x, y = self._path.next_pos() if self.overlaps(arrow, use_new_pos=True): arrow.say("OUCH!") else: self._scene.add_effect(Print( self._screen, SpeechBubble(sound), y, x, clear=True, delete_count=50))
def demo(screen): # Typical terminals are 80x24 on UNIX and 80x25 on Windows if screen.width != 80 or screen.height not in (24, 25): effects = [ Print(screen, FigletText("Resize to 80x24"), y=screen.height//2-3), ] else: effects = [ Cog(screen, 20, 10, 10), Cog(screen, 60, 30, 15, direction=-1), Print(screen, FigletText("ascii", font="smkeyboard"), attr=Screen.A_BOLD, x=47, y=3, start_frame=50), Print(screen, FigletText("matics", font="smkeyboard"), attr=Screen.A_BOLD, x=45, y=7, start_frame=100), Print(screen, FigletText("by Peter Brittain", font="term"), x=8, y=22, start_frame=150) ] screen.play([Scene(effects, -1)], stop_on_resize=True)
def _base(screen, element, row, fg_color, bg_color): base = Print( screen, Text(element.render()), row, colour=fg_color, bg=bg_color, ) return [base]
def plasma(screen: Screen) -> List[Print]: return [ Print( screen, Plasma(screen.height, screen.width, screen.colours), 0, speed=1, transparent=False, ) ]
def _plasma(screen): return [ Print( screen, Plasma(screen.height, screen.width, screen.colours), 0, speed=1, transparent=False, ) ]
def demo(screen): scenes = [] cell1 = Rainbow( screen, RotatedDuplicate( screen.width // 2, max(screen.width // 2, screen.height), FigletText("ASCII" if screen.width < 80 else "ASCII rules", font="banner", width=screen.width // 2))) cell2 = "" size = int(sqrt(screen.height**2 + screen.width**2 // 4)) for _ in range(size): for x in range(size): c = x * screen.colours // size cell2 += "${%d,2,%d}:" % (c, c) cell2 += "\n" for i in range(8): scenes.append( Scene([ Print(screen, Kaleidoscope(screen.height, screen.width, cell1, i), 0, speed=1, transparent=False), Print(screen, FigletText(str(i)), screen.height - 6, x=screen.width - 8, speed=1) ], duration=360)) scenes.append( Scene([ Print(screen, Kaleidoscope(screen.height, screen.width, StaticRenderer([cell2]), i), 0, speed=1, transparent=False) ], duration=360)) screen.play(scenes, stop_on_resize=True)
def demo(screen): scenes = [] effects = [ Print(screen, FigletText("JOGET DAB !", font='banner3' if screen.width > 80 else 'banner'), screen.height // 2 - 3, colour=7, bg=7 if screen.unicode_aware else 0), ] scenes.append(Scene(effects)) effects = [ Print(screen, ColourImageFile(screen, "sponge.gif", screen.height, uni=screen.unicode_aware), screen.height, speed=1), Scroll(screen, 2) ] scenes.append(Scene(effects)) effects = [ BannerText( screen, ColourImageFile(screen, "sponge.gif", screen.height - 2, uni=screen.unicode_aware, dither=screen.unicode_aware), 0, 0), ] scenes.append(Scene(effects)) effects = [ Print(screen, FigletText("SUWON", font='banner3' if screen.width > 80 else 'banner'), screen.height // 2 - 3, colour=7, bg=7 if screen.unicode_aware else 0), ] scenes.append(Scene(effects)) screen.play(scenes, stop_on_resize=True)
def demo(screen): scenes = [] effects = [ Print(screen, ImageFile("/home/pi/Desktop/WASP-Emojis-master/images/smiling.jpg", screen.height - 2, colours=screen.colours), 0, stop_frame=100), ] scenes.append(Scene(effects)) screen.play(scenes, stop_on_resize=True)
def demo(screen): global arrow, cross_hairs arrow = InteractiveArrow(screen) cross_hairs = CrossHairs(screen) scenes = [] effects = [ Print(screen, FigletText("Hit the arrow with the mouse!", "digital"), y=screen.height // 3 - 3), Print(screen, FigletText("Press space when you're ready.", "digital"), y=2 * screen.height // 3 - 3), ] scenes.append(Scene(effects, -1)) effects = [arrow, cross_hairs] scenes.append(Scene(effects, -1)) screen.play(scenes, stop_on_resize=True)
def demo(screen): scenes = [] effects = [ Print(screen, ImageFile("/home/pi/Desktop/WASP-Emojis-master/images/image.jpg", screen.height - 2, colours=screen.colours), 0, stop_frame=100), Print(screen, FigletText("H E R M E S", font='epic' if screen.width > 80 else 'banner'), screen.height // 2 - 3, colour=7, bg=7 if screen.unicode_aware else 0), ] scenes.append(Scene(effects)) screen.play(scenes, stop_on_resize=True)
def _code(screen, element, row): code = Print( screen, Text(element.render()), row, colour=Screen.COLOUR_WHITE, bg=Screen.COLOUR_BLACK, transparent=False, ) return [code]
def reset(self, old_scene=None, screen=None): effects = [ Print(self._screen, BW(self._screen, FigletText(self._text, font=self._font, width=self._screen.width-14)), x=4, y=8, clear=True, start_frame=0, stop_frame=200) ] for fx in effects: self.add_effect(fx)
def demo(screen): scenes = [] effects = [ Print(screen, ColourImageFile(screen, "colour_globe.gif", screen.height - 2, uni=screen.unicode_aware, dither=screen.unicode_aware), 0, stop_frame=200), Print(screen, FigletText("ASCIIMATICS NEWS", font='banner3'), screen.height // 2 - 3, colour=7, bg=7 if screen.unicode_aware else 0), ] scenes.append(Scene(effects)) effects = [ Print(screen, ColourImageFile(screen, "grumpy_cat.jpg", screen.height, uni=screen.unicode_aware), screen.height, stop_frame=(40 + screen.height) * 3), Scroll(screen, 3) ] scenes.append(Scene(effects)) effects = [ BannerText( screen, ColourImageFile(screen, "python.png", screen.height - 2, uni=screen.unicode_aware, dither=screen.unicode_aware), 0, 0), ] scenes.append(Scene(effects)) screen.play(scenes, stop_on_resize=True)
def demo(screen): scenes = [] effects = [ Rain( screen, 99**99, ), Print(screen, FigletText("Pr()j3ct 1/\/FIn1t3", font='banner3' if screen.width > 80 else 'banner'), screen.height // 2 - 3, colour=2, bg=2), Print(screen, SpeechBubble("Pr3ss Q to St@rt"), screen.height - 5, speed=1, transparent=False) ] scenes.append(Scene(effects)) screen.play(scenes, stop_on_resize=True)
def _codio(screen, element, row): codio = Print( screen, Codio(code=element.render(), width=element.width, height=element.size), row, colour=Screen.COLOUR_WHITE, bg=Screen.COLOUR_BLACK, transparent=False, speed=element.speed, ) return [codio]
def demo(screen): scenes = [] effects = [ Print(screen, Fire(screen.height, 80, "*" * 70, 0.8, 60, screen.colours, bg=screen.colours >= 256), 0, speed=1, transparent=False), Print(screen, FigletText("Help!", "banner3"), (screen.height - 4) // 2, colour=Screen.COLOUR_BLACK, speed=1, stop_frame=30), Print(screen, FigletText("I'm", "banner3"), (screen.height - 4) // 2, colour=Screen.COLOUR_BLACK, speed=1, start_frame=30, stop_frame=50), Print(screen, FigletText("on", "banner3"), (screen.height - 4) // 2, colour=Screen.COLOUR_BLACK, speed=1, start_frame=50, stop_frame=70), Print(screen, FigletText("Fire!", "banner3"), (screen.height - 4) // 2, colour=Screen.COLOUR_BLACK, speed=1, start_frame=70), ] scenes.append(Scene(effects, 100)) screen.play(scenes, stop_on_resize=True)
def reset(self, old_scene=None, screen=None): effects = [ # Stars(screen, (screen.width + screen.height) // 2, start_frame=0), Print(self._screen, Plasma(self._screen.height, self._screen.width, self._screen.colours), x=0, y=0, speed=10, start_frame=0, stop_frame=110, transparent=False), Print( self._screen, # Rainbow(self._screen, FigletText( "You found something, the memories are coming back.", font='thin', width=self._screen.width)), # noqa: E501 FigletText( "You found something, the memories are coming back.", font='thin', width=self._screen.width), x=2, y=16, clear=False, transparent=True, start_frame=0, stop_frame=110), DropScreen(self._screen, 100, start_frame=100), Print(self._screen, Rainbow( self._screen, FigletText("Tom is alive...", font='standard', width=self._screen.width)), x=20, y=16, clear=True, start_frame=150, stop_frame=self.duration), ] for fx in effects: self.add_effect(fx)
def flames_cpu_screen(screen): scenes = [] effects = [ Print(screen, Fire(screen.height, 80, "*" * 70, 0.8, 60, screen.colours, bg=screen.colours >= 256), 0, speed=1, transparent=False), Print(screen, FigletText("OMG!", "banner3"), (screen.height - 4) // 2, colour=Screen.COLOUR_BLACK, speed=1, stop_frame=30), Print(screen, FigletText("THE CPU", "banner3"), (screen.height - 4) // 2, colour=Screen.COLOUR_BLACK, speed=1, start_frame=30, stop_frame=50), Print(screen, FigletText("IS", "banner3"), (screen.height - 4) // 2, colour=Screen.COLOUR_BLACK, speed=1, start_frame=50, stop_frame=70), Print(screen, FigletText("ON FIRE!", "banner3"), (screen.height - 4) // 2, colour=Screen.COLOUR_BLACK, speed=1, start_frame=70), ] scenes.append(Scene(effects, 100)) screen.play(scenes, stop_on_resize=True, repeat=False)
def demo(screen): context = SlideSceneContext() scenes = [ SlideScene(context, [ Print(screen, FigletText("Slide 1", font='big'), int(screen.height / 2 - 15)) ]), SlideScene(context, [ Print(screen, FigletText("Slide 2", font='big'), int(screen.height / 2 - 12)) ]), SlideScene(context, [ Print(screen, FigletText("Slide 3", font='big'), int(screen.height / 2 - 9)) ]), SlideScene(context, [ Print(screen, FigletText("Slide 4", font='big'), int(screen.height / 2 - 6)) ]), SlideScene(context, [ Print(screen, FigletText("Slide 5", font='big'), int(screen.height / 2 - 3)) ]), SlideScene(context, [ Print(screen, FigletText("Slide 6", font='big'), int(screen.height / 2 - 0)) ]), ] screen.play(scenes)
def reset(self, old_scene=None, screen=None): effects = [ self.intro_text(self.title_text1, 0), Print(self._screen, Dull(self._screen, FigletText(self.title_text2, width=self._screen.width, font='term')), x=self._screen.width // 2 - 10, y=36, clear=True, start_frame=0, stop_frame=self.duration, bg=0), ] for fx in effects: self.add_effect(fx)
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)