Scenes and Sections
A Pymations file can be written two ways. Both play on one timeline in the preview, and both record to video the same way.
A short script
The quickest form: say what to play, one line after another.
from pymations import *
dot = Dot(color=YELLOW)
play(GrowFromCenter(dot))
play(dot.animate.shift(RIGHT * 2))
wait()
play, wait, add, remove and clear work on the file's own timeline. add(shape) puts something on screen at once, with no animation; remove(shape) takes it off; clear() empties the picture.
The Scene form
Longer pieces, Manim tutorials and AI-written scripts use classes. Each class is a scene, and its construct() method says what happens, with self. in front of play, wait and add:
from pymations import *
class Intro(Scene):
def construct(self):
title = Text("Squares and circles")
self.play(Write(title))
self.wait()
self.play(FadeOut(title))
class Shapes(Scene):
def construct(self):
square = Square(color=BLUE, fill_opacity=0.5)
self.play(Create(square))
self.play(Transform(square, Circle(color=ORANGE, fill_opacity=0.5)))
self.wait()
Every scene in the file plays, in the order it is written, one after the other on one timeline. Each scene starts with an empty picture. There is nothing to pick: press Run and you see them all, and a video records them all.
MovingCameraScene (for camera moves, see The camera), ZoomedScene and ThreeDScene are accepted too.
Sections
Each scene is a section, named after its class. On the timeline, a small tick marks where each section starts, so you can drag straight to it.
In a short script, start a section yourself:
from pymations import *
section("The circle")
play(Create(Circle()))
section("The square")
play(Create(Square().shift(RIGHT * 3)))
Inside a scene, self.next_section("name") does the same.
Transitions
A section can begin with a transition from the picture before it:
from pymations import *
section("The circle")
play(Create(Circle()))
wait()
section("The square", transition="slide_left")
clear()
play(Create(Square()))
| Transition | What you see |
|---|---|
"crossfade" | The old picture fades out as the new one fades in |
"slide_left" | The new picture slides in from the right, pushing the old one left |
"slide_right" | The new picture slides in from the left |
"wipe" | The new picture is uncovered from left to right |
transition_time=1 makes it last a second (half a second unless you say). config.transition = "crossfade" at the top of the file gives every section, and so every scene, that transition.
Settings for the whole file
config at the top of the file sets things for the whole animation:
from pymations import *
config.background_color = "#1e1e2e"
play(Write(Text("A different background")))
| Setting | What it does |
|---|---|
config.background_color | The colour behind everything (black unless you change it) |
config.frame_height | How many units tall the picture is (8). Larger fits more in and makes everything look smaller |
config.transition | How every section begins: "crossfade", "slide_left", "slide_right", "wipe" or "none" (the default) |
config(background_color=WHITE) sets several at once.
Related
- Your first animation
- Animations: timing,
run_timeand groups - Running Manim scripts