Animation engine for explanatory math videos with programmatic mathematical visualization capabilities
—
ManimGL's animation system provides over 80 animation classes for transforming mathematical objects over time. The system includes base animation functionality, transform animations, creation effects, movement, indication, and specialized mathematical animations with precise timing control.
Foundation classes that provide core animation functionality and composition.
class Animation:
def __init__(self, mobject, **kwargs):
"""
Base class for all animations.
Parameters:
- mobject: Mobject to animate
- run_time: float, animation duration in seconds (default: 1.0)
- rate_func: function, timing function (default: smooth)
- reverse_rate_function: bool, reverse timing function
"""
def interpolate(self, alpha):
"""
Interpolate animation at given progress.
Parameters:
- alpha: float, animation progress (0-1)
Returns:
None
"""
class AnimationGroup(Animation):
def __init__(self, *animations, **kwargs):
"""
Group multiple animations to play simultaneously.
Parameters:
- animations: Animation instances to group
- lag_ratio: float, stagger start times (0=simultaneous, 1=sequential)
"""
class Succession(AnimationGroup):
def __init__(self, *animations, **kwargs):
"""
Play animations sequentially one after another.
Parameters:
- animations: Animation instances to play in sequence
"""
class LaggedStart(AnimationGroup):
def __init__(self, animation_or_mobjects, **kwargs):
"""
Start animations with staggered timing.
Parameters:
- animation_or_mobjects: Animation or mobjects to stagger
- lag_ratio: float, delay between starts (default: 0.05)
"""
class LaggedStartMap(LaggedStart):
def __init__(self, animation_class, mobjects, **kwargs):
"""
Apply lagged start to multiple objects with same animation.
Parameters:
- animation_class: Animation class to apply
- mobjects: List of mobjects to animate
"""Animations that change objects from one state to another, including morphing, scaling, and property changes.
class Transform(Animation):
def __init__(self, mobject, target_mobject, **kwargs):
"""
Morph one mobject into another.
Parameters:
- mobject: Source mobject
- target_mobject: Target mobject to transform into
- path_arc: float, arc path for transformation
- replace_mobject_with_target_in_scene: bool, replace after transform
"""
class ReplacementTransform(Transform):
def __init__(self, mobject, target_mobject, **kwargs):
"""
Replace one object with another during transformation.
Parameters:
- mobject: Object to be replaced
- target_mobject: Replacement object
"""
class TransformFromCopy(Transform):
def __init__(self, mobject, target_mobject, **kwargs):
"""
Transform from a copy, leaving original unchanged.
Parameters:
- mobject: Original mobject (unchanged)
- target_mobject: Target of transformation
"""
class ClockwiseTransform(Transform):
def __init__(self, mobject, target_mobject, **kwargs):
"""Transform with clockwise rotation."""
class CounterclockwiseTransform(Transform):
def __init__(self, mobject, target_mobject, **kwargs):
"""Transform with counterclockwise rotation."""
class MoveToTarget(Animation):
def __init__(self, mobject, **kwargs):
"""
Move object to its target state (set via .generate_target()).
Parameters:
- mobject: Mobject with target state set
"""
class ApplyMethod(Transform):
def __init__(self, method, *args, **kwargs):
"""
Apply a method as an animation.
Parameters:
- method: Bound method to apply
- args: Method arguments
"""
class ApplyFunction(Transform):
def __init__(self, function, mobject, **kwargs):
"""
Apply a function transformation as animation.
Parameters:
- function: Function to apply to mobject
- mobject: Target mobject
"""
class FadeToColor(Animation):
def __init__(self, mobject, color, **kwargs):
"""
Animate color change.
Parameters:
- mobject: Object to recolor
- color: Target color
"""
class ScaleInPlace(Animation):
def __init__(self, mobject, scale_factor, **kwargs):
"""
Scale object around its center.
Parameters:
- mobject: Object to scale
- scale_factor: Scaling factor
"""
class ShrinkToCenter(ScaleInPlace):
def __init__(self, mobject, **kwargs):
"""Shrink object to its center point."""
class Restore(Animation):
def __init__(self, mobject, **kwargs):
"""
Restore object to previously saved state.
Parameters:
- mobject: Object to restore (must have saved state)
"""
class ApplyMatrix(Animation):
def __init__(self, matrix, mobject, **kwargs):
"""
Apply matrix transformation.
Parameters:
- matrix: 3x3 transformation matrix
- mobject: Object to transform
"""Animations for revealing and removing objects with various visual effects.
class ShowCreation(Animation):
def __init__(self, vmobject, **kwargs):
"""
Progressively reveal a vectorized mobject.
Parameters:
- vmobject: VMobject to reveal
- lag_ratio: float, stagger submobject reveals
"""
class Uncreate(ShowCreation):
def __init__(self, vmobject, **kwargs):
"""Reverse of ShowCreation - progressively hide object."""
class DrawBorderThenFill(Animation):
def __init__(self, vmobject, **kwargs):
"""
First draw border, then fill interior.
Parameters:
- vmobject: VMobject to draw and fill
- stroke_width: float, border thickness during drawing
- stroke_color: Border color during drawing
"""
class Write(DrawBorderThenFill):
def __init__(self, vmobject, **kwargs):
"""
Writing animation optimized for text.
Parameters:
- vmobject: Text or TeX object to write
- lag_ratio: float, stagger character/word reveals
"""
class ShowIncreasingSubsets(Animation):
def __init__(self, group, **kwargs):
"""
Reveal submobjects progressively.
Parameters:
- group: Group or VGroup with submobjects
- int_func: function, controls subset progression
"""
class ShowSubmobjectsOneByOne(ShowIncreasingSubsets):
def __init__(self, group, **kwargs):
"""Show submobjects one by one sequentially."""
class AddTextWordByWord(Succession):
def __init__(self, text_mobject, **kwargs):
"""
Add text word by word.
Parameters:
- text_mobject: Text mobject to reveal word by word
- run_time: float, total time for all words
"""Animations for gradually appearing and disappearing objects with various fade effects.
class FadeIn(Animation):
def __init__(self, mobject, **kwargs):
"""
Fade object into view.
Parameters:
- mobject: Object to fade in
- shift: np.array, movement during fade
- scale: float, scaling during fade
"""
class FadeOut(Animation):
def __init__(self, mobject, **kwargs):
"""
Fade object out of view.
Parameters:
- mobject: Object to fade out
- shift: np.array, movement during fade
- scale: float, scaling during fade
"""
class FadeInFromPoint(FadeIn):
def __init__(self, mobject, point, **kwargs):
"""
Fade in from specific point.
Parameters:
- mobject: Object to fade in
- point: np.array, starting point
"""
class FadeOutToPoint(FadeOut):
def __init__(self, mobject, point, **kwargs):
"""
Fade out to specific point.
Parameters:
- mobject: Object to fade out
- point: np.array, ending point
"""
class FadeInFromLarge(FadeIn):
def __init__(self, mobject, scale_factor=2, **kwargs):
"""Fade in while shrinking from large size."""
class FadeOutToSmall(FadeOut):
def __init__(self, mobject, scale_factor=0, **kwargs):
"""Fade out while shrinking to small size."""
class VFadeIn(Animation):
def __init__(self, vmobject, **kwargs):
"""
Vectorized fade in for VMobjects.
Parameters:
- vmobject: VMobject to fade in
"""
class VFadeOut(Animation):
def __init__(self, vmobject, **kwargs):
"""
Vectorized fade out for VMobjects.
Parameters:
- vmobject: VMobject to fade out
"""Animations for moving objects along paths and through space.
class Homotopy(Animation):
def __init__(self, homotopy_function, mobject, **kwargs):
"""
Continuous deformation animation.
Parameters:
- homotopy_function: function(x, y, z, t) -> (x', y', z')
- mobject: Object to deform
"""
class PhaseFlow(Animation):
def __init__(self, function, mobject, **kwargs):
"""
Vector field flow animation.
Parameters:
- function: Vector field function
- mobject: Object to move through field
"""
class MoveAlongPath(Animation):
def __init__(self, mobject, path, **kwargs):
"""
Move object along specified path.
Parameters:
- mobject: Object to move
- path: VMobject path to follow
- rotate: bool, rotate object to follow path tangent
"""
class Rotating(Animation):
def __init__(self, mobject, **kwargs):
"""
Continuous rotation animation.
Parameters:
- mobject: Object to rotate
- axis: np.array, rotation axis
- radians: float, total rotation angle
- about_point: np.array, rotation center
"""
class Rotate(Animation):
def __init__(self, mobject, angle, **kwargs):
"""
Single rotation animation.
Parameters:
- mobject: Object to rotate
- angle: float, rotation angle in radians
- axis: np.array, rotation axis
- about_point: np.array, rotation center
"""Animations for highlighting and drawing attention to objects.
class FocusOn(Transform):
def __init__(self, focus_point, **kwargs):
"""
Focus attention on specific point.
Parameters:
- focus_point: np.array or Mobject, point to focus on
- opacity: float, focus indicator opacity
- color: Focus indicator color
"""
class Indicate(Transform):
def __init__(self, mobject, **kwargs):
"""
Indicate object with emphasis effect.
Parameters:
- mobject: Object to indicate
- scale_factor: float, emphasis scaling
- color: Indication color
"""
class Flash(AnimationGroup):
def __init__(self, point, **kwargs):
"""
Flash effect at specified point.
Parameters:
- point: np.array, flash location
- color: Flash color
- flash_radius: float, flash size
- num_lines: int, number of flash lines
"""
class CircleIndicate(Indicate):
def __init__(self, mobject, **kwargs):
"""
Circle indication around object.
Parameters:
- mobject: Object to circle
- circle_color: Circle color
"""
class ShowPassingFlash(ShowCreation):
def __init__(self, vmobject, **kwargs):
"""
Passing flash effect along object.
Parameters:
- vmobject: Path for flash to follow
- time_width: float, flash duration
"""
class ShowCreationThenDestruction(Succession):
def __init__(self, vmobject, **kwargs):
"""Show creation followed immediately by destruction."""
class ShowCreationThenFadeOut(Succession):
def __init__(self, vmobject, **kwargs):
"""Show creation followed by fade out."""
class AnimationOnSurroundingRectangle(AnimationGroup):
def __init__(self, mobject, **kwargs):
"""Animate a rectangle surrounding the mobject."""
class WiggleOutThenIn(Animation):
def __init__(self, mobject, **kwargs):
"""
Wiggle animation effect.
Parameters:
- mobject: Object to wiggle
- scale_value: float, wiggle amplitude
- rotation_angle: float, wiggle rotation
"""
class TurnInsideOut(Transform):
def __init__(self, mobject, **kwargs):
"""Turn object inside out transformation."""Animations for objects that grow or shrink with directional effects.
class GrowFromPoint(Transform):
def __init__(self, mobject, point, **kwargs):
"""
Grow object from specific point.
Parameters:
- mobject: Object to grow
- point: np.array, growth origin point
"""
class GrowFromCenter(GrowFromPoint):
def __init__(self, mobject, **kwargs):
"""Grow object from its center."""
class GrowFromEdge(GrowFromPoint):
def __init__(self, mobject, edge, **kwargs):
"""
Grow object from specified edge.
Parameters:
- mobject: Object to grow
- edge: np.array, edge direction (UP, DOWN, LEFT, RIGHT)
"""
class GrowArrow(GrowFromPoint):
def __init__(self, arrow, **kwargs):
"""
Specialized growth for arrows.
Parameters:
- arrow: Arrow object to grow
"""
class SpinInFromNothing(GrowFromCenter):
def __init__(self, mobject, **kwargs):
"""Grow with spinning effect."""Animations that continuously update objects based on functions or other objects.
class UpdateFromFunc(Animation):
def __init__(self, mobject, update_function, **kwargs):
"""
Update object using custom function.
Parameters:
- mobject: Object to update
- update_function: function(mobject, dt) -> None
- suspend_mobject_updating: bool, suspend other updates
"""
class UpdateFromAlphaFunc(UpdateFromFunc):
def __init__(self, mobject, update_function, **kwargs):
"""
Update object using alpha-based function.
Parameters:
- mobject: Object to update
- update_function: function(mobject, alpha) -> None
"""
class MaintainPositionRelativeTo(Animation):
def __init__(self, mobject, tracked_mobject, **kwargs):
"""
Maintain relative position to another object.
Parameters:
- mobject: Object to maintain position
- tracked_mobject: Object to track
"""
class CyclicReplace(Transform):
def __init__(self, *mobjects, **kwargs):
"""
Cyclically replace objects in sequence.
Parameters:
- mobjects: Objects to cycle through
"""from manimgl import *
class BasicAnimation(Scene):
def construct(self):
circle = Circle(color=BLUE)
square = Square(color=RED)
# Transform circle into square
self.play(ShowCreation(circle))
self.play(Transform(circle, square))
self.wait()class CompositionExample(Scene):
def construct(self):
objects = [Circle(), Square(), Triangle()]
# Stagger creation
self.play(LaggedStartMap(ShowCreation, objects, lag_ratio=0.3))
# Simultaneous animations
self.play(AnimationGroup(
FadeOut(objects[0]),
Rotate(objects[1], PI/4),
objects[2].animate.shift(UP)
))
self.wait()class UpdateExample(Scene):
def construct(self):
dot = Dot()
def update_dot(mobject, dt):
mobject.shift(RIGHT * dt)
self.add(dot)
self.play(UpdateFromFunc(dot, update_dot), run_time=3)
self.wait()Install with Tessl CLI
npx tessl i tessl/pypi-manimgldocs