Animations in Manim
Animations interpolate mobjects between states over time. They are played using self.play().
The .animate Syntax
The most common way to animate is using the .animate property:
# Move a square to the right
self.play(square.animate.shift(RIGHT))
# Scale up
self.play(circle.animate.scale(2))
# Change color
self.play(text.animate.set_color(RED))
# Chain multiple changes
self.play(square.animate.shift(RIGHT).rotate(PI/4).set_color(BLUE))Animation Parameters
run_time
Controls animation duration in seconds (default: 1).
self.play(Create(circle), run_time=2) # 2 second animation
self.play(Create(circle), run_time=0.5) # Half secondrate_func
Controls the animation's timing curve (easing).
from manim import smooth, linear, there_and_back
self.play(square.animate.shift(RIGHT), rate_func=smooth)
self.play(square.animate.shift(RIGHT), rate_func=linear)
self.play(square.animate.shift(RIGHT), rate_func=there_and_back)Playing Multiple Animations
Simultaneously
# All play at the same time
self.play(
Create(circle),
FadeIn(square),
Write(text)
)Sequentially
# One after another
self.play(Create(circle))
self.play(FadeIn(square))
self.play(Write(text))
# Or use Succession
self.play(Succession(
Create(circle),
FadeIn(square),
Write(text)
))Common Animation Classes
Creation Animations
Create(mobject) # Draw the mobject progressively
Write(text) # Write text/equations
FadeIn(mobject) # Fade in from transparent
DrawBorderThenFill(mob) # Draw outline, then fill
GrowFromCenter(mobject) # Grow from center pointRemoval Animations
FadeOut(mobject) # Fade to transparent
Uncreate(mobject) # Reverse of Create
ShrinkToCenter(mobject) # Shrink to center and disappearTransform Animations
Transform(mob1, mob2) # Morph mob1 into mob2
ReplacementTransform(mob1, mob2) # Replace mob1 with mob2
TransformFromCopy(mob1, mob2) # Keep mob1, create mob2Movement Animations
MoveToTarget(mobject) # Move to preset target
Rotate(mobject, angle) # Rotate by angle
Circumscribe(mobject) # Draw attention with circleAnimation vs Instant Changes
# Animated change (visible transition)
self.play(circle.animate.set_color(RED))
# Instant change (no animation)
circle.set_color(RED)
self.add(circle)Best Practices
- Use .animate for simple transformations - Cleaner than explicit Animation classes
- Keep run_time reasonable - 0.5-2 seconds for most animations
- Use rate_func for polish -
smoothis usually better thanlinear - Group related animations - Play simultaneously when conceptually related