1. Home
  2. Explore
  3. Computer Science
  4. 3Blue1Brown Manim Animation Overview

Study methods

Flashcards
Quiz
Fill in the blanks
Written test
Lesson
Notes
Podcast
Content

3Blue1Brown Manim Animation Overview

Manim: Programmatic Mathematical Animation and the Lorenz Attractor

What Manim Is

Manim is a custom Python library for creating mathematical animations through code. Instead of manually drawing and editing every frame, the animator describes mathematical objects and their transformations programmatically.

Manim is designed to be:

  • Programmatic: scenes, objects, animations, and transformations are written in Python.

  • Mathematics-oriented: it includes objects and functions specifically useful for mathematical communication.

  • Bespoke: many features were created to support particular visual and pedagogical needs.

  • Vector-based: many objects are represented as geometric data, allowing them to scale, transform, and render cleanly.

The central philosophy is that mathematical ideas should be expressible as relationships between objects and transformations. A scene might contain equations, graphs, geometric shapes, coordinate systems, or dynamically evolving curves.


Versions of Manim

There are two important versions of Manim.

Original Version

The original version began as a personal Python project intended to illustrate mathematical functions as transformations. It developed alongside the animator’s mathematical animation work:

  1. A basic tool was written to display mathematical transformations.

  2. The tool was used to create animations.

  3. New animation requirements led to improvements in the tool.

  4. Those improvements made increasingly sophisticated animations possible.

  5. The cycle continued as more videos and visual experiments were created.

The original version has accumulated features such as:

  • More interactive scene development

  • Improved performance

  • Specialized animation effects

  • More flexible object transformations

  • Tools for manipulating mathematical text and geometric components

  • Support for three-dimensional scenes and camera movement

The code used to create animations and the underlying library were made publicly available.

Manim Community Version

Because the original project was primarily developed for personal use, it was not consistently managed as a conventional open-source project. A community interested in making Manim more robust created a fork called the Manim Community version.

The community version emphasizes:

  • Better issue and pull-request management

  • More systematic testing

  • Improved documentation

  • Greater usability for people who are learning or using Manim independently

  • A more maintained and accessible development process

Recommended starting point: New users are generally better served by the Manim Community version because it is more thoroughly documented and tested.

The original version and the community version share many fundamental ideas, but their implementations and available features may differ. Code written for one version may require adjustments before it works in the other.


Basic Manim Workflow

Scenes as Python Classes

A Manim animation is organized into a scene. Each scene is represented by a Python class.

A basic scene has:

  • A class defining the scene

  • A construct method containing the instructions that create and animate objects

  • Mathematical objects added to the scene

  • Animation commands that determine how those objects appear or change

Conceptually, a simple scene has the following structure:

class ExampleScene(Scene):
    def construct(self):
        # Create objects
        # Add objects
        # Animate objects
        pass

The construct method is where the code responsible for rendering the scene is placed.

Mathematical Objects

Manim refers to objects representing mathematical entities as mobjects, short for “mathematical objects.” Examples include:

  • Circles

  • Squares

  • Text

  • LaTeX equations

  • Coordinate axes

  • Curves

  • Dots

  • Camera frames

  • Groups of objects

Most newly created objects initially appear at the center of the scene unless their position is explicitly changed.

For example, creating a square does not automatically place it at the top or side of the screen. Movement methods must be used to reposition it.


Adding Objects to a Scene

Creating an object and adding it to a scene are separate operations.

For example:

  1. A circle is defined and stored in a variable.

  2. A square is defined and stored in another variable.

  3. The objects are added to the scene with an add operation.

An object that has been created but not added to the scene generally does not appear in the rendered output.

This distinction is useful because an object can be prepared in advance and then introduced later through an animation or transformation.

Positioning Objects

Objects can be moved using methods such as:

  • Shifting horizontally or vertically

  • Moving to an edge

  • Moving to a corner

  • Aligning with another object

  • Moving to a specified coordinate

  • Transforming into another object

For example, a square can be moved to the right or placed against the upper edge of the frame.


Interactive Python Control

Manim can be used with an interactive Python terminal that communicates with the current scene.

This allows the animator to issue commands such as:

square.shift(RIGHT)

The result can be observed immediately. Running the command again applies the movement again, so the square shifts farther to the right.

The interactive terminal can also evaluate ordinary Python expressions, such as calculating 1+21 + 21+2. It is therefore both:

  • A normal Python environment

  • A control interface for the active Manim scene

