Skip to main content

New Features

Examples showcasing newly implemented features in manim-web.

Clip Masks​

Clip any mobject to a mask shape, like an After-Effects track matte. The mask shape's filled region defines what stays visible; everything outside it is clipped. The clip uses the WebGL stencil buffer and updates every frame, so animating the mask shape re-clips the content live. Watch the circle sweep across to reveal the rainbow bars below.

Source Code
import { VGroup, Rectangle, Circle, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE } from 'manim-web';

// Colorful content: six tall rainbow bars.
const colors = [RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE];
const bars = new VGroup();
colors.forEach((color, i) => {
const bar = new Rectangle({ width: 1.7, height: 6, color, fillOpacity: 1, strokeWidth: 0 });
bar.moveTo([(i - 2.5) * 1.7, 0, 0]);
bars.add(bar);
});

// The mask shape defines the visible region. It is never drawn itself.
const mask = new Circle({ radius: 1.5 });
mask.moveTo([-6, 0, 0]);

bars.setMask(mask); // opt-in clip; bars.clearMask() removes it
scene.add(bars);

// Moving the mask re-clips the content every frame.
await scene.play(mask.animate.shift([12, 0, 0]).withDuration(2.5));
await scene.play(mask.animate.shift([-12, 0, 0]).withDuration(2.5));

Pass { invert: true } to setMask to show the content outside the mask shape instead of inside it.

Draggable Objects​

Make any mobject draggable with mouse and touch support. Supports axis constraints, snap-to-grid, and callbacks. Try dragging the shapes below — the line updates reactively.

Source Code
import { Circle, Square, Dot, Line, Text, makeDraggable, BLUE, GREEN, RED, YELLOW, WHITE } from 'manim-web';

const circle = new Circle({ radius: 0.5, color: BLUE, fillOpacity: 0.8 });
circle.moveTo([-2, 1, 0]);

const square = new Square({ sideLength: 0.8, color: GREEN, fillOpacity: 0.8 });
square.moveTo([2, 1, 0]);

const dot = new Dot({ color: YELLOW, radius: 0.15 });
dot.moveTo([0, -1, 0]);

// Line updates reactively as objects are dragged — Draggable
// re-renders the scene after each onDrag callback by default
const line = new Line({ start: circle.getCenter(), end: dot.getCenter() }).setColor(RED);
const updateLine = () =>
line.become(new Line({ start: circle.getCenter(), end: dot.getCenter() }).setColor(RED));

const label = new Text({ text: 'Drag the shapes!', fontSize: 24, color: WHITE });
label.moveTo([0, 2.5, 0]);

scene.add(circle, square, dot, line, label);

// Free drag
makeDraggable(circle, scene, { onDrag: updateLine });
makeDraggable(dot, scene, { onDrag: updateLine });

// Constrained to X axis with grid snapping
makeDraggable(square, scene, { constrainY: [1, 1], snapToGrid: 0.5 });

Draggable Objects (3D)​

Dragging works in 3D scenes too — objects move on a plane facing the camera. You can also orbit the camera (drag the background) and then drag individual objects.

Source Code
import { Sphere, Cube, Dot3D, ThreeDAxes, makeDraggable, BLUE, GREEN, YELLOW } from 'manim-web';

// ThreeDScene with orbit controls enabled by default
const axes = new ThreeDAxes({ xRange: [-4, 4, 1], yRange: [-4, 4, 1], zRange: [-3, 3, 1] });

const sphere = new Sphere({ radius: 0.4, color: BLUE, opacity: 0.8 });
sphere.moveTo([-2, 0, 0]);

const cube = new Cube({ sideLength: 0.6, color: GREEN, opacity: 0.8 });
cube.moveTo([2, 0, 0]);

const dot = new Dot3D({ color: YELLOW, radius: 0.2 });
dot.moveTo([0, 2, 0]);

scene.add(axes, sphere, cube, dot);

// 3D dragging raycasts onto a camera-facing plane at the object's depth
makeDraggable(sphere, scene);
makeDraggable(cube, scene);
makeDraggable(dot, scene);

Clickable Objects​

Clickable adds discrete click / double-click / tap detection to a mobject. The callback fires when you click on the object, but the object itself doesn't move — making it the tool for buttons, toggles, and actions. Click the circle below to cycle its color and bump the counter; double-click it to reset. The square next to it is Draggable instead: a plain click does nothing, you have to drag it.

Clickable vs Draggable​

