Madio

Prompting AI for math animations: 12 patterns that work

Sun May 10 2026 00:00:00 GMT+0000 (Coordinated Universal Time) · Sanatan Sharma

Prompting AI for animations is closer to writing a stage direction than writing code. The model already knows the Manim Community API, has read the 3Blue1Brown source, and can produce a working scene in seconds. What it cannot do is read your mind. The prompt has to do that work, and most prompts fail in the same handful of ways.

This post collects twelve patterns that produce reliable math animations on Madio and on raw LLMs. Each pattern has a name, a use case, a template, and a description of what the resulting frame looks like. At the end, the most common failure modes and how to fix them.

Why patterns matter

Manim is a small, declarative API. The LLM has seen thousands of examples and knows how Create, Transform, FadeOut, and MoveAlongPath compose. The bottleneck is not the model's coding skill. It is the prompt's specificity. If you ask for "an animation about derivatives," you will get something. It might be a parabola with a moving tangent line. It might be a list of rules with arrows. The model picks for you, and that pick is rarely what you wanted.

A pattern fixes that. It encodes the structure ("step-by-step", "before-and-after", "side-by-side-equation") so the model only has to fill in the math. The same pattern works whether you are writing the prompt for Madio's Gemini pipeline or pasting it into another tool.

The 12 patterns

1. Step-by-step

Use when the concept is a sequence: a derivation, an algorithm, a construction. Each step appears, the previous step fades or shifts, the final state remains.

Template: Animate <concept> in N steps. Step 1: <action>. Step 2: <action>. ... Final frame: <description>. Keep each step on screen for ~2 seconds before transitioning.

Example: "Animate the derivation of the quadratic formula in 5 steps. Step 1: write ax^2 + bx + c = 0. Step 2: divide both sides by a. Step 3: complete the square. Step 4: take the square root. Step 5: solve for x. Final frame: x = (-b plus or minus sqrt(b^2 - 4ac)) / 2a centered."

2. Compare-and-contrast

Use when two ideas are easier to understand together. Linear vs exponential growth, mean vs median, gradient vs Newton's method.

Template: Show <A> and <B> side by side. Left: <A> with <visual>. Right: <B> with <visual>. Highlight the difference at the end.

Example: "Show linear growth and exponential growth side by side. Left: y = 2x as a straight blue line. Right: y = 2^x as a red curve. Run x from 0 to 5. End with both labeled and the gap between them shaded."

3. Build-up

Use when the final figure has many parts and the order of arrival matters. A neural net diagram, a circuit, a graph with multiple curves.

Template: Build up <figure>, one element at a time. First <element>, then <element>, finally <element>. Hold the complete figure for 2 seconds.

Example: "Build up a unit circle, one element at a time. First the x and y axes, then the circle itself, then a radius at angle theta, then the cosine and sine projections as dashed lines. Hold for 2 seconds."

4. Derivation

A specialized step-by-step for proofs and algebraic manipulation. The key is keeping the previous expression visible long enough to see what changed.

Template: Derive <result> from <starting point>. Show each algebraic step with the changed term highlighted in <color>. End with the result boxed.

Example: "Derive sin(2x) = 2 sin(x) cos(x) from the angle addition formula. Highlight the substituted term in yellow at each step. End with the result boxed in blue."

5. Transform

Use when one object becomes another: a square morphing into a circle, an equation rearranging, a graph rotating. Manim's Transform is the workhorse here.

Template: Transform <A> into <B> over 2 seconds. Show the intermediate state if helpful.

Example: "Transform the equation y = x^2 into y = (x - 2)^2 + 1 over 3 seconds. Show the parabola shifting on a coordinate plane below the equation."

6. Anatomy-of

Label the parts of a structure. Useful for formulas, diagrams, and any figure where the components have names.

Template: Show <structure>. Then label each part with an arrow and text. Keep all labels on screen at the end.

Example: "Show the formula for Euler's identity, e^(i pi) + 1 = 0. Then label e as the natural base, i as the imaginary unit, pi as the half-circle constant, 1 as unity, 0 as zero. End with all five labels visible."

7. Before-and-after

Two states with a clear transition. Use for showing what an operation does: rotation, reflection, integration, normalization.

Template: Show <before>. Apply <operation>. Show <after>. The transition should make the operation obvious.

Example: "Show a triangle with vertices at (0,0), (3,0), (3,4). Apply a 90-degree counterclockwise rotation about the origin. Show the rotated triangle. The transition should sweep through intermediate angles."

