Introduction
MotionScript is a TypeScript-first animation library for creating programmatic 2D (and 3D) animations. You describe scenes as generator methods on a Scene class, compose animations with yield*, and render to video.
Quick start
The fastest way to get going is to scaffold a new project:
- npm
- yarn
- pnpm
npm create @motion-script@latest
yarn create @motion-script
pnpm create @motion-script@latest
Optional component packages
- npm
- yarn
- pnpm
npm install @motion-script/latex # LaTeX equations
npm install @motion-script/code # Syntax-highlighted code blocks
npm install @motion-script/three # Three.js 3D scenes
yarn add @motion-script/latex # LaTeX equations
yarn add @motion-script/code # Syntax-highlighted code blocks
yarn add @motion-script/three # Three.js 3D scenes
pnpm add @motion-script/latex # LaTeX equations
pnpm add @motion-script/code # Syntax-highlighted code blocks
pnpm add @motion-script/three # Three.js 3D scenes
How scenes work
Every animation is a Scene — a class that extends Scene and implements a build() generator method. Inside build() you add nodes to the scene and use yield* to drive animations frame by frame.
import { Scene, Rect, createRef, wait } from '@motion-script/core';
export class MyScene extends Scene {
*build() {
const box = createRef<Rect>();
this.add(
<Rect ref={box} width={200} height={200} fill="royalblue" borderRadius={16} />
);
// Slide right over 1 second, then wait
yield* box().to({ x: 400 }, 1);
yield* wait(0.5);
}
}
Key concepts:
this.add(node)— attach a node to the scenecreateRef<T>()— get a typed reference to a JSX nodeyield* node.to(props, duration)— animate properties over timeyield* wait(seconds)— pause for a duration
Next steps
- Shapes — Rect, Ellipse, Line, Path, Polygon, Polygram, Image
- Text — Text and RichText nodes
- Tweening — animate properties with easing,
parallel,sequence - Layouts — arrange children with flex and stack layout
- Effects — blur, grayscale, and pixelate
- Masks — clip content with shape masks
- Boolean Operators — combine paths
- Components → LaTeX — render math equations
- Components → Code — syntax-highlighted code blocks
- Components → Three.js — embed 3D scenes