Yellow marks are automatic key passages. They aren’t personal saved highlights. Select a timestamp to follow along with the video.
3Blue1Brown's videos are animated with Manim, a custom, fully programmatic Python library that began as a scrappy undergraduate project, grew alongside the channel, and now exists in the creator's own interactive version and a better documented, better tested community fork. Its workflow centers on scenes written as Python classes, a terminal that talks to the running scene, and a checkpoint-paste shortcut that reruns a single section of a long scene, with built-in touches such as the Write animation, free transformation between shapes, and rate functions that control smoothing. A live build of the Lorenz attractor shows the process in practice: a numerical ODE solver, conversion to the axes' coordinates, curves with glowing endpoint dots, ten nearly identical starting conditions that diverge into chaos around a strange attractor, tracing tails, a panning 3D camera, and some Python pitfalls such as zip and a cursed globals workaround. The video closes with rendering to MP4, LaTeX equations with colored and separated parts, example scenes, the open GitHub repository of all video code, and tips on editors, autocomplete and Copilot, with a fuller uncut conversation promised on Patreon.
What 3Blue1Brown uses to animate
The most common question about 3Blue1Brown is what is used to animate the videos. The short answer is a custom Python library called Manim. It is entirely programmatic and very bespoke. This behind-the-scenes look shows what Manim is for those who do not know it, and, even for those who do, how it is used and what the workflow looks like. The walkthrough comes from a conversation with Ben Sparks, recorded in the UK a couple of months earlier. Many viewers will recognize Sparks from his Numberphile videos. He wanted to know how Manim worked, and since a number of other people had the same question, the conversation was recorded. It is a scrappy recording, but it does the job. After a simple hello world example, the conversation animates the famous Lorenz attractor, which is very important in the foundations of chaos and is also just a fun visual to get into.
Two versions of Manim
There are two versions of Manim. The first has a history very intertwined with the history of the channel. The project began as the creator was finishing an undergrad degree. The goal was a coding project that would illustrate mathematical functions better, as transformations. A very scrappy bit of Python code was the result, and it was used to make the first video on the channel. As more videos were made the tool improved, and as the tool improved more videos were made. That loop has continued ever since. The most recent video, about holograms, would have been dramatically harder to make even two or three years earlier. In the creator's own view, the visuals in it were something to be proud of. Over the past month it was also kind of a joy to make, thanks to workflow improvements accumulated over the years.
All of the code behind the videos has always been posted openly on GitHub, and the underlying tool, Manim, was also made open source. The creator, by personality type, does not have the constitution to manage an open source project, and does not have the capacity for it while making videos. Issues and pull requests therefore did not get much attention. A community of people who wanted a more robust tool for others forked the repo and created a version that is attentive to issues and pull requests, with better testing and better documentation. It is called the Manim community version, and it is generally recommended as the place to start. Meanwhile, the creator's own version keeps receiving changes, and over the last couple of years it has become more interactive and more performant. The demo with Ben uses that personal version. Anyone who wants the better documented and tested option is advised to go with the community one.
Hello world: scenes and the interactive terminal
The hello world example is all in Python. On the left is essentially a plain text file, edited in Sublime Text, a text editor. The aim is to get something on screen and then talk through what is going on.
Every scene that gets edited into a video takes the form of a Python class. Inside a method of that class called construct lives all the code that renders things. Objects such as a circle or a square are added in there. Running the code produces the square.
Next to the editor is a Python terminal that can call commands on the scene. Typing square.shift to the right makes the square shift to the right, and calling it again makes more happen. Ordinary Python works there too, such as asking what one plus two is. It is essentially a Python entry box, but one that talks to the scene itself, which is handy while creating a scene.
A common workflow is to decide on a step, such as putting the square at the top edge, then copy the line, go to the terminal, paste it and press enter. That tests the line immediately. Doing this by hand every time is tedious, so a shortcut, tied to Sublime-specific features and bound to Command R, copies the selected text and runs it in the terminal. The shortcut runs the code and outputs the visual, giving an immediate check.
Long scenes and checkpoint paste
More is going on under the hood, and an example from the most recent video on holograms shows it best. These scenes can get quite long. The final output of the example was a four-and-a-half-minute MP4 describing diffraction gratings, in particular the double slit. Long scenes are nice because they share a lot of context, and while coding, that context can be referenced. The code for such a scene ends up as a big pile of Python. It used to be broken down into little subroutines, but historically it has proven nicer to keep everything in one spot, where all the local variables are shared.
The key point is that while working in the middle of such a scene, with lots of code already behind it, it is useful to iterate on just one small section and run only that section's code. In the example, some graphs are being drawn and a red and blue wave fades out a little. Tweaks might include making it not fade out as much, say only to 0.8, or changing the runtime, and then running that same section again.
For this to work, pasting cannot just run the code literally. The scene has to revert to the state it had at the start of the section. That is what a function called checkpoint paste does. If the copied text starts with a certain comment, it checks whether that comment has been seen before and whether a state of the scene was cached with it, so that the section can be run from there. This makes the workflow behave a bit more like a Jupyter notebook. Some viewers may wonder why it is not simply a Jupyter notebook. The preference is to keep the scene in a single text file that can be driven through scripts and similar tools, and this setup is a hybrid between the raw text file and a notebook.
Adding text and the Write animation
Some text that literally says hello world can be put on the screen too, placed at the top. It will not show up unless there is a line adding it, because adding makes an object appear. Most objects default to the center of the screen, and they only move if something like a shift or a move to an edge is applied.
Instead of adding an object, any animation goes through a method called play. Rather than passing in an object, the call says what should be done to that object. Here the text is written, so that it looks like it is being written on, using a function baked into the library. Parameters can be added, for example a longer run time of three seconds. Anyone who has watched Manim videos recognizes that effect immediately. It is ready to go and really useful. The effect was written for the library, and nothing else uses that particular look of the edge coming on and fading in. It is pretty, and it is the signature look of Manim.
Anything can transform into anything
A different philosophy in Manim is that anything can transform into anything. Take the text that has been written. Its H can be extracted and made to turn into a circle. The circle is defined first but not added anywhere, and then the H is transformed into it. When the scene reaches that point, the text gets written, and the line then extracts the H from the text and transforms it into the circle. Because the circle sits in the middle of the screen, the H moves there rather than simply disappearing.
Built-in functions such as write and transform are ones sculpted to make the intended jobs happen, and many other things derive from transform. There is no pedagogical reason for an H to turn into a circle. It looks nice, and it can be slowed down a little.
The transformation does not just jump from one state to the other. It is eased, and various smoothing functions are at work. In the first attempt the H shrinks while the circle grows, which is not the desired look. Extracting the H creates a group of all the H's found in the text. Text has a hierarchy, in which the whole text is a group of characters, so the first element of that group, the zeroth element of the Python list, is the first character. A simpler route is to take the actual points data of that H. Instead of working with the character object, the transform then uses only its geometry.
Rate functions and smoothing
The smoothing of an animation is controlled by an attribute called the rate function. It defaults to a function called smooth, which just looks smooth. It is not quite the classic smoothstep profile, but a cubic Bézier that behaves similarly. With a linear rate function instead, the motion looks a little jerky, and it is easier to see with a run time of one: a jerky start and a jerky stop. Sometimes that is wanted, and sometimes it is not. This comes up again later, where a linear rate is wanted even though the default is smooth.
Why small details matter in animation
It is those small details that make the difference between having made something move and having made something look good. Making that kind of polish easy to achieve is a big part of what the library is for, in the speaker's view.
The Lorenz attractor
A classic piece of recreational mathematics that many people have heard of makes a good test case: the Lorenz attractor, which had never been plotted in Manim before. The Lorenz attractor is a very bizarre shape that came up in the early history of chaos theory. It comes from a set of differential equations in three dimensions. If a point sits somewhere in 3D space, this set of deterministic rules dictates how that point should change at any given moment in time. What happens when the system is run from a variety of starting conditions proves to be very interesting, and it makes good material for animation. A Veritasium video on the topic is probably a good place to learn more. One of the speaker's favorite books, by one of their favorite authors, James Gleick, also describes how the Lorenz system came about and the role it played in early chaos theory.
A 2D rendering glitch and the 3D scene
A rendering bug briefly shows the points as flat, a side effect of recent experiments with the low-level rendering code. The cause is understood, and there is a dumb way to fix it, but it is not worth worrying about here. The scene was always three-dimensional. Everything is simply viewed through a flat camera, so adding 3D axes shows that everything exists by default on the X-Y plane. Ninety-nine scenes out of a hundred are made in 2D, because pedagogically they should feel like a blackboard. Going up to 3D makes sense only when it is really needed, and the Lorenz attractor needs it.
Getting a numerical ODE solver, with help from ChatGPT
The setup for the Lorenz attractor starts with some axes covering the region of interest. The math underneath amounts to feeding software a differential equation and an initial condition and asking how that initial condition evolves. Packages that do this with something smarter already exist, so the starting point was to ask ChatGPT for a Python function that uses a numerical ODE solver to find a solution of the famous Lorenz equations. That is a nice way to get acquainted with a new library, and it solves many of the protocol issues that can otherwise take hours to get past. The answer mentions SciPy's integrate module and its solve_ivp function (solve initial value problem), along with boilerplate that uses Matplotlib to render the result. That is entirely reasonable, but since Manim is the tool here, the code needs adapting.
Defining the system and wrapping the solver
A function describes the differential equation: for a given time and a given state with X, Y and Z coordinates, it returns the derivative of that state. Three parameters, named with Greek letters, can be tuned freely. The Wikipedia page for the Lorenz system lists values that someone has found to make nice diagrams, so those are used. The same page could later supply the equations to render onto the scene. A tiny wrapper around the SciPy solver takes an initial condition and returns all the points of the solution. The solver returns an object called solution containing time values and X, Y and Z values. The library is a little odd, treating Y as the output even though Y may be a vector, which is confusing. That is part of the reason for the wrapper: it allows thinking in terms of states rather than the library's language, and it transposes the matrix into the preferred layout, which is what the T in the code does. The wrapper itself is not important.
Trying initial conditions
With the wrapper in place, the initial condition can be set to 0, 0, 0 at first. The solver takes the Lorenz system function, that initial state and a duration of 10 seconds, and returns a set of points. Printing those points shows only zeros, which is predictable, since the origin is a fixed point and a bad initial condition. Changing the starting values to something like 10 produces interesting points instead of all zeros.
Turning points into a curve
Everything in Manim is a mobject, short for mathematical object. Many are vectorized mobjects, a term that describes how they are rendered, as opposed to a surface or a point cloud. These include curves with a stroke thickness, a fill and so on. To draw lines between the points, the curve is told to set its points as corners, as if it were a polygon, using all the points just created. At first nothing appears on screen. The curve exists, but the points were added without using the coordinate system of the axes, so they are not plotted according to those axes.
Converting to the axes' coordinate system
The fix is to use the axes' coordinates-to-points function, which converts from the axes' coordinate system into Manim's coordinate system. Because it is used so often, it has an abbreviation, c2p (coords to points). It expects a list of X values, a list of Y values and a list of Z values, so the points array needs a little transposing. The result sits in the actual coordinate system of the axes.
Python's asterisk for unpacking
The asterisk in the code unpacks an iterable. Take the tuple (1, 2, 3) and a function that takes x, y and z separately and returns, say, their sum. Calling the function on the tuple directly raises a type error, because the function wants the values separated. Passing each element by index would work, but Python has a bit of syntactic convenience: putting an asterisk in front of an iterable unpacks it into separate arguments. For some viewers that is the most useful thing learned all day.
Why coordinates-to-points takes lists
In this case, points is an array in which each row is one point. The syntax of coordinates-to-points, however, takes lists of X coordinates, Y coordinates and Z coordinates, which is arguably a dumb design. It does make sense, though. Usually the function is called as axes.c2p with individual values, to find which point in Manim's coordinate system corresponds to a given point on the axes. Adding a dot there shows where it appears. A system that works is not a dumb system, even if it can always be improved, and this one works a whole lot better than many systems people try to make.
Animating the curve's creation
Rather than just adding the curve, the system can be shown evolving by animating the creation of the curve, which runs through all the points slowly. Drawn with the default settings, it appears very fast. The runtime should match the actual time of the dynamical system, so the curve is drawn over 10 seconds. By default, though, drawing applies the smoothing function, which changes the behavior. Smoothing is almost always nice, but this is one of those cases where the math being represented matters and needs to be kept rather than masked. Setting the rate function to linear shows the actual evolution of the system.
Styling the curve
The curve can be styled, for example with a blue stroke that is a little thinner. A range of stroke values can even produce a gradient, such as starting blue and ending red, or starting at zero stroke width and ending at 10, or the reverse. Those options look pretty ugly here, and color will be needed for a different reason anyway.
Showing chaos with multiple curves
The system is interesting because it is chaotic. Initial conditions that are really close to each other, but not quite the same, evolve identically for a while and then diverge. To illustrate this, the scene creates multiple curves collected in a group. The group is called a VGroup to signal that its members are vectorized objects, which makes rendering a little faster. Without that information the objects still render, but a certain optimization trick is not used. The next step is to go through a bunch of states, which must be defined now. These are the initial conditions.
Setting up multiple initial conditions
The initial conditions are built by changing the z coordinate by a small amount, an epsilon of 1/1000. A loop over `n in range(...)` generates the states. Two initial conditions are enough to start, and the count can be raised to many more later. A list is slightly redundant for two states, but it generalizes. The states no longer depend on a single `state 0`; each one comes from whichever state the for loop is currently handling.
Coloring the curves and building the group
Everything written so far goes inside the loop, so each state creates its own curve. By default every curve is blue, so a list of colors is added, for now just blue and red because there are only two curves. Eventually a numerical way of generating colors will be needed, one that generalizes. The states and colors are zipped together, so each curve is colored differently. Commenting the code this way is a rarity in animation work, and there is plenty of room for improvement.
The curve-creation animation also changes. The empty group of curves gets each new curve added inside the loop with `curves.add(curve)`. A generator then produces a list of animations, one creation animation per curve. Passing that list with a star into `play` hands the animations over as if they were several separate arguments. With two threads this works, and the count can be raised to 10 later.
Watching the curves diverge
The scene now shows two curves evolving at once. At first only the red one is visible, because it is drawn on top of the blue one. After a while they diverge, but the divergence needs to be easier to see, so the run needs to be longer. The evolution length gets a name, `time`, an overused name that will need care, and is set to 30.
Adding glowing endpoint dots
Small dots marking each curve's endpoint make the divergence easy to follow by eye. A group of glow dots is created, one per color. A glow dot is a built-in object for a point that moves and has a nice bit of coloring. It is not a vectorized object. Its data is a point in space, an amount of ambient glow, and a color.
An updater function keeps the dots in place. It takes the dots as input and is written in place, since keeping everything relevant to the animation in that block is a useful habit. Zipping the dots with the curves, each dot moves to `curve.get_end()`, the last point of its curve. The function is added as an updater on the dots, so it is called on every iteration from then on.
How Python's zip works
The `zip` function stacks two lists in parallel so they can be iterated together. With a list of numbers (1, 2, 3) and a list of letters (a, b, c), `for number, letter in zip(list1, list2): print(number, letter)` pairs them up. Lists that refer to related things can therefore be kept in step implicitly, by position.
The danger of zipping lists of different lengths
Zipping lists of different sizes is unsettling. If one list is much longer, the loop stops as soon as the shorter one runs out. Nothing fails, but many items are silently missing, and the bug is quite hard to find if it goes unspotted. Unless someone is fluent in Python, this behavior is easy to be caught by.
The fix is a color gradient function that goes between two colors in a given number of steps. Setting the steps to the length of the list of states guarantees that the number of colors always matches the number of states.
Noticing discomfort while working
Watching someone work can show when discomfort kicks in. Experience, not necessarily bitter experience, signals when to worry about something and when not to. That discomfort is the cue to deal with an issue before forgetting about it.
The dots now have their updater. Once they are added to the scene, they should track the endpoints of the curves as those change with what has been drawn.
An error from the glow dot constructor
A line follows that anyone who knows Python will recoil at, and it is an annoying necessity. First, an error appears: the argument must be a string or a real number. It points at the line where the points and colors are set. The color gradient output was being passed where glow dot expects its center, the position in space, as its first argument. Glow dot's constructor should have given a better error message, though this is not held against it.
Matching animation time to evolution time
The dots appear, with red on top of blue at first. The curves run too fast because the runtime is now different from the evolution time. The 30-unit solution plays out in 10 seconds. Rerunning shows the system at its intended speed. The curves start off together, very close at the beginning, then separate, and after a little while behave as if they are doing completely different things. This is the classic picture of chaos.
Why the cursed global-update line is needed
The line `globals().update(locals())` is ridiculously cursed. It works around a bug in the IPython embed used for Manim.
A simple example shows the problem. A variable `x` is defined, then a function `f(y)` uses that `x`, and `f(10)` is expected to return 13. Run as an ordinary script from the terminal, it prints 13. Run inside the IPython embed used for Manim, the identical code raises `NameError: name 'x' is not defined`.
The catch-all hack and its limits
Inside an IPython cell like this, a newly defined function apparently does not share the scope it would have in a normal Python environment. The catch-all hack is to make the variable global. Python exposes the dictionary of all global variables, and the hack updates it with the dictionary of all local variables, so everything local becomes global. This would be horrifying in code for a real library. For scrappy use in an interactive session purely for scene development, it is not as dangerous.
The problem does not occur in plain IPython run from the terminal; the same code works fine there without the hack. It seems to come from embedding, which drops into the middle of a scene much like a debugger. A better workaround would be welcome from anyone who knows one.
The better approach: explicit default arguments
A cleaner way exists when a function references a variable it needs. Make the dependency explicit: add `x` as an argument of the function, with a default value equal to the `x` defined in the enclosing scope. Everything then works as intended.
In the scene recorded with Ben, the cursed line exists because a function references `curves`. The better fix is to make `curves` an explicit argument that defaults to the value from the outside, which handles the problem fully.
List constructors and the same bug
This approach can be annoying with lambdas written on the fly, which is one reason the hack became a habit. The same bug also arises with list constructors. Take an expression like `x + y for y in range(10)`. In normal Python, `x` is visible from outside, so running it works as expected. Inside the Manim environment, at least previously, the same bug emerged. On a recent look, however, it seems to be fine. Whatever bug had been there that affected list constructors and
Dropping the cursed line
The bug with list constructors seems to have disappeared, so there is no longer a reason to type that incredibly cursed line, and the last five minutes of debugging can be ignored. Back to finishing the scene with Ben.
Tuning the dots and aesthetics
The dots get a radius of one. Red does not work well as the second color; it looks kind of ugly. A radius of one turns out to be a very big dot, perhaps a little too big, so it is worth easing off. It is a minor point, but the aesthetics are handled by the library: even a big glow dot still looks nice, because care went into making the glow-dot function produce a good-looking dot.
The scene is not interactive in the final product. Everything is ultimately rendered and made into a YouTube video. Occasionally an animation is played with live in the moment, but that is not common.
Panning the camera for 3D depth
A very common move is to have the camera pan slowly through an animation. In 3D rendering on a 2D screen, the illusion created by rotation keeps the depth alive. An undocumented keyboard shortcut saves to the clipboard a call that puts the camera in its current position, which grabs the current camera angle.
In the animation, the camera frame can then be animated with the animate syntax: instead of applying a change directly to the object, the change is animated over time. In this case the animated change is the camera reorienting itself to a certain position, so it slowly pans over from wherever it currently is. When the runtime is passed as an argument of the play method, it becomes the runtime for every animation in that call. The movement may not be enough, so a bigger spin is better, since it happens over 30 seconds.
Smooth motion and color choices
The pan is very slow, but smooth, and a smooth pan is preferable; it might look jerky otherwise. The scene can now be seen from all the different angles. The color scheme is still a little jarring, so the second color changes to teal, something close to the first, and the motion becomes more aggressive.
Color vision deficiency makes the speaker a poor judge of color: yellow and blue can be told apart, as can blue and teal. Colors should either be starkly different so they are easy to see, or aesthetically pleasing, using shade rather than hue to distinguish them. Two different shades of blue would look cleaner but may be harder to discern. For fun, the scene uses ten points that differ only by epsilon in the third coordinate.
The strange attractor
Mathematically, wherever the starting point lies, the trajectory ends up in this same sort of shape. That is the second surprising thing: the point is not just that the system does something strange, but that there is an attractor. With differential equations, trajectories may be attracted to a single point, blow up to infinity, or be attracted to a cycle. A strange attractor is different: all the points are attracted to a certain shape, but that shape is not as simple as a cycle and has a fractal nature.
There is an inherent contradiction in describing chaos. The system is unpredictable, yet at the same time predictable, because of the strange attractor. The trajectory will be on this subset of R3 and will get close to it, but where on that subset it will be is another matter. Ten starting conditions that were very close to each other end up all over the place once the curves are removed and only the dots remain.
Fading the curves
An idea comes up to have the curves fade out over time. The conversation with Ben that follows was made far more complicated than it needed to be, and the two chased down a couple of different bugs. The full, relatively uncut version of that conversation may go up on Patreon, with a much more succinct version of the wrap-up here.
The scene is essentially the same as the one built with Ben: axes setting up a 3D coordinate system, and ten curves. When animated, the curves are drawn and the dots follow. Ben had asked whether the curves could fade out over time. The answer is to use FadeOut on the curves, another animation type that slowly changes them to zero opacity. If the evolution time is passed as the runtime parameter of the play call, it becomes the runtime for everything inside. Over those 10 seconds the curves slowly fade, leaving only the dots, which looks very nice.
Tracing tails
A nice effect is a tail that follows the dots and fades out smoothly. A class called TracingTail, written once for some video long ago, does this. Given a single object, such as the first dot, it adds a tail. Instead of fading out the curves, they are set to invisible by setting their opacity to zero. They are still drawn and still determine where the dots go through the update function called on them, but they are not seen. What shows is one tail for one of the dots, which fades from full opacity to zero opacity and zero stroke width at the back.
Some parameters can be changed. The time traced is the amount of time the tail follows the dot: it starts at one second, and making it three seconds gives a longer tail. Instead of one tail, a group of tails can be created, one for every dot, each matching the color of its dot. The result is ten different tails following for a bit more time, a nice smooth effect, and the spread of the dots shows up cleanly.
Slowing the divergence
More fun comes from letting the scene evolve longer: 30 seconds instead of ten. The starting points can also be brought closer by making epsilon one one-hundred-thousandth instead of one one-thousandth. In theory the ten dots then stay together much longer, and it takes longer before the divergence caused by chaos appears. Indeed it takes a while, but eventually they spread out. That makes a nice end effect.
The goal is achieved: a Lorenz attractor with multiple initial conditions varied very slightly, animating prettily with a glitchy trail. The more uncut version will be posted elsewhere, and this is a good point to move on to other topics.
Rendering to MP4
The last step of the workflow is to bake the finished code into an MP4 file. Once the scene looks right and has been cleaned up a bit, a keyboard shortcut renders it. Normally Manim is called from the command line: after downloading it from GitHub and importing it, the command is manim followed by a Python file that contains the scene, along with the name of the scene to render from that file.
Several flags are available. Pre-run goes through the whole scene without animating, estimates how long rendering will take and catches errors up front rather than halfway through the animation. The Finder option pops the result up in Finder, the macOS file system. W writes the output to a file. Running the command pre-runs the scene, works out how long it will take, then renders it to an MP4. Because rendering is usually done at 4K, it can sometimes take a little longer.
Why the interactive workflow exists
This is one reason for showing the behind-the-scenes process. The way Manim was originally used, and probably how a lot of Manim Community users still use it, is always from the command line: write the scene, run manim on it, and it renders an MP4 file and pops it up, so the whole file has to render first. There were shortcuts, such as rendering only from a certain animation onward, but the iteration cycle is annoying when every update has to be viewed this way. Later on, around the same time the implementation moved to OpenGL, an interactive shell version was added, so that the process of creating just is like, highlight the code
Interactive workflow with a text editor
Highlighting code and immediately seeing what it does is a fundamental change to the workflow, and a huge one. In the presenter's own setup, this depends on Sublime scripts that send a command to Terminus, the Sublime extension that provides a terminal. The process will be documented in the description of the video. Whatever text editor someone uses, including Visual Studio, probably allows something that does the same thing.
Rendering to a video file and adding LaTeX equations
A rendered scene may look glitchy because of the glitches mentioned earlier, but it is now a plain video file playing in a video player. That file can be dropped into Final Cut for editing. One thing not yet covered is equations. A LaTeX object takes some LaTeX and renders it, and the result is added to the scene.
MathPix is a very useful tool for this. It is OCR for LaTeX: a snapshot of any equation yields several outputs, one of which is the LaTeX for that expression, and it can also be exported as an SVG. A bitmap from the screen thus becomes a scalable vector. The equations can then be used in the scene.
Fixing equations in frame and coloring parts of the text
Added equations land in the middle of the screen, on the XY plane. In a 3D scene, an object can be fixed in frame, as if glued to the camera frame, which allows it to sit in a corner instead.
A tex object can be indexed by a string. For example, every X can be colored red, and every Y can be given another color, such as green or blue. A tex-to-color mapping handles this, and the line spacing can be adjusted so the result looks nicer.
Separating mathematical parts of an expression
Once the text is split into parts, the equations can be pulled apart: the Xs can be extracted and shifted slightly upward, for instance. By default the system does its best, but when specific variables need to be separated, it must be known from the tex expression how many symbols there will be, so that the Manim object can be dissected accordingly. Getting this to work can be tricky.
When control over variables is wanted, they can be placed in their own parts of an expression. There is also an option called isolate. Nine times out of ten, the default works for simpler expressions.
Draw order, depth testing and layout
When the scene renders, the equations appear on screen while the rest of the animation runs. Whether they sit behind or in front of the camera is controllable. By default, things are rendered in the order they were added unless a depth test is applied. Many 3D objects that know they are meant to be three-dimensional are depth tested. Here, the equations' actual position is on the XY plane, which makes it a little odd.
To make sure they show up in front, they can be added last. A back stroke can be set to leave a little space around them, and the font size can be reduced to about 30 so that they sit up in the corner. They then overlap less with the solutions, since they are smaller.
Breaking text into mathematical parts
Because everything is updated every frame, breaking text into mathematical parts is extraordinarily useful for highlighting them, and it would be a real pain to do in almost any other context.
Example scenes and matching transforms
A set of example scenes is provided for anyone who wants to get started. One shows what working with tex looks like: a series of expressions that rearrange a certain equation, where each expression is a line of the equation. A special kind of transform tries to match the strings underlying the expressions, so that in the animation the A squared goes to the A squared, the B squared goes to the B squared, and so on.
The examples show the kinds of operations available. Playing around with strings, this matching transform automatically gives a nice anagram animation. There is nothing to think about: each letter simply moves to the corresponding letter, in what is essentially a one-liner. That was an emergent behavior. It is slightly unhelpful for viewers, but a big anagram came up in discussion a couple of days earlier, and it would have saved Simon some effort had it been run through Manim.
Highlighting animations and finding what functions exist
With the famous equation E = mc², a part of it can be referenced on its own. An animation called flash around can flash around just the E, and another called indicate can indicate the pi. Parts are pulled out bit by bit.
As for discovering which functions exist, there is the author's own head, a vast trove of experience built over the time of writing the library. The Manim Community version is a different version, but these functions still exist, and the community version definitely has much better documentation. The original has some documentation, though not much. All the animations can be seen in a folder of the library called animation, and browsing through it shows what exists.
The GitHub repository of all video code
All of the code written for any video is on GitHub, at github.com/3b1b/videos. The repository contains the animation code for past videos and for current ones, although no animation for holograms has been made yet. It also includes puzzles made recently for the IMO. Together this gives a sense of the functionality available.
Autocomplete, language servers and Copilot
For beginners, a question is how to find functions without knowing what is out there. Looking through the library is one answer. Autocomplete is another, and it depends on the text editor. Sublime has a language server protocol, with a plugin called something like Pi LSP, that has some sense of the environment and may autocomplete. That is one way to find a function, and a function that might be named a certain way can be checked for existence.
GitHub Copilot is another option. In the presenter's experience, Copilot works poorly with Manim, because the presenter knows what is wanted and Copilot does not quite know it. It is really nice when engaging with a new library, but simpler, dumber autocomplete tools are what the presenter actually prefers. When the exact need is unclear, the request is easier to articulate in code than in English. To each their own, and trying it is worthwhile, particularly for someone with the experience to fall back on.
Overcoming the barrier to getting started
Workflow and text-editor choices are things many newcomers are not used to, and that lower level is sometimes the barrier to getting started. Once those hurdles are crossed, the question remains of where to start at all. The example scenes give some sense of that.
Closing and what comes next
Seeing the back end was a real pleasure. Coding is a very human experience, and the messiness is part of it. This was a little peek behind the scenes. A link to the repository, where the code for literally any past video can be seen, will be in the description. By the time of posting, the readme of that repository will also outline the actual workflow used here, including the specific Sublime scripts and what to mimic with a different text editor.
The full version of the conversation, warts and all, will be posted to Patreon. Manim live streams may also happen on Patreon periodically; viewers who would be into that are invited to say so, and to say what kinds of things they would like to see. In the meantime, the next video is waiting to be animated.
Turn your watchlist into a reading routine
Bring your YouTube videos together, read summaries with key passages marked, and explore the full transcript. Save your own highlights with Pro.
Start with 5 free batteries. Each covers up to 30 minutes of a new summary.
New summaries depend on video availability and demand; processing may take time or require retry.