def __init__(self, origin: m.Mobject, scene: m.Scene): self.entries = m.Group( m.Tex("Contexte~:", color=m.GRAY).next_to(origin, m.UP * 2, aligned_edge=m.LEFT)) scene.play(m.FadeInFrom(self.entries, direction=m.DOWN)) self.scene = scene
def test_scene_time(): with tempconfig({"dry_run": True}): scene = Scene() assert scene.renderer.time == 0 scene.wait(2) assert scene.renderer.time == 2 scene.play(FadeIn(Circle()), run_time=0.5) assert pytest.approx(scene.renderer.time) == 2.5 scene.renderer._original_skipping_status = True scene.play(FadeIn(Square()), run_time=5) # this animation gets skipped. assert pytest.approx(scene.renderer.time) == 7.5
def test_custom_animation_mobject_list(): G = Graph([1, 2, 3], [(1, 2), (2, 3)]) scene = Scene() scene.add(G) assert scene.mobjects == [G] with tempconfig({"dry_run": True, "quality": "low_quality"}): scene.play(G.animate.add_vertices(4)) assert str(G) == "Graph on 4 vertices and 2 edges" assert scene.mobjects == [G] scene.play(G.animate.remove_vertices(2)) assert str(G) == "Graph on 3 vertices and 0 edges" assert scene.mobjects == [G]
def test_subcaption(): with tempconfig({"dry_run": True}): scene = Scene() scene.add_subcaption("Testing add_subcaption", duration=1, offset=0) scene.wait() scene.play( Wait(), run_time=2, subcaption="Testing Scene.play subcaption interface", subcaption_duration=1.5, subcaption_offset=0.5, ) subcaptions = scene.renderer.file_writer.subcaptions assert len(subcaptions) == 2 assert subcaptions[0].start == datetime.timedelta(seconds=0) assert subcaptions[0].end == datetime.timedelta(seconds=1) assert subcaptions[0].content == "Testing add_subcaption" assert subcaptions[1].start == datetime.timedelta(seconds=1.5) assert subcaptions[1].end == datetime.timedelta(seconds=3) assert subcaptions[ 1].content == "Testing Scene.play subcaption interface"
def animate(self, scene: Scene): for actor in self.actors.values(): actor.stretch( sum(item.get_height() + 0.5 for item in self.interactions)) if scene.renderer.camera.frame_height < self.get_height() + 1.5: height_scale = scene.renderer.camera.frame_height / ( self.get_height() + 1.5) else: height_scale = 1 if scene.renderer.camera.frame_width < self.get_width() + 5: width_scale = scene.renderer.camera.frame_width / ( self.get_width() + 5) else: width_scale = 1 scale = min(1, height_scale, width_scale) self.scale(scale) self.to_edge(UP) self.to_edge(LEFT) start_y = self.get_edge_center(UP)[1] - 1.5 * scale scene.play(ShowCreation(self)) last: Interaction = None for interaction in [item for item in self.interactions if item.target]: interaction.scale(scale) if not last: interaction.set_y(start_y, direction=UP) else: interaction.set_y(last.get_y(DOWN) - 0.5 * scale, direction=UP) scene.play(ShowCreation(interaction)) last = interaction
def replace_expr(scene: m.Scene, expr: m.Mobject, text: str, **kwargs) -> None: """Play an animation that transforms an expression in an other kwargs are given to a call to the new Mobject's `move_to` method """ scene.play(m.Transform(expr, m.Tex(text).move_to(expr, **kwargs)))