Getting Started with Motion Canvas for Programmatic Animations
Motion Canvas is a TypeScript-based animation tool that lets you create high-quality motion graphics through code. Unlike traditional video editors, you script every element—shapes, timelines, and transitions—using JavaScript/TypeScript syntax. This tutorial covers the essentials to build your first animation.
Setting Up Your First Project
Install Motion Canvas globally via Node.js: npm install -g @motion-canvas/cli. Then create a new project: npm init @motion-canvas@latest my-project. Navigate into the folder and run npm start to launch the editor in your browser at localhost:9000.
Understanding Scene and Node Architecture
Every animation is composed of scenes (timeline sections) and nodes (visual elements). In src/scenes/example.tsx, define a scene:
- Use
makeScene2Dto create a scene function. - Add nodes like
Circle,Rect, orTxtinside a<View>component. - Each node accepts properties such as
fill,size,position, andopacity.
Adding Keyframe Animations
Motion Canvas uses generators for smooth transitions:
Basic movement
yield* circle().position.x(200, 1) moves the circle 200px right over 1 second. The * after yield tells the runtime to wait for completion.
Chaining animations
Use multiple yield* calls sequentially, or combine with all() for parallel motion:
yield* all(circle().opacity(0, 0.5), rect().scale(2, 0.5)) – both animations run simultaneously.
Exporting Your Animation
Stop the dev server (Ctrl+C) and run npm run export. The tool renders each scene as a series of PNG frames inside the output folder. Use FFmpeg or similar to stitch them into a video file. Alternatively, install @motion-canvas/ffmpeg for direct video export.
Motion Canvas gives you full programmatic control over every pixel. Start with simple shapes, experiment with generators, and build complex motion graphics entirely in code.