This interaction is useful during scene development because it allows rapid visual experimentation without repeatedly rendering an entire animation.


Rapid Iteration

A productive Manim workflow depends on quickly testing small pieces of code.

A common process is:

  1. Write a line of Python in the text editor.

  2. Copy the line.

  3. Paste it into the interactive terminal.

  4. Run it.

  5. Observe the visual result.

  6. Modify the code if necessary.

Manim workflows can automate this process with keyboard shortcuts. A shortcut can copy the selected code from the text editor and send it directly to the interactive terminal.

This creates a fast feedback loop:

Edit code → run code → inspect the visual result → revise code

Rapid iteration is particularly important for animation because the final appearance depends on many factors that are difficult to predict from code alone, including:

  • Position

  • Scale

  • Color

  • Timing

  • Motion smoothness

  • Layering

  • Camera angle

  • Visual balance

  • Interaction between multiple objects


Checkpoints and Notebook-Like Development

The Problem with Long Scenes

A complex animation may consist of a large Python scene containing many sequential operations. A long scene can be useful because all of its variables and context remain available, but rerunning the entire scene whenever one small section changes is inefficient.

For example, a scene may already have:

  • Coordinate axes

  • Several graphs

  • Text and equations

  • Previously animated objects

  • Variables containing mathematical data

  • Camera positioning

  • Earlier transformations

If the animator is working on a small section near the middle of the scene, restarting from the beginning every time would make experimentation slow.


Checkpoint Paste

A checkpoint-based workflow allows a section of code to be run from a saved state.

The basic process is:

  1. A scene reaches a particular point.

  2. The current state is cached and associated with a marker or comment.

  3. A later section of code is copied.

  4. The system detects the marker.

  5. The scene is restored to the cached state.

  6. The selected section is executed from that state.

This prevents the selected code from being run in an inappropriate or already-modified state.

Checkpoint paste makes a plain Python file behave somewhat like a Jupyter notebook, where individual cells can be executed while retaining a computational state.

The workflow is a hybrid between:

  • A single, organized source file

  • A live, interactive notebook

  • A debugger that can resume execution from a meaningful point

Keeping the entire scene in one file has advantages:

  • Local variables remain available

  • The overall sequence is easy to inspect

  • Context is preserved

  • Related operations can remain close together

  • The animator does not have to divide every small operation into separate functions


Core Animation Concepts

The play Method

Manim distinguishes between:

  • Adding a finished object immediately

  • Playing an animation that changes how an object appears

The play method is used when an object should be animated.

For example, instead of immediately adding text, the animator can play an animation that writes the text onto the screen.

Conceptually:

self.play(Write(text))

The play method can accept:

  • A single animation

  • Multiple animations

  • A runtime controlling how long the animations take

  • Animation-specific parameters

If several animations are passed to one play call, they can occur simultaneously.


Writing Objects onto the Screen

The Write animation creates the appearance that an object is being written or drawn onto the screen.

It is especially useful for:

  • Text

  • Equations

  • Mathematical notation

  • Curves

  • Diagrams

The effect is strongly associated with Manim’s visual style. The object does not simply appear all at once; its components are progressively revealed.

The duration can be adjusted with a runtime parameter. A longer runtime makes the writing process slower and more visually deliberate.


Transforming Objects

One of Manim’s central design philosophies is:

Almost any object can transform into almost any other object.

For example, a character from a word can transform into a circle. The circle does not need to have been added to the scene beforehand. It can exist as a target object used by the transformation.

A transformation involves:

  1. Selecting or extracting an object.

  2. Defining a target object.

  3. Mapping the original object’s geometry onto the target geometry.

  4. Interpolating between the original and target states over time.

The transformation is based on the underlying points that describe the objects.

Transformations are useful for representing conceptual relationships, such as:

  • A symbol becoming a geometric object

  • One equation changing into an equivalent equation

  • A graph changing as a parameter varies

  • A shape deforming into another shape

  • A visual metaphor for mathematical equivalence

The transformation from a letter to a circle may not have a direct pedagogical purpose, but it demonstrates the flexibility of the system.


Groups and Object Hierarchies

Manim objects can contain other objects in a hierarchy.

For example:

  • A complete mathematical expression can be a group.

  • The expression can contain groups representing individual terms.

  • A term can contain individual symbols.

  • A symbol can contain its geometric point data.

This hierarchy allows the animator to control objects at different levels of detail.

Possible operations include:

  • Transforming an entire equation

  • Selecting a particular term

  • Extracting a specific character

  • Manipulating the geometric points of a single symbol

  • Applying different colors to different variables

