manim
pedagogic animations via python
October 8, 2018 — February 6, 2023
Grant Sanderson a.k.a. 3blue1brown’s project manim is a curious passion project to create interactive python plot-compatible animations with mathematics, via code. It is YouTube-famous. Here is a powerful example of what this tool can do. Most importantly, it makes me feel fancy. Here are some notes and links I need while using it.
1 Installation
- I believe the community edition (source) is recommended for newcomers rather than the more idiosyncratic 31b1 version.
- ManimCommunity/manim: A community-maintained Python framework for creating mathematical animations.
Note dependencies:
2 Intros
- Manim Quickstart
- /r/manim the Reddit community is very helpful
3 Tips and tricks
- Moving things to the edge of the screen?
to_edge
- Manim Tutorial on 2D Graphs
- A deep dive into Manim’s internals
- Manim’s Output Settings
- Manim’s building blocks
- There are z_indexes to allow us to include one thing with another.
- A lot of stuff that is badly explained, or unexplained, in the manual is beautifully demonstrated in the Example Gallery
3.1 SVG height is not what it claims
From the documentation, one might get the impression that the SVGMobject width and height parameters set width and height. Wrong; if I use both, they only set the width. If I wanted to set the height, I needed to use the stretch_to_fit_height
method.
def create_person(width=1.5, height=2.6, *_, color=PURPLE):
person = SVGMobject(
"person.svg",
fill_color=color,
width=width, height=height,
).set_z_index(0)
print("requested dims", width, height, "!=actual dims", person.get_width(), person.get_height())
person = person.stretch_to_fit_width(width).stretch_to_fit_height(height)
print("but after stretching we should match", person.get_width(), person.get_height())
return person
4 Easings
5 Useful extensions
- Professionalize the police - by Noah Smith - Noahpinion
- manimml/ManimML: ManimML is a project focused on providing animations and visualizations of common machine learning concepts with the Manim Community Library.
- Matheart/manim-physics: Physics simulation plugin of Manim that can generate scenes in various branches of Physics.
- NeoPlato/manim-livestream: Package that implements livestreaming configurations for Manim.
- ManimCommunity/awesome-manim: A database with many Manim users and content creators
- heejin_park’s Lectures
- naveen521kk/manim-fonts: Use Fonts from Internet With Manim.
- naveen521kk/manim-fontawesome: Font Awesome SVGs for Manim
6 Secret OpenGL mode
Undocumented, except for the distressingly vague and unofficial Manim OpenGL Renderer Usage Guide.
Fast (notionally) and interactive.
Possibly using OpenGL is as simple as passing the --renderer=opengl
flag? That does not work for me.
7 In jupyter
This is how we create a cell that will render itself:
%%manim -v WARNING --progress_bar None CreateCircle
class CreateCircle(Scene):
def construct(self):
circle = Circle() # create a circle
circle.set_fill(PINK, opacity=0.5) # set the colour and transparency
self.play(Create(circle)) # show the circle on screen
The -v WARNING
and --progress_bar None
are to keep output minimalist.
It is somewhat hard to find documentation for this feature by browsing, but it exists under ManimMagic, although there it punts lots of stuff to the manim command line.
8 Misc tips
8.1 Tip tips
Misfeature: Arrow is a thing, but the tip of the arrow does not inherit the z_index
of the parent. Checking TipableVMobject we find the correct mitigation is
8.2 Fade out everything
9 Workflow
OK, but how do we actually create a video with helpful text etc? People do not often post full examples. Here is one, by Act of Learning.
9.1 Quick and dirty presentation by screen capture
Painstakingly editing a video in code is very hi-fi, but also tedious and I am happy to throw away some fidelity in order to get my presentations done.
One quick hack to improve the quality of inference is to use a screen capture tool to record the video as it is being rendered. I use QuickTime on macOS because that is easy, but there are many alternatives on all OSes; in particular there are fancy video routers which will do live compositing.
To make that fluid, there needs to be something to play back and pause the video animation; this goes much nicer if there are no annoying “pause” and “play” icons on the screen.
Pro-tip: VLC has a mode without such icons, which are called “on screen display”. They can be disabled in the advanced preferences: see How to disable the pause and play on screen icons.
That done, a screen capture of the important bit of the video playing window is a reasonably seamless way to show off the animation, and it is easy to pause and resume the animation as needed. The resulting video might occasionally be paused in the wrong moment and will have some silly resolution (811 pixels high on my machine) but TBH my years of training is in machine learning not in video production, so they are going to have to pay someone if they want something better.
9.2 Manim editor
Want a quirky GUI to present those animations fluidly?
9.3 Voiceover mode
A recent feature tries to make the timing of the animation smoother by easing synchronising a script and a recorded or synthesised voice inside the animation.
I personally am bad at writing scripts, and bad at following scripts, and I usually speak off the cuff, so this does not seem to help me.
9.4 Interactive mode
OpenGL mode is supposedly interactive:
Adding a line:
self.interactive_embed()
within your scene allows you to interact with the scene directly via an IPython shell
However, OpenGL mode does not work for me.
9.5 In VS Code
There is an extension apparently for live previewing manim animations. It doesn’t work for me; for one it seems to use PowerShell, somehow, but then gives an error about a missing /bin/sh
. What shell/OS am I even supposed to be using?
10 Alternatives
Many manim-like packages have been inspired by manim.