Using the Anima Engine
Anima is a TypeScript animation engine for mathematical visualizations. It runs on Bun and renders to canvas.
Import everything from 'anima' (the package index). All classes, animations, and easing functions are exported from there.
Quick Start
import { Scene, Circle, Rectangle, Color, easeInOutQuad } from 'anima';
export class MyScene extends Scene {
constructor() {
super({ width: 1920, height: 1080, frameRate: 60, backgroundColor: Color.BLACK });
const circle = new Circle(1).stroke(Color.WHITE, 2).pos(-2, 0); // radius 1, at position (-2, 0)
const rect = new Rectangle(2, 1).fill(Color.BLUE, 0.6).pos(2, 0); // 2×1, at position (2, 0)
// Items in the same play() call run in PARALLEL
this.play(
circle.fadeIn(1).moveTo(0, 0, 1), // fadeIn 1s, then move to (x=0, y=0) over 1s
rect.fadeIn(1) // fadeIn 1s (runs in parallel with circle's chain)
);
this.wait(0.5); // 0.5 second pause
// Successive play() calls run SEQUENTIALLY
this.play(circle.fadeOut(0.5)); // fadeOut over 0.5s
}
}
Render with CLI: anima render myfile.ts -s MyScene -o output.mp4
Coordinate System
Origin (0, 0) is screen center. Y-axis points up. Visible frame is ~14.2 × 8 world units at 1920×1080.
Skill Modules
For detailed usage of each subsystem, read the relevant module:
| Module |
What it covers |
| Scene |
Scene setup, config, coordinate system, play(), wait(), add()/remove(), lifecycle rules |
| Mobjects |
Mobject/VMobject hierarchy, immediate setters (pos, show, hide, setScale, setRotation), saveState()/restore() |
| Geometry |
Circle, Rectangle, Line, Arrow, Arc, Polygon, Point — constructors and usage |
| Styling |
Color class (presets, fromHex, fromHSL), .stroke(), .fill(), default appearance rules |
| Animations |
Fluent API (chaining), Pro API (explicit objects), Sequence, Parallel, MorphTo, delay(), hybrid usage |
| Easing |
All 30+ easing functions: standard, bounce, Manim-style rate functions, choosing guide |
| Camera |
CameraFrame animations (zoomIn, zoomOut, centerOn, fitTo, zoomToPoint), Shake, Follow, bounds, instant methods |
| Text |
Text creation from font files, TextStyle, glyph access, animating text |
| Graph |
Graph nodes/edges, layout algorithms (circular, tree, force-directed), updateEdges() |
| VGroup |
VGroup children management, arrange(), center(), toCorner(), alignTo(), cascading styles |
| Keyframes |
KeyframeAnimation, KeyframeTrack — fine-grained multi-property keyframe control |
| Rendering |
Renderer, formats (mp4/webp/gif/sprite/png), Resolution presets, quality, CLI commands, serialize/deserialize |
Core Rules for Authoring Scenes
- Extend
Scene and build everything in the constructor.
- Intro animations (
fadeIn, write, draw, FadeIn, Write, Draw) auto-add objects to the scene.
- Transform/exit animations (
moveTo, rotate, scaleTo, fadeOut, etc.) require the target to already be in the scene.
- Use
this.add(obj) for static objects that should be visible without animation.
- All durations are in seconds.
- All angles are in radians.
- Multiple items in one
this.play(...) call run in parallel. Successive play() calls run sequentially.
- Use
this.wait(seconds) to insert gaps between play calls.
Long Video Tips
For 30–50 minute videos:
- Structure in sections: Group related animations with
this.wait() between logical sections.
- Use
saveState() / restore(): Save object positions before zooming in, restore to return.
- Camera management: Use
centerOn, fitTo, and zoomIn/zoomOut to guide the viewer's focus.
- Reuse objects:
remove() objects when done, add() new ones. Don't leave hundreds of invisible objects in the scene.
- Use
Sequence and Parallel: For complex choreography, compose explicitly rather than deeply nesting fluent chains.
- Keyframes: For complex motion paths, use
KeyframeAnimation instead of chaining dozens of moveTo calls.
- Preview quality: Use
quality: 'preview' or the CLI preview command during iteration, switch to production for final render.
1---2name: anima3description: Summarizes how to use the Anima animation engine (Scene, Mobjects, Fluent API, Pro API, camera, timeline, rendering, and CLI). Use when authoring or explaining Anima animations.4---5
6# Using the Anima Engine
7
8Anima is a TypeScript animation engine for mathematical visualizations. It runs on Bun and renders to canvas.
9
10Import everything from `'anima'` (the package index). All classes, animations, and easing functions are exported from there.
11
12## Quick Start
13
14```ts
15import { Scene, Circle, Rectangle, Color, easeInOutQuad } from 'anima';
16
17export class MyScene extends Scene {
18 constructor() {
19 super({ width: 1920, height: 1080, frameRate: 60, backgroundColor: Color.BLACK });
20
21 const circle = new Circle(1).stroke(Color.WHITE, 2).pos(-2, 0); // radius 1, at position (-2, 0)
22 const rect = new Rectangle(2, 1).fill(Color.BLUE, 0.6).pos(2, 0); // 2×1, at position (2, 0)
23
24 // Items in the same play() call run in PARALLEL
25 this.play(
26 circle.fadeIn(1).moveTo(0, 0, 1), // fadeIn 1s, then move to (x=0, y=0) over 1s
27 rect.fadeIn(1) // fadeIn 1s (runs in parallel with circle's chain)
28 );
29
30 this.wait(0.5); // 0.5 second pause
31
32 // Successive play() calls run SEQUENTIALLY
33 this.play(circle.fadeOut(0.5)); // fadeOut over 0.5s
34 }
35}
36```
37
38Render with CLI: `anima render myfile.ts -s MyScene -o output.mp4`
39
40## Coordinate System
41
42Origin `(0, 0)` is screen center. Y-axis points **up**. Visible frame is ~14.2 × 8 world units at 1920×1080.
43
44## Skill Modules
45
46For detailed usage of each subsystem, read the relevant module:
47
48| Module | What it covers |
49|---|---|
50| [Scene](rules/scene.md) | Scene setup, config, coordinate system, `play()`, `wait()`, `add()`/`remove()`, lifecycle rules |
51| [Mobjects](rules/mobjects.md) | Mobject/VMobject hierarchy, immediate setters (`pos`, `show`, `hide`, `setScale`, `setRotation`), `saveState()`/`restore()` |
52| [Geometry](rules/geometry.md) | `Circle`, `Rectangle`, `Line`, `Arrow`, `Arc`, `Polygon`, `Point` — constructors and usage |
53| [Styling](rules/styling.md) | `Color` class (presets, `fromHex`, `fromHSL`), `.stroke()`, `.fill()`, default appearance rules |
54| [Animations](rules/animations.md) | Fluent API (chaining), Pro API (explicit objects), `Sequence`, `Parallel`, `MorphTo`, `delay()`, hybrid usage |
55| [Easing](rules/easing.md) | All 30+ easing functions: standard, bounce, Manim-style rate functions, choosing guide |
56| [Camera](rules/camera.md) | `CameraFrame` animations (`zoomIn`, `zoomOut`, `centerOn`, `fitTo`, `zoomToPoint`), `Shake`, `Follow`, bounds, instant methods |
57| [Text](rules/text.md) | `Text` creation from font files, `TextStyle`, glyph access, animating text |
58| [Graph](rules/graph.md) | `Graph` nodes/edges, layout algorithms (`circular`, `tree`, `force-directed`), `updateEdges()` |
59| [VGroup](rules/vgroup.md) | `VGroup` children management, `arrange()`, `center()`, `toCorner()`, `alignTo()`, cascading styles |
60| [Keyframes](rules/keyframes.md) | `KeyframeAnimation`, `KeyframeTrack` — fine-grained multi-property keyframe control |
61| [Rendering](rules/rendering.md) | `Renderer`, formats (mp4/webp/gif/sprite/png), `Resolution` presets, quality, CLI commands, `serialize`/`deserialize` |
62
63## Core Rules for Authoring Scenes
64
651. **Extend `Scene`** and build everything in the constructor.
662. **Intro animations** (`fadeIn`, `write`, `draw`, `FadeIn`, `Write`, `Draw`) auto-add objects to the scene.
673. **Transform/exit animations** (`moveTo`, `rotate`, `scaleTo`, `fadeOut`, etc.) require the target to already be in the scene.
684. Use `this.add(obj)` for static objects that should be visible without animation.
695. All durations are in **seconds**.
706. All angles are in **radians**.
717. Multiple items in one `this.play(...)` call run in **parallel**. Successive `play()` calls run **sequentially**.
728. Use `this.wait(seconds)` to insert gaps between play calls.
73
74## Long Video Tips
75
76For 30–50 minute videos:
77
78- **Structure in sections**: Group related animations with `this.wait()` between logical sections.
79- **Use `saveState()` / `restore()`**: Save object positions before zooming in, restore to return.
80- **Camera management**: Use `centerOn`, `fitTo`, and `zoomIn`/`zoomOut` to guide the viewer's focus.
81- **Reuse objects**: `remove()` objects when done, `add()` new ones. Don't leave hundreds of invisible objects in the scene.
82- **Use `Sequence` and `Parallel`**: For complex choreography, compose explicitly rather than deeply nesting fluent chains.
83- **Keyframes**: For complex motion paths, use `KeyframeAnimation` instead of chaining dozens of `moveTo` calls.
84- **Preview quality**: Use `quality: 'preview'` or the CLI `preview` command during iteration, switch to `production` for final render.