A text object can therefore be treated as a collection of characters rather than as one indivisible object.

In Python, indexing begins at zero. Thus, the first element of a list is accessed using index 000.


Accessing Geometric Data

Manim’s vectorized objects are described by geometric point data. An animator can work with:

  • The entire object

  • A group of subobjects

  • A single subobject

  • The underlying points that define the subobject

Accessing the points directly allows more precise control over how an object transforms.

This is useful when the default transformation behavior is not visually appropriate. For example, transforming a large letter into a circle might cause the letter to shrink while the circle grows. Selecting the correct geometric component can produce a more controlled effect.


Animation Timing and Rate Functions

Runtime

The runtime determines how long an animation takes.

A runtime can be assigned:

  • To an individual animation

  • To a complete play call

  • To multiple simultaneous animations

When a runtime is supplied to play, it can serve as the duration for every animation passed into that call.

For example, if a curve is supposed to represent ten seconds of a dynamical system, the animation can be given a runtime of ten seconds so that visual time corresponds to mathematical time.


Rate Functions

A rate function controls how an animation progresses through time.

The default rate function is generally smooth. This means the animation tends to:

  • Begin gradually

  • Move more quickly through the middle

  • End gradually

This behavior creates visually pleasing motion and avoids abrupt starts and stops.

A linear rate function progresses at a constant rate. It is appropriate when the speed of the visual motion itself represents a mathematical process.

Smooth Motion

Smooth interpolation is usually preferable for:

  • Camera movement

  • Decorative transitions

  • Object introductions

  • General visual polish

  • Transformations where constant speed is not mathematically meaningful

Linear Motion

Linear interpolation is important when:

  • A curve represents a time-dependent system

  • The movement should correspond directly to elapsed time

  • Smoothing would distort the mathematical behavior

  • The animator wants to preserve the actual distribution of points along a trajectory

If a curve is drawn with a smooth rate function, Manim may alter the apparent speed along the curve. For a physical or mathematical trajectory, this can mask the system’s true evolution. In such cases, linear timing better preserves the intended interpretation.

Visual polish and mathematical fidelity can conflict. Smooth motion often looks better, but linear motion may be necessary when animation speed carries mathematical meaning.


Rendering Modes: Two Dimensions and Three Dimensions

Default Two-Dimensional Scenes

Manim scenes are often two-dimensional by default. Objects generally lie on the xyxyxy-plane, which gives the scene a blackboard-like appearance.

Two-dimensional scenes are often preferable because they:

  • Make mathematical content easier to read

  • Avoid unnecessary visual complexity

  • Emphasize diagrams and equations

  • Match how many mathematical ideas are naturally presented

  • Reduce the cognitive burden on the viewer

Three-dimensional rendering should be used when depth is essential to understanding the concept.


Three-Dimensional Scenes

A three-dimensional scene adds:

  • A zzz-coordinate

  • Three-dimensional axes

  • Depth relationships

  • Camera orientation

  • Perspective changes

  • Possibility of rotating or panning around an object

Objects may initially appear flat because the camera is viewing the scene from a particular direction. A three-dimensional object can therefore look two-dimensional until the camera is moved.

A three-dimensional coordinate system allows a point to be represented as:

(x,y,z)(x,y,z)(x,y,z)

The Lorenz attractor is fundamentally three-dimensional, so a three-dimensional scene is appropriate for displaying its structure.


Camera Movement

Camera movement can be animated just like any other object.

The camera frame can be:

  • Rotated

  • Reoriented

  • Shifted

  • Panned

  • Moved around a three-dimensional scene

A camera transformation can be animated over a specified runtime. This allows the camera to slowly reveal different viewpoints of a three-dimensional object.

Smooth camera movement is generally preferable because abrupt movement can make the scene difficult to follow. In three dimensions, camera motion is especially important because changing the viewpoint creates the visual cues that communicate depth.

A useful interactive workflow is:

  1. Move or rotate the camera manually.

  2. Find a position that shows the geometry clearly.

  3. Copy or save the camera’s current position.

  4. Use that position as the target of an animated camera transformation.

Objects that should remain fixed relative to the screen can be attached to the camera frame. These objects are called fixed in frame and remain in the same screen location even while the camera moves through the scene.

This is useful for:

  • Labels

  • Equations

  • Explanatory text

  • Legends

  • Titles

  • Interface-like annotations


The Lorenz Attractor

Definition

