--- name: motion-canvas description: Create programmatic vector animations with TypeScript using the Motion Canvas library. Use when building animated explainer videos, tutorials, data visualizations, or presentations with synchronized audio. Triggers on tasks involving motion graphics, animation scenes, code-based video creation, or requests to animate shapes/text/images with precise timing control. --- # Motion Canvas TypeScript library for creating animated videos programmatically using generator functions. ## Project Setup ```bash npm init @motion-canvas@latest # Create new project npm install && npm start # Run dev server at localhost:9000 ``` **Project structure:** ``` my-project/ ├── src/ │ ├── project.ts # Main project config │ └── scenes/ # Animation scenes ├── vite.config.ts └── package.json ``` ## Core Concepts ### 1. Project Configuration ```ts // src/project.ts import {makeProject} from '@motion-canvas/core'; import scene1 from './scenes/scene1?scene'; // Note: ?scene suffix required export default makeProject({ scenes: [scene1], // audio: audioFile, // Optional: sync animations to voiceover }); ``` ### 2. Scenes Scenes use generator functions - `yield*` pauses to render frames: ```tsx import {makeScene2D, Circle, Rect, Txt} from '@motion-canvas/2d'; import {createRef, all, waitFor, waitUntil} from '@motion-canvas/core'; export default makeScene2D(function* (view) { const circle = createRef(); view.add(); yield* circle().position.x(300, 1); // Move right over 1 second yield* waitFor(0.5); // Pause 0.5 seconds yield* circle().position.x(0, 1); // Move back }); ``` ### 3. Nodes (Visual Elements) ```tsx // Shapes // Text // Media