Пример #1
0
def test_scene_add_remove():
    """Test Scene.add() and Scene.remove()."""
    with tempconfig({"dry_run": True}):
        scene = Scene()
        container_add(scene, lambda: scene.mobjects)
        scene = Scene()
        container_remove(scene, lambda: scene.mobjects)
Пример #2
0
    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
Пример #3
0
def test_add_sound(tmpdir):
    # create sound file
    sound_loc = Path(tmpdir, "noise.wav")
    f = wave.open(str(sound_loc), "w")
    f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
    for _ in range(22050):  # half a second of sound
        packed_value = struct.pack("h", 14242)
        f.writeframes(packed_value)
        f.writeframes(packed_value)

    f.close()

    scene = Scene()
    scene.add_sound(sound_loc)
Пример #4
0
def test_add_sound():
    # create sound file
    f = wave.open("noise.wav", "w")
    f.setparams((2, 2, 44100, 0, "NONE", "not compressed"))
    for _ in range(22050):  # half a second of sound
        packed_value = struct.pack("h", 14242)
        f.writeframes(packed_value)
        f.writeframes(packed_value)

    f.close()

    scene = Scene()
    scene.add_sound("noise.wav")

    os.remove("noise.wav")
Пример #5
0
def test_ABC():
    """Test that the Container class cannot be instantiated."""
    with pytest.raises(TypeError):
        Container()

    # The following should work without raising exceptions
    Mobject()
    Scene()
Пример #6
0
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
Пример #7
0
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]
Пример #8
0
    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
Пример #9
0
def test_background_color(using_opengl_renderer):
    S = Scene()
    S.renderer.background_color = "#ff0000"
    S.renderer.update_frame(S)
    assert np.all(S.renderer.get_frame()[0, 0] == np.array([255, 0, 0, 255]))

    S.renderer.background_color = "#436f80"
    S.renderer.update_frame(S)
    assert np.all(S.renderer.get_frame()[0,
                                         0] == np.array([67, 111, 128, 255]))

    S.renderer.background_color = "#fff"
    S.renderer.update_frame(S)
    assert np.all(S.renderer.get_frame()[0,
                                         0] == np.array([255, 255, 255, 255]))
Пример #10
0
def test_background_color():
    S = Scene()
    S.camera.background_color = "#ff0000"
    S.renderer.update_frame(S)
    assert np.all(S.renderer.get_frame()[0, 0] == np.array([255, 0, 0, 255]))

    S.camera.background_color = "#436f80"
    S.renderer.update_frame(S)
    assert np.all(S.renderer.get_frame()[0,
                                         0] == np.array([67, 111, 128, 255]))

    S.camera.background_color = "#bbffbb"
    S.camera.background_opacity = 0.5
    S.renderer.update_frame(S)
    assert np.all(S.renderer.get_frame()[0,
                                         0] == np.array([187, 255, 187, 127]))
Пример #11
0
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"
Пример #12
0
def test_background_color():
    S = Scene()
    S.camera.background_color = "#ff0000"
    S.renderer.update_frame(S)
    np.testing.assert_array_equal(S.renderer.get_frame()[0, 0],
                                  np.array([255, 0, 0, 255]))

    S.camera.background_color = "#436f80"
    S.renderer.update_frame(S)
    np.testing.assert_array_equal(S.renderer.get_frame()[0, 0],
                                  np.array([67, 111, 128, 255]))

    S.camera.background_color = "#fff"
    S.renderer.update_frame(S)
    np.testing.assert_array_equal(S.renderer.get_frame()[0, 0],
                                  np.array([255, 255, 255, 255]))

    S.camera.background_color = "#bbffbb"
    S.camera.background_opacity = 0.5
    S.renderer.update_frame(S)
    np.testing.assert_array_equal(S.renderer.get_frame()[0, 0],
                                  np.array([93, 127, 93, 127]))
Пример #13
0
def test_scene_add_remove():
    with tempconfig({"dry_run": True}):
        scene = Scene()
        assert len(scene.mobjects) == 0
        scene.add(Mobject())
        assert len(scene.mobjects) == 1
        scene.add(*(Mobject() for _ in range(10)))
        assert len(scene.mobjects) == 11

        # Check that adding a mobject twice does not actually add it twice
        repeated = Mobject()
        scene.add(repeated)
        assert len(scene.mobjects) == 12
        scene.add(repeated)
        assert len(scene.mobjects) == 12

        # Check that Scene.add() returns the Scene (for chained calls)
        assert scene.add(Mobject()) is scene
        to_remove = Mobject()
        scene = Scene()
        scene.add(to_remove)
        scene.add(*(Mobject() for _ in range(10)))
        assert len(scene.mobjects) == 11
        scene.remove(to_remove)
        assert len(scene.mobjects) == 10
        scene.remove(to_remove)
        assert len(scene.mobjects) == 10

        # Check that Scene.remove() returns the instance (for chained calls)
        assert scene.add(Mobject()) is scene
Пример #14
0
def test_scene_remove():
    """Test Scene.remove()."""
    scene = Scene()
    container_remove(scene, lambda: scene.mobjects)
Пример #15
0
def test_scene_add():
    """Test Scene.add()."""
    scene = Scene()
    container_add(scene, lambda: scene.mobjects)
Пример #16
0
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)))