The Lorenz attractor is a three-dimensional dynamical structure associated with the foundations of chaos theory.

It arises from a system of differential equations. In general, a differential equation specifies how a state changes over time. For the Lorenz system, the state has three coordinates:

(x,y,z)(x,y,z)(x,y,z)

The equations determine the time derivatives:

dxdt,dydt,dzdt\frac{dx}{dt}, \qquad \frac{dy}{dt}, \qquad \frac{dz}{dt}dtdx​,dtdy​,dtdz​

For any current state and time, the system provides deterministic rules for the state’s instantaneous change.

The Lorenz equations are commonly written as:

dxdt=σ(y−x)\frac{dx}{dt} = \sigma(y-x)dtdx​=σ(y−x)
dydt=x(ρ−z)−y\frac{dy}{dt} = x(\rho-z)-ydtdy​=x(ρ−z)−y
dzdt=xy−βz\frac{dz}{dt} = xy-\beta zdtdz​=xy−βz

Here:

  • σ\sigmaσ, ρ\rhoρ, and β\betaβ are parameters.

  • The parameters influence the shape and behavior of the resulting trajectories.

  • Certain parameter choices produce the familiar butterfly-like attractor.


Initial Conditions

An initial condition specifies the starting point of a trajectory.

For example:

(x0,y0,z0)(x_0,y_0,z_0)(x0​,y0​,z0​)

The differential equation solver uses the initial condition and the Lorenz system to determine how the state evolves.

A starting state of:

(0,0,0)(0,0,0)(0,0,0)

is uninformative for the standard Lorenz system because the derivatives remain zero. The trajectory therefore stays at the origin.

A nonzero initial condition, such as one with a small displacement in the zzz-coordinate, produces a nontrivial trajectory.


Numerical Solution

The Lorenz equations generally cannot be solved in a simple closed form for the trajectory of interest. Instead, a numerical ordinary differential equation solver approximates the solution.

A typical computational process is:

  1. Define the differential equation as a Python function.

  2. Provide the current time and state.

  3. Return the derivatives of the state.

  4. Provide an initial condition.

  5. Specify the time interval.

  6. Use a numerical ODE solver to approximate the trajectory.

  7. Extract the resulting time and coordinate values.

  8. Convert the points into a Manim curve.

Scientific Python libraries such as SciPy provide numerical integration tools for solving initial-value problems.

A solver typically returns:

  • Time values

  • xxx-coordinates

  • yyy-coordinates

  • zzz-coordinates

A small wrapper around the solver can simplify the data format. Such a wrapper may:

  • Present the result as a sequence of states

  • Hide library-specific naming conventions

  • Transpose arrays into a more convenient orientation

  • Make the output easier to use with Manim

The purpose of the wrapper is not to change the mathematics. It provides a more convenient interface between the numerical solver and the animation code.


Converting Numerical Data into a Curve

The numerical solver produces a sequence of points. Manim can interpret these points as the vertices or corners of a polygonal approximation to the trajectory.

The general process is:

  1. Obtain an array of states.

  2. Separate the coordinate values.

  3. Convert the coordinates into Manim’s coordinate system.

  4. Use the points to define a curve.

  5. Render the curve as a vectorized object.

The points must be mapped to the coordinate system used by the displayed axes. Numerical coordinates and screen coordinates are not automatically identical.

For example, the axes may define a displayed coordinate range that differs from Manim’s internal scene coordinates. A coordinate conversion function maps a mathematical point to its correct visual location.


Coordinate Conversion

Suppose the numerical solution provides a point:

(x,y,z)(x,y,z)(x,y,z)

The axes object converts this mathematical point into the corresponding point in the scene.

This allows:

  • Correct scaling

  • Correct placement

  • Alignment with axis labels

  • Consistent interpretation of coordinates

  • Accurate display of three-dimensional trajectories

Without coordinate conversion, the points may appear in the wrong location or outside the visible region.

Python Argument Unpacking

Python can unpack an iterable using an asterisk. If a point is stored as a tuple such as:

(1, 2, 3)

and a function expects three separate arguments, the tuple can be unpacked so that the function receives:

1, 2, 3

This is useful when passing stored coordinate data into a function that expects separate xxx, yyy, and zzz arguments.


Chaos and Sensitive Dependence on Initial Conditions

Nearby Starting Points

A key feature of the Lorenz system is that trajectories beginning from very similar initial conditions initially remain close.

Suppose two starting points differ by only a small amount:

x1(0)≈x2(0)\mathbf{x}_1(0) \approx \mathbf{x}_2(0)x1​(0)≈x2​(0)