Clickable / makeClickableDraggable / makeDraggable
Triggerdiscrete click / dblclick / tapmousedown → move → mouseup (a drag gesture)
Moves the mobject?No — fires a callback, the object stays putYes — repositions the mobject as you drag
CallbacksonClick, onDoubleClickonDragStart, onDrag, onDragEnd
Extra options—constrainX / constrainY / constrainZ, snapToGrid
Reach for it when…buttons, toggles, selecting, triggering an actionletting users reposition objects

Both return a handle with enable(), disable(), and dispose() — call dispose() to remove the underlying event listeners when you're done. (Hoverable / makeHoverable is the third sibling, for hover feedback like scaling or recoloring.)

Source Code
import { Circle, Square, Text, makeClickable, makeDraggable, BLUE, GREEN, YELLOW, RED, PURPLE, ORANGE, TEAL, PINK, WHITE } from 'manim-web';

const PALETTE = [BLUE, GREEN, YELLOW, RED, PURPLE, ORANGE, TEAL, PINK];

// Clickable: a discrete tap action — the circle never moves
let colorIndex = 0;
let clickCount = 0;
const circle = new Circle({ radius: 0.7, color: BLUE, fillOpacity: 0.9 });
circle.moveTo([-2.5, 0.3, 0]);
const counter = new Text({ text: 'Clicks: 0', fontSize: 22, color: WHITE });
counter.moveTo([-2.5, -1.6, 0]);

// Draggable: a continuous gesture that repositions the square
const square = new Square({ sideLength: 1.3, color: GREEN, fillOpacity: 0.9 });
square.moveTo([2.5, 0.3, 0]);
const posLabel = new Text({ text: 'Square: (2.5, 0.3)', fontSize: 22, color: WHITE });
posLabel.moveTo([2.5, -1.6, 0]);

scene.add(circle, counter, square, posLabel);

// This scene has no animation loop, so the callbacks call scene.render()
// to repaint after mutating a mobject.

// Click cycles color + counts; double-click resets (reset is idempotent)
const clickable = makeClickable(circle, scene, {
onClick: () => {
clickCount += 1;
colorIndex = (colorIndex + 1) % PALETTE.length;
circle.setColor(PALETTE[colorIndex]);
counter.setText(`Clicks: ${clickCount}`);
scene.render();
},
onDoubleClick: () => {
clickCount = 0;
colorIndex = 0;
circle.setColor(BLUE);
counter.setText('Clicks: 0');
scene.render();
},
});

// Drag repositions the square and reports its live position
const draggable = makeDraggable(square, scene, {
onDrag: (_mobject, position) => {
posLabel.setText(`Square: (${position[0].toFixed(1)}, ${position[1].toFixed(1)})`);
scene.render();
},
});

// Remove the event listeners when finished
// clickable.dispose();
// draggable.dispose();

Learn More: Clickable · makeClickable · Draggable · makeDraggable


Matrix Helpers​

Helper functions for working with matrices: getDetText adds determinant notation around a matrix, matrixToMobject converts arrays to Matrix mobjects, and matrixToTexString generates LaTeX strings from arrays.

Source Code
import {
Matrix, IntegerMatrix, DecimalMatrix, MobjectMatrix,
Circle, Square, MathTex,
FadeIn, getDetText, YELLOW,
} from 'manim-web';

// Multiple matrix types (like Python Manim's MatrixExamples)
const m0 = new Matrix([['\\pi', '0'], ['-1', '1']]);
const m1 = new IntegerMatrix([[1.5, 0], [12, -1.3]], { bracketType: '()' });
const m2 = new DecimalMatrix([[3.456, 2.122], [33.2244, 12.33]], { numDecimalPlaces: 2, hBuff: 3.2 });
const m3 = new MobjectMatrix([
[new Circle({ radius: 0.15 }), new Square({ sideLength: 0.25 })],
[new MathTex({ latex: '\\pi' }), new Circle({ radius: 0.1 })],
]);

scene.add(m0, m1, m2, m3);

// Determinant text (like Python Manim's DeterminantOfAMatrix)
const matrix = new Matrix([[2, 0], [-1, 1]]);
const det = getDetText(matrix, { determinant: 3, color: YELLOW });
scene.add(matrix, det);

ConvexHull3D​

A 3D convex hull computed from arbitrary points in space. Pass an array of 3D coordinates and get a solid or wireframe hull mesh.

Source Code
import { ConvexHull3D, GREEN_C } from 'manim-web';