8. Graph-growth

Animate a function being plotted from left to right, or a parametric curve traced over time. Standard for calculus.

Template: Plot <function> from <start> to <end>. Trace the curve at constant speed. <Optional: show a moving point with coordinates>.

Example: "Plot y = sin(x) from x = 0 to 4 pi. Trace the curve at constant speed over 4 seconds. Show a moving dot on the curve with its (x, y) coordinates labeled in real time."

9. Axis-zoom

Reveal local behavior by zooming in. Useful for showing why limits work, what derivatives look like up close, or how floating-point error accumulates.

Template: Plot <function> on a wide axis. Then zoom into <region> over 2 seconds. Highlight <feature> in the zoomed view.

Example: "Plot y = x^2 on the range -3 to 3. Zoom into the point (1, 1) over 2 seconds. Highlight the tangent line with slope 2 in red."

10. Side-by-side-equation

Pair the algebra with the geometry. The equation lives on one side, the picture on the other, and they update in sync.

Template: On the left, show <equation>. On the right, show <visual>. As <variable> changes, update both simultaneously.

Example: "On the left, show the equation y = a sin(x) with a slider for a. On the right, plot the resulting sine wave. As a goes from 0.5 to 2, update both. Hold each value for 1 second."

11. Layered-reveal

Start with the top-level idea. Reveal layers underneath. Like peeling back a label to show the math beneath the metaphor.

Template: Show <high-level statement>. Reveal the formula. Reveal the derivation. Reveal the intuition.

Example: "Show the headline 'Compound interest beats simple interest'. Reveal the formula A = P(1 + r/n)^(nt). Reveal a graph of both curves over 30 years. Reveal the gap as a shaded region with a dollar amount."

12. Summary-card

End on a single static frame that captures the takeaway. Useful as the last 3 seconds of any longer animation, and as a standalone for social media.

Template: Show a summary card titled <title>. Three bullets: <bullet>, <bullet>, <bullet>. Hold for 4 seconds.

Example: "Show a summary card titled 'Three properties of the normal distribution'. Three bullets: symmetric about the mean, 68 percent within one sigma, 95 percent within two sigma. Hold for 4 seconds."

Common failure modes

The patterns above are not magic. They reduce variance. Here are the prompt failures we see most on Madio's logs and how to fix each.

Vague nouns. "Show derivatives" leaves the model to choose the function, the axis range, and the visual style. Replace with "Show the derivative of y = x^2 as a tangent line that slides along the curve."

Two concepts at once. "Animate gradient descent on a loss landscape with a neural net training in real time" combines two animations. The model will produce one badly or both badly. Split into two prompts.

Implicit 3D. "Show a paraboloid with gradient descent" requires a 3D scene. If the prompt does not say "3D", the model often defaults to 2D and produces a confused output. Add "Use a 3D scene with axes labeled x, y, z."

Unnamed entities. "Show the curve and the line and the point" leaves three unlabeled objects. Name them. "Show the blue curve y = x^2, the red tangent line at x = 1, the green point (1, 1)."

Color collisions. Asking for five colored objects often pushes the model into a palette where two colors are nearly identical. Stick to four named colors maximum: blue, red, green, yellow. Madio's prompt augmentation step injects a palette guard but explicit colors still win.

Timing micromanagement. "Show the curve for exactly 1.7 seconds, then fade over 0.4 seconds, then..." gives the model too much rope. Specify timing once or twice in a prompt, not on every step. Rendering with manim -ql at 480p uses default 1-second transitions and looks fine.

How Madio fits

The patterns above work in any LLM. Madio adds three things on top: a prompt augmentation step that injects safety rules (no undefined classes, palette guard, scene length cap), a sandboxed Docker render with a 3-attempt retry loop that re-fixes the code when rendering fails, and a two-tier code cache so the same prompt produces a video in 8 seconds the second time. The free tier gives you 5 credits and 30-second clips at 720p with a watermark, which is enough to test all 12 patterns. The pricing page has the full breakdown.

If you want to see the patterns rendered, the gallery has samples grouped by topic, and the templates page lets you load a pattern into the editor without retyping the prompt.

What to read next

If you want to apply patterns 8 and 11 to a concrete topic, the gradient descent walkthrough shows the full prompt and the rendered output. If you want to know what the model is doing under the hood when it picks a pattern, text-to-Manim AI tools in 2026 covers how Gemini, GPT, and Claude differ on Manim code generation.

Open the editor and try one pattern. The free tier is enough.

Try Madio free →