At first, their trajectories may look nearly identical. However, after sufficient time, they can diverge dramatically:

x1(t)≉x2(t)\mathbf{x}_1(t) \not\approx \mathbf{x}_2(t)x1​(t)≈x2​(t)

This behavior is called sensitive dependence on initial conditions.

It is one of the defining features of chaotic systems.


Deterministic but Unpredictable

The Lorenz system is deterministic: the rules governing its evolution are fixed and do not involve random choices.

Nevertheless, long-term prediction becomes difficult because tiny differences in initial conditions grow over time. In practice:

  • The system follows definite rules.

  • The rules can be known exactly.

  • The starting state can only be measured with limited precision.

  • Small measurement differences eventually produce noticeably different outcomes.

This creates the apparent contradiction at the heart of chaos:

Chaotic systems are deterministic but can be difficult to predict over long time intervals.

The divergence of nearby trajectories is not caused by randomness. It is caused by the structure of the dynamical system.


The Strange Attractor

A conventional dynamical system might:

  • Approach a single stable point

  • Grow without bound

  • Approach a repeating cycle

The Lorenz system instead approaches a strange attractor.

A strange attractor has the following properties:

  • Trajectories are drawn toward a particular region of state space.

  • The region is not a single point.

  • The behavior is not a simple repeating cycle.

  • The geometry has a fractal-like structure.

  • Nearby trajectories can separate even while remaining within the same overall shape.

The Lorenz attractor is therefore both:

  • Constrained: trajectories remain near a particular subset of three-dimensional space.

  • Unpredictable in detail: the exact location on that subset becomes difficult to forecast.

The attractor explains why many different starting conditions eventually produce trajectories occupying a similar overall shape.


Visualizing Divergence

A clear animation can illustrate chaos by:

  1. Choosing several initial conditions.

  2. Making the initial conditions almost identical.

  3. Integrating the Lorenz equations for each one.

  4. Drawing all trajectories simultaneously.

  5. Assigning different colors to the trajectories.

  6. Adding dots at the current endpoints.

  7. Allowing the trajectories to evolve over time.

  8. Showing the eventual separation.

Initially, the curves overlap and may appear to be a single path. As time passes, they separate. Eventually, they occupy different regions of the attractor.

The number of starting conditions can be increased from two to ten or more. A gradient of related colors can help distinguish trajectories without producing an overly distracting image.


Epsilon and Divergence Time

The initial conditions can be separated by a small quantity ε\varepsilonε.

For example, the zzz-coordinate of successive initial conditions might differ by:

ε=11000\varepsilon = \frac{1}{1000}ε=10001​

or by an even smaller value such as:

ε=1100000\varepsilon = \frac{1}{100000}ε=1000001​

A smaller ε\varepsilonε generally causes the trajectories to remain visually close for longer before divergence becomes obvious. However, the chaotic dynamics eventually amplify the small difference.

This provides a visual demonstration of sensitivity:

  • Larger initial separation produces earlier visible divergence.

  • Smaller initial separation delays visible divergence.

  • Even extremely small differences can eventually become significant.


Dynamic Objects and Updaters

Endpoint Dots

To make the evolution of trajectories easier to follow, a dot can be placed at the endpoint of each curve.

The dot should move as the curve is drawn. An updater function accomplishes this.

An updater is a function that is repeatedly called during the animation. At each frame, it can:

  1. Inspect the current state of an object.

  2. Compute a new position or appearance.

  3. Apply the update.

  4. Repeat on the next frame.

For a trajectory endpoint, the updater moves the dot to the last point of the corresponding curve.

Conceptually:

def update_dot(dot):
    dot.move_to(curve.get_end())

The updater allows the dot to track the evolving curve automatically.


Matching Dots and Curves

When multiple trajectories are displayed, each dot should correspond to its own curve.

The animation must therefore keep parallel collections of:

  • Curves

  • Dots

  • Initial conditions

  • Colors

The corresponding elements can be processed together using Python’s zip operation.

For example:

  • The first curve is paired with the first dot.

  • The second curve is paired with the second dot.

  • Each curve and dot receives the same color.

If two lists have different lengths, zip stops when the shorter list is exhausted. This behavior prevents an error but may silently omit unmatched elements. Therefore, the lengths of related lists should be managed carefully.


Color Gradients

A color gradient can generate a collection of colors between two endpoints.

If there are nnn initial conditions, the gradient should produce exactly nnn colors. This ensures that every trajectory and endpoint dot receives a color.