const hull = new ConvexHull3D({
points: [
[1, 0, 0], [-1, 0, 0],
[0, 1, 0], [0, -1, 0],
[0, 0, 1], [0, 0, -1],
[0.5, 0.5, 0.5], [-0.5, -0.5, 0.5],
],
color: GREEN_C,
opacity: 0.7,
wireframe: true,
});

scene.add(hull);

// Switch to a solid hull at any time with hull.setWireframe(false).

TipableVMobject​

Base class enabling arrow tips on arbitrary VMobjects. Arrows use this internally, but now any curve-based mobject can have tips added to its endpoints.

Source Code
import { Arc, Arrow, Create, BLUE, RED, YELLOW } from 'manim-web';

const arc = new Arc({
radius: 2,
startAngle: 0,
angle: Math.PI * 1.2,
color: BLUE,
addTip: true, // TipableVMobject adds an arrow tip to the arc's end
});
await scene.play(new Create(arc));

const arrow1 = new Arrow({
start: [-3, -1.5, 0],
end: [0, 1.5, 0],
color: RED,
tipLength: 0.3,
});

const arrow2 = new Arrow({
start: [0, 1.5, 0],
end: [3, -1.5, 0],
color: YELLOW,
tipLength: 0.3,
});

await scene.play(new Create(arrow1));
await scene.play(new Create(arrow2));

TransformMatchingAbstractBase​

Abstract base class for matching-based transform animations. TransformMatchingShapes and TransformMatchingTex extend this base, and you can create custom matching transforms by subclassing it.

Source Code
import {
VGroup, Circle, Square, Triangle,
TransformMatchingShapes, Create,
BLUE, RED, GREEN, YELLOW,
} from 'manim-web';

// Source shapes
const source = new VGroup();
source.add(new Circle({ radius: 0.5, color: BLUE, fillOpacity: 0.5 }));
source.add(new Square({ sideLength: 1, color: RED, fillOpacity: 0.5 }));
source.add(new Triangle({ color: GREEN, fillOpacity: 0.5 }));
await scene.play(new Create(source));

// Target shapes (rearranged)
const target = new VGroup();
target.add(new Circle({ radius: 0.7, color: YELLOW, fillOpacity: 0.5 }));
target.add(new Square({ sideLength: 1.2, color: GREEN, fillOpacity: 0.5 }));
target.add(new Triangle({ color: BLUE, fillOpacity: 0.5 }).scale(0.8));

// Shapes are matched and transformed smoothly
await scene.play(new TransformMatchingShapes(source, target, { duration: 2 }));

ManimBanner​

A branded manim-web banner with logo shapes and text. Includes built-in createAnimation() and expandAnimation() methods for animated reveals.

Source Code
import { ManimBanner } from 'manim-web';

const banner = new ManimBanner({ darkTheme: true });

// Draw the logo shapes
await scene.play(banner.createAnimation({ duration: 2 }));

// Reveal the text
await scene.play(banner.expandAnimation({ duration: 1.5 }));

TeX Templates​

Configuration classes for LaTeX rendering. TexTemplate lets you customize preamble and packages, while TexFontTemplates and TexTemplateLibrary provide pre-built configurations.

Source Code
import {
TexTemplate, TexTemplateLibrary, TexFontTemplates,
MathTex, Create,
} from 'manim-web';

// Create a custom template
const template = new TexTemplate();
template.addPackage('physics');
console.log(template.getBody('$\\int_0^\\infty e^{-x^2} dx$'));

// Use pre-built templates
const defaultTemplate = TexTemplateLibrary.default;
const mathTemplate = TexTemplateLibrary.fullMath;

// Font templates available
const palatino = TexFontTemplates.palatino;
console.log(palatino.description); // "Palatino"

MathTex Parts​

SingleStringMathTex handles single LaTeX expressions, while MathTexPart enables composing equations from individually styleable and animatable parts.

Source Code
import { MathTex, Create, Indicate, RED, BLUE, GREEN, YELLOW, WHITE } from 'manim-web';

// One multi-part MathTex: each array entry is an addressable part.
const equation = new MathTex({ latex: ['x^2', '+', 'y^2', '=', 'r^2'], color: WHITE });
await equation.waitForRender();

// Color individual parts with getPart(index).
equation.getPart(0).setColor(RED); // x^2
equation.getPart(2).setColor(BLUE); // y^2
equation.getPart(4).setColor(GREEN); // r^2

