The Camera

The camera decides what part of the picture you see: pan, zoom in, zoom out.

Zoom in and out

from pymations import *


class ZoomIn(MovingCameraScene):
    def construct(self):
        cells = VGroup(*[Square(side_length=0.8) for _ in range(24)]).arrange_in_grid(rows=4, buff=0.15)
        target = cells[9]
        self.play(FadeIn(cells))
        self.play(target.animate.set_fill(YELLOW, opacity=0.8))

        self.play(self.camera.frame.animate.scale(0.35).move_to(target), run_time=2)
        self.wait()
        self.play(self.camera.frame.animate.scale(1 / 0.35).move_to(ORIGIN), run_time=2)

self.camera.frame is the camera's view, as a rectangle in the picture. Animate it like any shape:

ChangeWhat you see
frame.animate.scale(0.5)Zooms in: the view is half as big, so everything looks twice the size
frame.animate.scale(2)Zooms out
frame.animate.move_to(m)Centres the view on m (or on a point)
frame.animate.shift(RIGHT * 3)Pans

To go back to where you started, scale by one over the zoom and move to ORIGIN, as above.

Use MovingCameraScene instead of Scene for a scene that moves the camera, as Manim scripts do. In a short script without a class, the camera is camera.frame:

from pymations import *

dot = Dot(RIGHT * 3, color=YELLOW)
play(GrowFromCenter(dot))
play(camera.frame.animate.scale(0.4).move_to(dot), run_time=2)

The background

config.background_color = "#101820" (or self.camera.background_color in a scene) sets the colour behind everything. See Scenes and sections.

3D scenes

ThreeDScene and ThreeDAxes are accepted, so a 3D Manim script still runs, but the preview shows it flat, in 2D, for now. Camera turns such as set_camera_orientation and move_camera are skipped, and the output under the preview says so. For 3D pictures today, use Pyctures 3D.