A gradient can be used to:

  • Distinguish multiple trajectories

  • Preserve visual consistency

  • Avoid assigning every curve the same color

  • Create an ordered visual relationship among trajectories

Color choice must account for both aesthetics and accessibility. Strongly contrasting colors make curves easier to distinguish, while similar shades may produce a cleaner appearance but can be harder to separate visually.


Glow Dots

A glow dot is a specialized point-like object with a luminous appearance.

It is useful for:

  • Marking a moving endpoint

  • Showing a particle or state

  • Drawing attention to a location

  • Making a moving point visually prominent

A glow dot may have parameters controlling:

  • Position

  • Color

  • Radius

  • Brightness or ambient glow

Because glow dots are not necessarily vectorized objects, they may be rendered differently from curves and other vectorized shapes.


Trails and Fading Effects

Fading Curves

Once the curves have shown how trajectories diverge, they can be faded out while the endpoint dots remain visible.

A fade-out animation gradually reduces the opacity of an object until it becomes invisible.

This creates a useful visual sequence:

  1. Trajectories are drawn.

  2. Endpoint dots follow the trajectories.

  3. The curves fade away.

  4. The dots remain, showing where the trajectories ended.

The fade-out can share the same runtime as the dynamical evolution. This synchronizes the visual effect with the mathematical process.


Tracing Tails

A tracing tail follows a moving object and displays a fading segment behind it.

A tracing tail typically:

  • Tracks the recent path of an object

  • Shows only a limited time window of the path

  • Fades toward the back

  • Gradually decreases in opacity and stroke width

If the tail follows the previous three seconds of motion, points older than three seconds disappear from the tail.

Tracing tails are effective for showing motion without leaving the entire historical trajectory permanently visible.

Multiple Tails

A group of tails can be created, one for each moving dot.

The tails can be assigned the same colors as their corresponding dots. This makes it easier to identify which trajectory each tail belongs to.

With ten nearby initial conditions:

  • The tails initially overlap.

  • The group moves as a coherent cluster.

  • The tails gradually spread apart.

  • The divergence becomes visually apparent.

  • The attractor’s structure remains visible through the collective motion.

A smaller initial separation delays this spreading and makes the eventual divergence more striking.


Layering, Opacity, and Depth

Rendering Order

Objects are generally rendered in the order in which they are added to the scene. Later objects can therefore appear in front of earlier objects.

This is useful for ensuring that:

  • Equations remain visible

  • Labels appear above graphs

  • Highlighted elements are not obscured

  • Decorative strokes surround an object

  • Important annotations remain readable

Objects can also be given explicit depth behavior in a three-dimensional scene.


Depth Testing

Three-dimensional objects may use a depth test, which determines visibility based on their spatial position relative to the camera.

Depth testing is appropriate for objects that genuinely occupy three-dimensional space. However, objects fixed to the camera frame or placed on a two-dimensional overlay may need different treatment.

An equation positioned on the xyxyxy-plane in a three-dimensional scene can behave ambiguously because it has a spatial position but may be intended as a flat overlay. Fixing it to the frame or controlling its rendering order can ensure that it appears correctly.


Mathematical Text and LaTeX

Rendering Equations

Manim can create mathematical text from LaTeX expressions.

A LaTeX object can be:

  • Added immediately

  • Written onto the screen

  • Transformed

  • Colored

  • Moved

  • Grouped

  • Positioned relative to the camera

  • Decomposed into mathematical symbols

A LaTeX renderer converts the expression into a structured mathematical graphic rather than treating it as ordinary text.


Fixed Equations in 3D Scenes

When a three-dimensional camera moves, an equation may move with the mathematical scene unless it is fixed in the camera frame.

A fixed-in-frame equation remains attached to the screen. It can be placed in a corner while the camera rotates around the three-dimensional object.

This is useful when the equation explains the system being visualized and should remain readable throughout the animation.


Coloring Mathematical Components

Individual components of a LaTeX expression can often be selected and colored.

For example, the animator may specify that:

  • Every occurrence of xxx is red.

  • Every occurrence of yyy is green.

  • Every occurrence of zzz is blue.

Coloring variables consistently helps viewers connect the equation to the corresponding coordinates, axes, or curves.

The effectiveness of this process depends on how well Manim can dissect the rendered mathematical expression into its symbolic components.


Isolating Symbols and Subexpressions

Manim can attempt to identify individual mathematical symbols automatically, but more complicated expressions may require explicit instructions.