await scene.play(new Create(equation));

// Highlight specific parts.
await scene.play(new Indicate(equation.getPart(0), { color: YELLOW }));
await scene.play(new Indicate(equation.getPart(2), { color: YELLOW }));
await scene.play(new Indicate(equation.getPart(4), { color: YELLOW }));

Step-by-Step Formula Transformation​

Show the algebra steps, ManimCE-style. Build every line as its own MathTex, then step through them: Write the first line, then fade each line out as the next fades in. A multi-part MathTex for the result makes each term an addressable part, so the middle term can be highlighted. Here (a + b)² expands to a² + 2ab + b².

Source Code
import { MathTex, Write, FadeIn, FadeOut, Indicate, WHITE, YELLOW } from 'manim-web';

// Build and render every line up front. MathTex renders asynchronously, so
// resolving the batch first keeps each `scene.play` self-contained.
const line1 = new MathTex({ latex: '(a+b)^{2}', color: WHITE });
const line2 = new MathTex({ latex: '(a+b)(a+b)', color: WHITE });
const line3 = new MathTex({ latex: 'a^{2}+ab+ab+b^{2}', color: WHITE });
// The result is multi-part so each term is addressable with getPart().
const line4 = new MathTex({ latex: ['a^{2}', '+', '2ab', '+', 'b^{2}'], color: WHITE });

const lines = [line1, line2, line3, line4];
await Promise.all(lines.map((eq) => eq.waitForRender()));
for (const eq of lines) eq.moveTo([0, 0, 0]);

// Write the first line, then fade each step out as the next fades in.
scene.add(line1);
await scene.play(new Write(line1));

let previous = line1;
for (const next of [line2, line3, line4]) {
scene.add(next);
await scene.play(new FadeOut(previous, { duration: 0.5 }), new FadeIn(next, { duration: 0.5 }));
scene.remove(previous);
previous = next;
}

// Highlight the middle term of the result.
line4.getPart(2).setColor(YELLOW);
await scene.play(new Indicate(line4.getPart(2), { color: YELLOW }));

Animation Utilities​

prepareAnimation normalizes animation inputs — accepts Animation instances or functions returning animations. overrideAnimation registers custom animations for mobject methods.

Source Code
import {
Circle, Square, Create, Transform,
prepareAnimation, BLUE, RED,
} from 'manim-web';

// Accept direct Animation instances
const circle = new Circle({ radius: 1, color: BLUE });
const anim1 = prepareAnimation(new Create(circle));
await scene.play(anim1);

// Accept functions returning animations
const square = new Square({ sideLength: 2, color: RED });
const anim2 = prepareAnimation(() => new Transform(circle, square));
await scene.play(anim2);

Responsive Multi-Aspect Layout​

Author one scene, render it landscape (16:9 YouTube) and portrait (9:16 Reels/Shorts) from the same source. Scene.setFrameAspect(width, height) reconfigures the camera frame, the renderer and the logical coordinate frame at runtime. A SafeArea computes the rectangle visible in every target aspect, so content anchored to it reflows instead of clipping. Watch the frame switch below — the safe-area content stays on screen in both shapes.

Source Code
import { Scene, SafeArea, Rectangle, Text, Circle, renderAspects, WHITE, BLUE } from 'manim-web';

// The rectangle visible in BOTH 16:9 and 9:16.
const safe = SafeArea.fromAspectRatios([16 / 9, 9 / 16]);

const title = new Text({ text: 'Safe area', color: WHITE });
safe.place(title, 'top', 0.3); // anchored to the safe-area top edge

const badge = new Circle({ radius: 1, color: BLUE, fillOpacity: 0.8 });
safe.place(badge, 'center');

scene.add(title, badge);

// Switch aspect at runtime — content anchored to the safe area reflows.
scene.setFrameAspect(1080, 1920); // 9:16 portrait
scene.setFrameAspect(1920, 1080); // 16:9 landscape

// Or produce every output at once, then drive the existing exporters per scene.
const outputs = await renderAspects(
() => new Scene(container),
(s) => {
const dot = new Circle({ radius: 1, color: BLUE });
SafeArea.fromAspectRatios([16 / 9, 9 / 16, 1 / 1]).place(dot, 'center');
s.add(dot);
},
[
{ width: 1920, height: 1080, name: 'youtube' },
{ width: 1080, height: 1920, name: 'reels', theme: 'dark' },
{ width: 1080, height: 1080, name: 'square' },
],
);