Source code for manim.scene.moving_camera_scene

"""A scene whose camera can be moved around.




.. manim:: ChangingCameraWidthAndRestore

    class ChangingCameraWidthAndRestore(MovingCameraScene):
        def construct(self):
            text = Text("Hello World").set_color(BLUE)
   * 1.2))

.. manim:: MovingCameraCenter

    class MovingCameraCenter(MovingCameraScene):
        def construct(self):
            s = Square(color=RED, fill_opacity=0.5).move_to(2 * LEFT)
            t = Triangle(color=GREEN, fill_opacity=0.5).move_to(2 * RIGHT)
            self.add(s, t)

.. manim:: MovingAndZoomingCamera

    class MovingAndZoomingCamera(MovingCameraScene):
        def construct(self):
            s = Square(color=BLUE, fill_opacity=0.5).move_to(2 * LEFT)
            t = Triangle(color=YELLOW, fill_opacity=0.5).move_to(2 * RIGHT)
            self.add(s, t)


.. manim:: MovingCameraOnGraph

    class MovingCameraOnGraph(MovingCameraScene):
        def construct(self):

            ax = Axes(x_range=[-1, 10], y_range=[-1, 10])
            graph = ax.plot(lambda x: np.sin(x), color=WHITE, x_range=[0, 3 * PI])

            dot_1 = Dot(ax.i2gp(graph.t_min, graph))
            dot_2 = Dot(ax.i2gp(graph.t_max, graph))
            self.add(ax, graph, dot_1, dot_2)



from __future__ import annotations

__all__ = ["MovingCameraScene"]

from manim.animation.animation import Animation

from import MovingCamera
from ..scene.scene import Scene
from import extract_mobject_family_members
from ..utils.iterables import list_update

[docs]class MovingCameraScene(Scene): """ This is a Scene, with special configurations and properties that make it suitable for cases where the camera must be moved around. .. SEEALSO:: :class:`.MovingCamera` """ def __init__(self, camera_class=MovingCamera, **kwargs): super().__init__(camera_class=camera_class, **kwargs)
[docs] def get_moving_mobjects(self, *animations: Animation): """ This method returns a list of all of the Mobjects in the Scene that are moving, that are also in the animations passed. Parameters ---------- *animations The Animations whose mobjects will be checked. """ moving_mobjects = super().get_moving_mobjects(*animations) all_moving_mobjects = extract_mobject_family_members(moving_mobjects) movement_indicators = for movement_indicator in movement_indicators: if movement_indicator in all_moving_mobjects: # When one of these is moving, the camera should # consider all mobjects to be moving return list_update(self.mobjects, moving_mobjects) return moving_mobjects