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

Speaker 1Speaker 2

3Blue1Brown Manim Animation Overview

14:41
0:00-14:41
  1. Maria

    The most common question about 3Blue1Brown is, “What do you use to animate the videos?” The short answer is Manim, a custom Python library I wrote. It is programmatic and highly bespoke, meaning the visuals are created through code designed specifically for mathematical explanations.

  2. Corey

    And this episode is a behind-the-scenes look at both what Manim is and how you use it. You recorded the conversation with Ben Sparks, whom many viewers know from Numberphile, and after a simple Hello World example, you move on to the Lorenz attractor.

  3. Maria

    Right. The Lorenz attractor is a striking object from the early history of chaos theory, so it is a fun example for showing how Manim handles mathematics, animation, and three-dimensional scenes. But first, there is an important distinction: there are two versions of Manim.

  4. Corey

    The original version grew alongside the channel, correct?

  5. Maria

    Yes. While finishing my undergraduate degree, I wanted a coding project that would help me illustrate mathematical functions as transformations. I made a very rough piece of Python code, used it for the first video on the channel, and then kept improving the tool as I made more videos. The improvement and the video-making fed into each other.

  6. Corey

    So visual techniques that would have been difficult a few years earlier became much easier as the workflow improved.

  7. Maria

    Exactly. The holograms video is an example of that. The visuals would have been dramatically harder to create two or three years earlier, but after years of improvements, making them became much more enjoyable. I have also posted the code for the videos openly on GitHub, and Manim itself is open source.

  8. Corey

    But the original project was not managed as a fully attentive open-source project.

  9. Maria

    That is right. I did not have the time or the temperament to manage issues, pull requests, testing, and documentation while also making videos. A community of users forked the repository and created the Manim Community version, which is more attentive to issues and pull requests and has better testing and documentation. That community version is generally recommended for people who are starting.

  10. Corey

    And the demonstration uses your personal version, which has continued to receive developments such as greater interactivity and better performance.

  11. Maria

    Yes. The two versions are related, but viewers should know which one they are using. The community version is the better-documented and better-tested choice, while I often demonstrate my own version because it contains developments from my personal workflow.

  12. Corey

    Let us start with Hello World. What does the basic Manim code look like?

  13. Maria

    Everything is written in Python. A scene is represented as a Python class, and the code that renders the scene lives inside a method called construct. In that method, you can create objects such as a circle, a square, or text, and then add those objects to the scene.

  14. Corey

    So an object can exist in the code without appearing in the output until you add it to the scene?

  15. Maria

    Exactly. Most objects default to appearing at the center. If I add a square, it appears there. I can then move it by calling an operation such as square.shift to the right, or I can position it relative to an edge, such as the top edge.

  16. Corey

    The demonstration also includes a Python terminal that communicates with the scene.

  17. Maria

    That interactive terminal is extremely useful. It is a Python entry box, so it can evaluate ordinary Python, such as one plus two, but it can also issue commands to the current scene. For example, calling square.shift to the right immediately changes the square, and calling it again shifts it farther.

  18. Corey

    And instead of manually copying a line into the terminal every time, you use a keyboard shortcut.

  19. Maria

    Yes. The shortcut copies the selected text from the editor and runs it in the terminal, giving an immediate visual check. My particular shortcut is tied to Sublime Text and its terminal extension, but the general idea can be adapted to other text editors.

  20. Corey

    That must matter even more for a long scene, such as a four-and-a-half-minute video.

  21. Maria

    It does. A long scene can contain a very large amount of Python, but keeping the code together means local variables and the scene's context are available throughout. When I am working in the middle of such a scene, I want to test only the small section I am editing rather than rerun everything from the beginning.

  22. Corey

    How does Manim let you do that without losing the earlier state?

  23. Maria

    A feature called checkpoint paste can recognize a comment associated with a saved scene state. When I paste a section, Manim restores the scene to the state at the beginning of that section and then runs the selected code. This makes a single Python file behave somewhat like a Jupyter notebook, while preserving the advantages of keeping the scene in one text file.

  24. Corey

    What does a basic animation look like?

  25. Maria

    Instead of simply adding an object, I can use the play method and give it an animation. For example, I can create text saying “Hello World” and play the built-in Write animation, which makes the text appear as though it is being written. A runtime parameter controls how long that animation takes.

  26. Corey

    One of Manim's distinctive ideas is that anything can transform into anything.

  27. Maria

    That is a central design philosophy. For example, I can extract the H from the text and transform that character into a circle. The circle may have been defined earlier but never added to the scene; the transformation uses its geometry as the destination for the H.

  28. Corey

    And the objects have a hierarchy. Text is a group of characters, and a character can contain geometric point data.

  29. Maria

    Yes. You can work with the group of characters, select the first character in the Python list, or access the underlying points that describe its geometry. That gives precise control over what is transforming.

  30. Corey

    The transformation also looks smooth rather than simply linear.

  31. Maria

    By default, Manim uses a smooth rate function, which eases the animation so it does not begin and end abruptly. If I use a linear rate function instead, the motion has a jerky start and stop, but sometimes that is exactly what a mathematical animation needs. The important point is that the framework makes it easy to choose between a visually polished motion and a motion that accurately represents a changing system.

  32. Corey

    That brings us to the Lorenz attractor. What is the mathematical object being animated?

  33. Maria

    The Lorenz attractor comes from a system of differential equations in three dimensions. Given a point with X, Y, and Z coordinates, deterministic rules specify how that point changes at each moment. When you try the system with different starting conditions, the resulting behavior is surprisingly complex.

  34. Corey

    Although the familiar visualization appears on a two-dimensional screen, the underlying points are three-dimensional.

  35. Maria

    Correct. Manim scenes are often two-dimensional because a blackboard-like view is usually best pedagogically. Objects normally lie in the X-Y plane. But when three dimensions are genuinely needed, as with the Lorenz attractor, you can create three-dimensional axes and view the scene through a camera.

  36. Corey

    How did you obtain the numerical solution to the equations?

  37. Maria

    I used ChatGPT to help write a Python function based on SciPy's integration tools. The function describes the Lorenz differential equations and uses a numerical ordinary differential equation solver to find how an initial state evolves over time. I then added a small wrapper so I could think in terms of states and points rather than the solver's particular output format.

  38. Corey

    Why is an initial condition of zero, zero, zero not useful here?

  39. Maria

    For the chosen system, that initial condition produces points that remain zero, so it does not reveal the interesting behavior. Changing the initial condition, for example to include a nonzero coordinate, produces a collection of meaningful points. Manim can then interpret those points and draw a curve through them.

  40. Corey

    How do you connect the numerical coordinates to the Manim axes?

  41. Maria

    The solver gives the points in its own coordinate data, so I use the axes' coordinate-to-point operation to convert them into Manim's scene coordinates. Then I set the curve's points as corners, effectively drawing lines through the sequence of numerical points. Without that conversion, the curve would not necessarily appear in the intended coordinate system.

  42. Corey

    And rather than showing the entire curve instantly, you animate its creation.

  43. Maria

    Yes. The ShowCreation animation draws the curve gradually. Usually smoothing is attractive, but here it would alter the apparent timing of the dynamical system. Using a linear rate function makes the curve appear according to the actual evolution of the sampled solution. I can also change the stroke color and width, or use a color range, although a gradient can sometimes look less clean.

  44. Corey

    The more revealing experiment uses several starting points that are almost identical.

  45. Maria

    Exactly. I create multiple initial states by changing one coordinate by a very small epsilon, then solve the system for each one. The resulting curves start together because the initial conditions are so close, but eventually they diverge and behave as though they are following completely different paths.

  46. Corey

    That is the chaotic feature: tiny differences in starting conditions eventually lead to very different behavior.

  47. Maria

    Yes, but the Lorenz system has another surprising feature. Even though the individual trajectories become difficult to predict, they are drawn toward the same strange attractor. In ordinary differential equations, a system might approach a point, grow toward infinity, or approach a cycle. Here, the trajectories approach a more complicated shape with a fractal nature.

  48. Corey

    So the system is both unpredictable in detail and constrained in its overall shape.

  49. Maria

    That combination is part of what makes chaos difficult to explain: the behavior is unpredictable, yet it remains on a particular subset of three-dimensional space. Ten starting points that begin very close can eventually spread across different parts of that same attractor.

  50. Corey

    How do the moving dots and trails work?

  51. Maria

    I create a dot for each curve and give it an updater function. On every iteration, the updater moves a dot to the endpoint of its corresponding curve, so the dots track the evolving solutions. A group can hold all the dots, and a color gradient can assign matching colors to the curves and dots.

  52. Corey

    You also discussed a Python detail involving zip and the star operator.

  53. Maria

    The zip function pairs corresponding elements from two lists, such as states and colors, so they can be processed together. It stops when one list runs out, which is why I make the number of colors match the number of states. The star operator unpacks an iterable, such as a tuple or array, into separate arguments when a function expects them individually.

  54. Corey

    And there was a particularly cursed global-update line.

  55. Maria

    That line worked around a scope problem in the embedded IPython environment used for the interactive Manim session. A function or list construction could fail to see variables defined outside it, even though the same code worked in a normal Python script. The workaround made local variables global, but it is not something you would want in a serious library. The cleaner approach is to pass needed variables explicitly as function arguments, sometimes with defaults.

  56. Corey

    The camera movement is another reason the interactive workflow is useful, especially in three dimensions.

  57. Maria

    Yes. A keyboard shortcut can save the camera's current position, and the camera frame can then be animated toward that position. Over the course of the animation, the camera slowly pans or rotates, keeping the three-dimensional structure visible on a two-dimensional screen. The runtime of the play call can apply to all the animations inside it.

  58. Corey

    The final effect uses fading curves and tracing tails.

  59. Maria

    Fading out the curves gradually changes their opacity to zero, leaving the endpoint dots visible. A tracing tail follows a moving object and fades behind it, with parameters controlling how much history remains. Creating one tail for each dot and matching its color produces a smooth visual showing how the trajectories separate over time.

  60. Corey

    You can also change the evolution time and epsilon to control what the viewer sees.

  61. Maria

    Right. Making the evolution last longer gives more time for divergence to become visible. Making epsilon smaller means the initial conditions are even closer, so the trajectories remain together longer before their chaotic separation becomes obvious.

  62. Corey

    Once the scene looks right interactively, how does it become a video?

  63. Maria

    Normally, Manim can be called from the command line with a Python file and the name of the scene to render. Options can pre-run the scene to estimate its duration and catch errors before rendering, write the result to a file, and open the output in the file system. The result is an MP4 file, which can then be brought into Final Cut for editing.

  64. Corey

    That is different from the interactive iteration cycle.

  65. Maria

    Very different. The older workflow involved changing code, rendering an MP4, and then opening it to inspect the result. There were shortcuts for rendering only part of a scene, but it was still slower. The interactive shell changes the process into highlighting code and immediately seeing what it does, which is a fundamental improvement.

  66. Corey

    Manim also handles mathematical text through LaTeX.

  67. Maria

    You can create a LaTeX object from an expression and add it to the scene. In a three-dimensional scene, you can fix the object to the camera frame so it stays like an overlay, then place it in a corner. You can also separate symbols such as X, Y, and Z and color or move them individually, although more complicated expressions require Manim to know how many symbols it should isolate.

  68. Corey

    And transformations can match corresponding mathematical symbols rather than treating an equation as an undifferentiated image.

  69. Maria

    Exactly. Manim has transformations that match the underlying strings, so an A squared can move to the corresponding A squared in a new equation, and the B squared can do the same. There are also effects such as FlashAround and Indicate for drawing attention to a particular part of an expression. For simpler expressions, Manim can often identify the pieces automatically.

  70. Corey

    What resources are available for someone who wants to learn the available functions?

  71. Maria

    The Manim Community version has substantially better documentation. In the original version, you can inspect the animation folder to see the available animation types, and the example scenes provide working demonstrations. The code for the videos is also available in the 3Blue1Brown videos repository on GitHub, so studying those scenes gives a sense of what Manim can do.

  72. Corey

    Text editors can help too, through autocomplete or language-server tools.

  73. Maria

    Yes. Tools connected to the editor can provide autocomplete, and systems such as GitHub Copilot may help when learning a new library. But my own preference is often for simpler autocomplete, because when I know Manim well, I tend to express what I want directly in code rather than describe it in English.

  74. Corey

    So the full workflow is: write a scene in Python, create and add mathematical objects, use play and transformation methods to animate them, iterate interactively, and finally render the finished scene to an MP4.

  75. Maria

    That is the essence. Manim combines ordinary Python, mathematical data, a library of visual objects and animations, and an interactive development process. The original version evolved from the needs of one video maker, while the community version makes the tool more robust and approachable for other users.

  76. Corey

    And the Lorenz attractor shows why the approach is powerful: numerical solutions can become curves, curves can become animations, and small changes in code can immediately change the visual explanation.

  77. Maria

    Exactly. The goal is not just to make something move, but to make mathematical structure visible and controllable. That is why programmatic animation, transformations between arbitrary objects, careful timing, camera control, and an efficient workflow are all central to how these videos are made.

Ask anything

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

FlashcardsQuizFill in the blanksWritten testLessonNotesPodcastContent