If the animator knows that a particular variable or term will need independent control, it is useful to mark or isolate it during construction.

Explicit isolation allows the animator to:

  • Shift one variable

  • Color a specific term

  • Highlight a component

  • Transform a subexpression

  • Apply an animation only to selected symbols

For simpler expressions, automatic matching often works without additional instructions. For complex expressions, explicit grouping improves reliability.


Matching Text During Transformations

Manim can perform transformations that match corresponding text or mathematical symbols.

When transforming one equation into another, matching components can remain visually connected. For example:

  • An a2a^2a2 term can transform into another a2a^2a2 term.

  • A b2b^2b2 term can move to its corresponding location.

  • Common symbols can be preserved during algebraic rearrangement.

This produces an animation that communicates equivalence more clearly than simply replacing one equation with another.

The same matching principle can be used for text rearrangements and anagrams. Characters can move toward their corresponding positions automatically, allowing a one-line implementation of a visually meaningful rearrangement.


Highlighting Components

Manim includes effects for drawing attention to specific parts of an expression.

Examples include:

  • Flash around: briefly draws attention around a selected symbol or term.

  • Indicate: emphasizes a selected component through a visual cue.

  • Transform a subexpression: changes only a selected portion of an equation.

These effects support explanations in which a mathematical argument proceeds one component at a time.


Interactive Development and Python Scope

Interactive Scope Problems

Interactive execution environments may handle variable scope differently from a standard Python script.

Consider a function that uses a variable defined outside the function:

x = 3

def f(y):
    return x + y

In an ordinary Python script, f(10) returns 131313 because the function can access the surrounding variable xxx.

An embedded interactive environment may fail to find xxx if the function is defined within a special execution context. This can produce a NameError, even though the same code works normally in a script.


Global and Local Variables

A temporary workaround is to copy local variables into the global namespace. In Python, dictionaries of global and local variables can be accessed programmatically.

However, converting all local variables into global variables is generally poor practice because it:

  • Creates hidden dependencies

  • Makes variable ownership unclear

  • Increases the possibility of name collisions

  • Makes code harder to test

  • Can produce unpredictable behavior in larger programs

It may be acceptable in a temporary interactive scene-development environment, where the purpose is rapid experimentation rather than designing a reusable software library.


Better Practice: Explicit Arguments

A more reliable solution is to pass required variables explicitly into functions.

Instead of relying on an external variable, write the function so that the dependency is visible:

def f(y, x=3):
    return x + y

This approach:

  • Makes dependencies explicit

  • Works consistently in normal and interactive Python

  • Improves readability

  • Reduces scope-related bugs

  • Makes functions easier to reuse

The same principle applies to updater functions, list constructors, lambda expressions, and animation helpers.

Best practice: If a function needs a variable, make that variable an explicit argument whenever practical.


Manim Objects and Vectorization

Vectorized Mobjects

Many Manim objects are vectorized mobjects. Their shapes are represented through geometric point data, including information about:

  • Curves

  • Corners

  • Stroke thickness

  • Fill

  • Opacity

  • Position

  • Transformable geometry

Vectorized objects can be transformed and rendered efficiently.

Examples include:

  • Curves

  • Text outlines

  • Geometric shapes

  • Mathematical diagrams

  • LaTeX-derived objects

Manim can use specialized rendering strategies when it knows that an object is vectorized. This can improve performance.


Other Object Types

Not every object is vectorized. A glow dot, for example, may be represented more like a point with visual parameters than like a complete vector path.

Different object types may therefore have different:

  • Rendering methods

  • Available attributes

  • Performance characteristics

  • Transformation behavior

Understanding the object type helps explain why some objects are manipulated through points while others are updated through position, radius, or glow properties.


Rendering a Finished Scene

Command-Line Rendering

Once a scene is complete, it can be rendered from the command line.

The general command includes:

  1. The Manim command

  2. The Python file containing the scene

  3. The name of the scene to render

  4. Optional rendering parameters

A file may contain several scenes, so the scene name identifies which one should be rendered.

The finished output is typically an MP4 file.


Pre-Rendering

A pre-rendering or dry-run mode can execute the scene without producing the full animation.

It can be used to:

  • Estimate the total runtime

  • Detect errors before rendering

  • Check whether the scene executes successfully

  • Avoid discovering a problem halfway through an expensive render

This is especially useful for high-resolution output, where rendering may take significant time.


Output Options

