manim.scene.moving_camera_scene

A scene whose camera can be moved around.

See also

moving_camera

Examples

ChangingCameraWidthAndRestore
class ChangingCameraWidthAndRestore(MovingCameraScene):
    def construct(self):
        text = Text("Hello World").set_color(BLUE)
        self.add(text)
        self.camera_frame.save_state()
        self.play(self.camera_frame.animate.set_width(text.get_width() * 1.2))
        self.wait(0.3)
        self.play(Restore(self.camera_frame))
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.wait(0.3)
        self.add(s, t)
        self.play(self.camera_frame.animate.move_to(s))
        self.wait(0.3)
        self.play(self.camera_frame.animate.move_to(t))
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)
        self.play(self.camera_frame.animate.move_to(s).set_width(s.get_width()*2))
        self.wait(0.3)
        self.play(self.camera_frame.animate.move_to(t).set_width(t.get_width()*2))

        self.play(self.camera_frame.animate.move_to(ORIGIN).set_width(14))
MovingCameraOnGraph
class MovingCameraOnGraph(GraphScene, MovingCameraScene):
    def setup(self):
        GraphScene.setup(self)
        MovingCameraScene.setup(self)
    def construct(self):
        self.camera_frame.save_state()
        self.setup_axes(animate=False)
        graph = self.get_graph(lambda x: np.sin(x),
                               color=WHITE,
                               x_min=0,
                               x_max=3 * PI
                               )
        dot_at_start_graph = Dot().move_to(graph.points[0])
        dot_at_end_graph = Dot().move_to(graph.points[-1])
        self.add(graph, dot_at_end_graph, dot_at_start_graph)
        self.play(self.camera_frame.animate.scale(0.5).move_to(dot_at_start_graph))
        self.play(self.camera_frame.animate.move_to(dot_at_end_graph))
        self.play(Restore(self.camera_frame))
        self.wait()

Classes

MovingCameraScene

This is a Scene, with special configurations and properties that make it suitable for cases where the camera must be moved around.