Pymations: Maths Animations in Python

Pymations ("Python animations") makes maths animations from short Python scripts. Shapes, equations, graphs and labels appear, move, change into each other and fade away, the way they do in maths explainer videos. You write what should happen; Pymations works out where everything goes and draws it.

In Circuitry you build your scenes, run them beside the code, mix them with Pyctures drawing, and export a video.

It runs Manim Community scripts, so a script from a Manim tutorial, or one an AI wrote for Manim, can be pasted in and run.

Pymations is also a Python library for your own computer: see the Pymations page, where you can edit an animation and run it in your browser.

from pymations import *

square = Square(color=BLUE, fill_opacity=0.5)
circle = Circle(color=ORANGE, fill_opacity=0.5)

play(Create(square))
play(Transform(square, circle))
wait()

That is a whole animation. The square is drawn line by line, turns into a circle, and the picture holds for a second.

Start in Circuitry

  1. From the new-document menu (+), choose Code, then Python, and give the file a name ending in .py.
  2. Type or paste the script above. The first line, from pymations import *, is what makes it an animation.
  3. Press Run in the footer. The preview beside the code plays the animation.

The first run in a session loads Python, which can take a few seconds. After that, runs start straight away.

Watch, pause and scrub

Move the pointer over the preview (or tap it) and a timeline appears along the bottom:

  • / plays and pauses.
  • Drag along the track to move to any moment, forwards or backwards.
  • The time shows where you are and how long the whole animation is.
  • A small tick on the track marks the start of each section (each scene, see Scenes and sections).

The timeline hides itself again after a moment.

Make a video

The button in the editor's footer records the animation to an MP4 file, at 720p, 1080p, 4K, a 9:16 Short or a square. File → Record Video… opens the same choices. See Recording videos.

How it works, in one paragraph

Python only describes the animation. Circle() makes a shape, play(...) adds an animation to the timeline, and wait() adds a pause. Python finishes in a moment; then the preview plays the timeline, smoothly, without asking Python for each frame. That is why scrubbing is instant and a video never drops a frame.

One thing follows from this: positions are worked out in the preview, not in Python. You rarely need the numbers (next_to, move_to and arrange place things for you), but when you do, see reading a position back.

Where it comes from

Manim was created by Grant Sanderson to make the animations in his 3Blue1Brown maths videos. Manim Community is the community-maintained version that most people use today.

Pymations is a fresh rewrite, not a fork. It runs Manim Community scripts, but it is built to play in real time and to use Circuitry as its code editor and preview: build your scenes, run them, mix them with Pyctures animations, and export a video. Pymations is an independent project and is not affiliated with Manim, Manim Community or 3Blue1Brown.

What's in this section