| name | manimlib-animations-animations |
| description | Reference for manimlib animation primitives, transform families, and timing patterns used with self.play(). |
| metadata | {"short-description":"manimlib animation API reference"} |
Animations
All animations are passed to self.play(). Multiple animations in the same self.play() call run simultaneously.
self.play(anim1, anim2, anim3)
self.play(anim1, anim2, run_time=2)
self.play(anim1, rate_func=linear)
Creation Animations
Write
The go-to animation for text and Tex. Draws the border then fills.
self.play(Write(text))
self.play(Write(tex, run_time=3))
self.play(Write(tex, rate_func=linear))
Write extends DrawBorderThenFill:
- First half: draws the outline stroke
- Second half: fills in the fill color
run_time defaults to 1 for < 15 submobjects, 2 otherwise
lag_ratio is auto-calculated: min(4.0 / (family_size + 1.0), 0.2)
ShowCreation
Draws a VMobject from start to end along its path. Great for lines, curves, graphs.
self.play(ShowCreation(line))
self.play(ShowCreation(circle, run_time=2))
self.play(ShowCreation(graph))
Uncreate
Reverse of ShowCreation -- erases from end to start.
self.play(Uncreate(line))
DrawBorderThenFill
Like Write but more configurable.
self.play(DrawBorderThenFill(shape))
self.play(DrawBorderThenFill(shape, stroke_width=3, stroke_color=YELLOW))
AddTextWordByWord
Shows text word by word.
self.play(AddTextWordByWord(text, time_per_word=0.2))
ShowIncreasingSubsets / ShowSubmobjectsOneByOne
self.play(ShowIncreasingSubsets(VGroup(*dots), run_time=3))
self.play(ShowSubmobjectsOneByOne(VGroup(*dots), run_time=3))
Fading Animations
FadeIn
self.play(FadeIn(mob))
self.play(FadeIn(mob, shift=UP))
self.play(FadeIn(mob, shift=LEFT * 2))
self.play(FadeIn(mob, scale=0.5))
self.play(FadeIn(mob, shift=DOWN, scale=2))
FadeOut
self.play(FadeOut(mob))
self.play(FadeOut(mob, shift=DOWN))
self.play(FadeOut(mob, scale=0.5))
FadeInFromPoint / FadeOutToPoint
self.play(FadeInFromPoint(mob, point=ORIGIN))
self.play(FadeOutToPoint(mob, point=UP * 3))
FadeTransform
Cross-fades between two different mobjects by matching their shapes/positions.
self.play(FadeTransform(old_mob, new_mob))
FadeTransformPieces
Like FadeTransform but aligns submobject families first.
self.play(FadeTransformPieces(old_group, new_group))
VFadeIn / VFadeOut / VFadeInThenOut
VMobject-specific fading that only adjusts stroke/fill opacity (no position change).
self.play(VFadeIn(vmob))
self.play(VFadeOut(vmob))
self.play(VFadeInThenOut(vmob))
Transform Animations
Transform
Morphs one mobject into the shape/style of another. The original mobject persists (its data changes).
self.play(Transform(mob_a, mob_b))
ReplacementTransform
Like Transform, but replaces the original with the target in the scene.
self.play(ReplacementTransform(mob_a, mob_b))
TransformFromCopy
Creates a copy of the source and transforms it into the target. Source stays unchanged.
self.play(TransformFromCopy(mob_a, mob_b))
MoveToTarget
Animates a mobject to its .target attribute.
circle.generate_target()
circle.target.shift(RIGHT * 2)
circle.target.set_color(RED)
self.play(MoveToTarget(circle))
Note: mob.animate.method() internally uses this mechanism.
ApplyMethod (legacy)
self.play(ApplyMethod(circle.shift, RIGHT * 2))
ApplyFunction
Apply an arbitrary function to a mobject.
self.play(ApplyFunction(lambda m: m.scale(2).set_color(RED), circle))
ApplyMatrix
Apply a linear transformation matrix.
self.play(ApplyMatrix([[2, 1], [0, 1]], mob))
self.play(ApplyMatrix(np.eye(3), mob))
ApplyComplexFunction
Apply a complex function to all points (treating xy-plane as complex plane).
self.play(ApplyComplexFunction(lambda z: z**2, plane))
Restore
Animate a mobject back to its saved state.
circle.save_state()
self.play(circle.animate.shift(RIGHT * 3).set_color(RED))
self.play(Restore(circle))
CyclicReplace / Swap
self.play(CyclicReplace(a, b, c))
self.play(Swap(a, b))
Other transforms
ScaleInPlace(mob, 2)
ShrinkToCenter(mob)
FadeToColor(mob, RED)
Matching Transforms
TransformMatchingStrings (for Tex/Text morphing)
The most powerful tool for animating equation changes. Automatically matches identical substrings.
eq1 = Tex("x^2 + y^2 = 1")
eq2 = Tex("x^2 + y^2 = r^2")
self.play(Write(eq1))
self.wait()
self.play(TransformMatchingStrings(eq1, eq2))
matched_keys
Force specific substrings to match even if they differ:
self.play(TransformMatchingStrings(
eq1, eq2,
matched_keys=["x^2", "y^2", "="],
))
key_map
Map a substring in source to a different substring in target:
eq1 = Tex("a^2 + b^2 = c^2")
eq2 = Tex("x^2 + y^2 = z^2")
self.play(TransformMatchingStrings(
eq1, eq2,
key_map={"a": "x", "b": "y", "c": "z"},
))
matched_pairs
Directly specify pairs of submobjects to match:
self.play(TransformMatchingStrings(
eq1, eq2,
matched_pairs=[(eq1[0:3], eq2[0:3])],
))
TransformMatchingShapes / TransformMatchingParts
Matches based on geometric shape similarity (not string content). Works on any mobjects.
self.play(TransformMatchingShapes(group1, group2))
TransformMatchingTex
Alias for TransformMatchingStrings.
Indication Animations
Indicate
Temporarily scales up and changes color, then reverts.
self.play(Indicate(mob))
self.play(Indicate(mob, scale_factor=1.5, color=RED))
Flash
Creates radiating flash lines at a point.
self.play(Flash(point))
self.play(Flash(mob))
self.play(Flash(
point,
color=RED,
line_length=0.3,
num_lines=16,
flash_radius=0.5,
))
CircleIndicate
Draws a circle around a mobject that appears and disappears.
self.play(CircleIndicate(mob, color=YELLOW))
FlashAround
A stroke flash that traces around the boundary of a mobject.
self.play(FlashAround(mob))
self.play(FlashAround(mob, color=RED, stroke_width=6, time_width=1.0))
FlashUnder
Like FlashAround but only underlines.
self.play(FlashUnder(mob))
ShowPassingFlash
A partial stroke that travels along a path.
self.play(ShowPassingFlash(path.copy(), time_width=0.3, run_time=2))
VShowPassingFlash
Gaussian-width version of ShowPassingFlash (smoother).
self.play(VShowPassingFlash(path.copy(), time_width=0.3, run_time=2))
ApplyWave
Sends a wave distortion through a mobject.
self.play(ApplyWave(mob))
self.play(ApplyWave(mob, direction=UP, amplitude=0.3))
WiggleOutThenIn
self.play(WiggleOutThenIn(mob, scale_value=1.1, rotation_angle=0.02 * TAU))
ShowCreationThenDestruction
self.play(ShowCreationThenDestruction(path.copy(), run_time=2))
ShowCreationThenFadeOut
self.play(ShowCreationThenFadeOut(circle.copy()))
FlashyFadeIn
Combines a fade-in with a passing flash outline.
self.play(FlashyFadeIn(vmob, stroke_width=2))
Composition Animations
AnimationGroup
Play multiple animations simultaneously with explicit control.
self.play(AnimationGroup(
FadeIn(a),
FadeIn(b),
FadeIn(c),
lag_ratio=0,
))
Succession
Play animations one after another within a single self.play().
self.play(Succession(
FadeIn(a),
FadeIn(b),
FadeIn(c),
))
LaggedStart
Stagger the start times of animations.
self.play(LaggedStart(
FadeIn(a), FadeIn(b), FadeIn(c),
lag_ratio=0.2,
))
LaggedStartMap
Apply the same animation function to each submobject of a group, with lagged starts.
self.play(LaggedStartMap(FadeIn, group, lag_ratio=0.1))
self.play(LaggedStartMap(Write, equations, lag_ratio=0.3, run_time=4))
self.play(LaggedStartMap(GrowFromCenter, dots, lag_ratio=0.05))
self.play(LaggedStartMap(FadeIn, group, shift=UP, lag_ratio=0.1))
Movement Animations
MoveAlongPath
self.play(MoveAlongPath(dot, circle_path, run_time=3))
Homotopy
Apply a continuous deformation (x, y, z, t) -> (x', y', z').
self.play(Homotopy(
lambda x, y, z, t: (x + t, y + t * np.sin(x), z),
mob,
run_time=3,
))
ComplexHomotopy
self.play(ComplexHomotopy(
lambda z, t: z * np.exp(1j * t * PI),
plane,
run_time=3,
))
PhaseFlow
Apply a vector field flow to a mobject.
self.play(PhaseFlow(
lambda p: np.array([-p[1], p[0], 0]),
mob,
run_time=3,
))
Rotation Animations
Rotate
self.play(Rotate(mob, angle=PI))
self.play(Rotate(mob, angle=TAU, axis=UP))
self.play(Rotate(mob, angle=90 * DEG))
Rotating
Like Rotate but defaults to a full turn with linear rate function and longer run_time.
self.play(Rotating(mob, angle=TAU, run_time=5, rate_func=linear))
Number Animations
ChangeDecimalToValue
Animate a DecimalNumber from its current value to a target.
num = DecimalNumber(0)
self.play(ChangeDecimalToValue(num, 100), run_time=3)
CountInFrom
Animate counting from a source number to the current value.
num = DecimalNumber(42)
self.play(CountInFrom(num, 0))
ChangingDecimal
Most flexible -- provide a function from alpha to value.
self.play(ChangingDecimal(
num,
lambda alpha: alpha * 100,
run_time=3,
))
Growing Animations
GrowFromCenter
self.play(GrowFromCenter(mob))
GrowFromPoint
self.play(GrowFromPoint(mob, point=ORIGIN))
self.play(GrowFromPoint(mob, point=LEFT * 3, point_color=RED))
GrowFromEdge
self.play(GrowFromEdge(mob, edge=DOWN))
GrowArrow
Grows an arrow from its start point.
self.play(GrowArrow(arrow))
Update Animations
UpdateFromFunc
Apply a function to a mobject each frame during the animation.
self.play(UpdateFromFunc(
label,
lambda m: m.next_to(dot, UP),
), run_time=3)
UpdateFromAlphaFunc
Like UpdateFromFunc but the function also receives the animation alpha.
self.play(UpdateFromAlphaFunc(
mob,
lambda m, alpha: m.set_opacity(alpha),
), run_time=2)
MaintainPositionRelativeTo
Keep a mobject at a fixed offset from another mobject during animation.
self.play(
dot.animate.shift(RIGHT * 3),
MaintainPositionRelativeTo(label, dot),
run_time=2,
)
Animation Parameters
All animations accept these keyword arguments:
Animation(
mobject,
run_time=1.0,
rate_func=smooth,
lag_ratio=0,
remover=False,
suspend_mobject_updating=False,
)
These can also be passed to self.play() to override for all animations in that call:
self.play(FadeIn(a), FadeIn(b), run_time=2, rate_func=linear)
time_span
Specify when during the total run_time an animation should be active:
self.play(
FadeIn(a, time_span=(0, 1)),
FadeIn(b, time_span=(1, 2)),
FadeIn(c, time_span=(0.5, 1.5)),
run_time=2,
)
This is an alternative to LaggedStart / Succession for fine-grained timing control.