Rendering options may control:

  • Whether the output is written to a file

  • Whether the resulting file is opened automatically

  • Whether a preview is displayed

  • Resolution and quality

  • Frame rate

  • Start and end points

  • Particular sections of a scene

A finished Manim scene is rendered into a video file that can then be imported into a conventional video editor for further editing.


Iteration Costs

The traditional workflow is:

  1. Edit the Python scene.

  2. Run Manim from the command line.

  3. Render an MP4 file.

  4. Open or preview the file.

  5. Inspect the result.

  6. Return to the code.

  7. Repeat.

This approach can be slow when every small change requires rendering the whole scene.

Interactive OpenGL-based workflows reduce this cost by allowing the animator to:

  • Highlight a piece of code

  • Execute that piece immediately

  • See the visual result

  • Continue editing without repeatedly rendering complete video files

This is a major change in workflow because the scene becomes directly inspectable during construction.


Performance and OpenGL

Manim’s development has included changes to its rendering implementation, including OpenGL-based interactive rendering.

Benefits include:

  • Faster visual feedback

  • More interactive scene manipulation

  • Reduced need to render complete MP4 files

  • Better support for exploratory development

  • A more immediate connection between source code and visual output

The interactive approach does not eliminate final rendering. Instead, it improves development and experimentation. Once the scene is satisfactory, it can still be rendered at high quality, including resolutions such as 4K4\text{K}4K.


Reusable Animation Functions

Many common effects are implemented as reusable animation functions. Examples include:

  • Writing an object

  • Transforming one object into another

  • Fading an object out

  • Highlighting a component

  • Moving a camera

  • Creating a glow dot

  • Creating a tracing tail

  • Indicating a mathematical term

  • Flashing around a selected object

These functions act as building blocks. A custom animation library becomes powerful when frequently needed visual operations are encoded once and reused across many scenes.

The library’s usefulness therefore comes not only from its ability to render shapes, but also from its collection of high-level operations that express common explanatory goals.


Example-Driven Learning

Manim’s available functionality can be learned through:

  • Example scenes

  • Existing animation code

  • Library source files

  • Animation categories

  • Auto-completion tools

  • Interactive experimentation

Example scenes are valuable because they show complete working patterns rather than isolated function definitions.

A learner can study:

  • How objects are constructed

  • How groups are organized

  • How animations are sequenced

  • How camera movement is implemented

  • How equations are decomposed

  • How updaters track moving objects

  • How colors and styles are applied

  • How scenes are rendered

Looking through the animation portion of the library reveals the types of built-in effects available.

Text editors may also provide auto-completion through language-server tools. These can suggest function names and inspect the coding environment.

AI-assisted code completion can be useful when learning an unfamiliar library, but it may not understand the animator’s precise visual intention. Directly expressing the desired operation in code is often more effective once the user understands the library’s conventions.


General Manim Production Workflow

A complete workflow can be organized as follows:

  1. Choose the mathematical idea.

  2. Represent the idea in Python.

  3. Create a Manim scene class.

  4. Place the scene’s construction code in construct.

  5. Create mathematical objects.

  6. Add objects or animate their introduction.

  7. Use transformations to show relationships.

  8. Use interactive execution to test small sections.

  9. Use checkpoints when working in the middle of a long scene.

  10. Adjust positions, colors, timing, and rate functions.

  11. Use camera movement for three-dimensional content.

  12. Attach explanatory equations or labels to the camera frame when necessary.

  13. Run a pre-render to detect errors and estimate duration.

  14. Render the completed scene to an MP4 file.

  15. Import the rendered video into a video editor for final assembly.

The most important feature of this workflow is the close relationship between code and visual output. Every mathematical object, transformation, and timing decision can be adjusted directly in the source code.


Key Takeaways

Manim is a Python-based system for creating mathematical animations through programmable objects and transformations.

A scene is a Python class whose construct method contains the code that creates and animates its contents.

The interactive workflow allows individual code sections to be tested immediately, reducing the cost of experimentation.

Rate functions control motion timing: smooth functions improve visual polish, while linear functions preserve mathematical time relationships.

The Lorenz attractor demonstrates chaos through deterministic evolution, sensitive dependence on initial conditions, and convergence toward a strange fractal-like attractor.

Updaters allow objects such as dots and tails to respond continuously to changing scene data.

Manim’s hierarchical mathematical objects make it possible to manipulate entire expressions, individual terms, or individual symbols.

A finished scene can be pre-rendered for error checking and then rendered into an MP4 file for final editing.

Ask anything

We've read this whole study set, so questions about it get the best answers.

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent