motion-canvas-rs 0.1.2

A high-performance vector animation engine inspired by Motion Canvas, built on Vello and Typst.
Documentation

Motion Canvas in Rust

Motion Canvas Banner

A high-performance vector animation engine inspired by Motion Canvas, built on Vello and Typst.

[!IMPORTANT] Prototype Status: This project is a functional prototype and proof-of-concept. It is not a 1:1 implementation of the original Motion Canvas API or features.

Installation

Add the library to your Cargo.toml. To enable all features (math, code blocks, images, export), use the full flag:

# Enable everything
cargo add motion-canvas-rs --features full

# Or pick only what you need (e.g., just math and images)
cargo add motion-canvas-rs --features math,image

Features

Feature Description Enables
math Typst-powered LaTeX math rendering. MathNode
code Syntax-highlighted code blocks via Syntect. CodeNode
image Bitmap (PNG, JPEG) and Vector (SVG) support. ImageNode
export Headless frame rendering and video generation. project.export()
full Meta-feature that enables all of the above. Everything

Key Capabilities

  • High-performance: GPU-accelerated vector rendering via Vello.
  • Arc-length Sampling: Accurate path animations and offsets.
  • Easing Library: 30+ standardized easing functions.
  • FFmpeg Integration: Direct streaming of animation frames to video.
  • Clean API: Streamlined prelude for high-speed prototyping.
  • Node Primitives: Built-in support for Circles, Rects, Polygons, Lines, and Groups.

Supported Nodes

Node Description Features
Circle Basic circle primitive. radius, color, transform
Rect Rectangle with optional corner radius. size, radius, color
Polygon Regular and custom polygon shapes. points, fill, stroke
Line Simple line between two points. start, end, width
PathNode Complex path sampling and animation. arc-length, sample
TextNode High-quality text rendering (skrifa). text, font_size, family
MathNode Typst-powered mathematical formulas. LaTeX, smooth-transitions
CodeNode Syntax-highlighted code with transitions. syntect, magic-move
ImageNode Bitmap and SVG image display. png, jpeg, svg
GroupNode Hierarchical grouping of any nodes. children, inherited-opacity

Project Structure

The engine is organized into a modular structure:

  • src/lib.rs: Library entry point with clean module re-exports.
  • src/engine/nodes/: Individual node implementations.
  • src/engine/animation/: Core animation traits and flow controls.
  • src/engine/easings.rs: Comprehensive easing function library.
  • examples/: Ready-to-run demonstration scripts.

Quick Start

use motion_canvas_rs::prelude::*;
use std::time::Duration;

fn main() {
    // Project::default() uses default values (800x600, 60fps)
    let mut project = Project::default()
        .with_title("Quick Start")
        .with_background(Color::rgb8(0x1a, 0x1a, 0x1a));

    // Nodes support a builder pattern and Default traits
    let circle = Circle::default()
        .with_position(Vec2::new(400.0, 300.0))
        .with_radius(100.0)
        .with_color(Color::RED);

    let text = TextNode::default()
        .with_position(Vec2::new(400.0, 300.0))
        .with_text("Hello Motion Canvas!")
        .with_font_size(48.0)
        .with_color(Color::WHITE);

    project.scene.add(Box::new(circle.clone()));
    project.scene.add(Box::new(text.clone()));

    project.scene.timeline.add(all![
        circle.radius.to(100.0, Duration::from_secs(1)),
        text.transform
            .to(Affine::translate((400.0, 500.0)), Duration::from_secs(1)),
    ]);

    project.show().expect("Failed to render");
}

Running Examples

The project includes 13+ formal examples. Detailed documentation for each can be found in the examples directory.

cargo run --example getting_started

https://github.com/user-attachments/assets/0ce19049-7d85-4d3a-befe-5bc7c9dc33be

cargo run --example shapes
cargo run --example polygon

https://github.com/user-attachments/assets/304d86fa-22c5-4aa4-83ab-35c199260c31

cargo run --example math_code

https://github.com/user-attachments/assets/967e0b47-a8de-4ab7-9b21-8758a2c7f508

cargo run --example images

https://github.com/user-attachments/assets/25248e66-ccc7-4422-9f2f-7b9ef361d8d9

cargo run --example advanced_flow

https://github.com/user-attachments/assets/d283b03a-ae50-4011-9fab-77ced70a2632

cargo run --example easing_scope

https://github.com/user-attachments/assets/f875086e-d927-42a4-9f21-e57afbdaaaa4

cargo run --example math_animation

https://github.com/user-attachments/assets/f3d8e774-31f4-4e96-b7b7-9e6bda0ec16f

cargo run --example color_interpolation

https://github.com/user-attachments/assets/cd002797-84ec-4bcb-af1f-0ab6e7c20433

cargo run --example code_animation

https://github.com/user-attachments/assets/96135e70-b5d5-471f-9107-cc70f2b416fa

cargo run --example code_advanced

https://github.com/user-attachments/assets/23ad4662-e499-42f0-8468-3e1666e33d84

cargo run --example group_animation

https://github.com/user-attachments/assets/75f078ba-51c2-4d26-8993-25e6b77372a9

cargo run --example export

https://github.com/user-attachments/assets/c01897a9-e744-43af-bfee-045f44549ba9

Requirements

  • Rust 1.75+
  • FFmpeg (optional, for direct video streaming)
  • System fonts (Inter, Fira Code, etc. for specific examples)

Credits

This project is heavily inspired by the original Motion Canvas by aarthificial.

Special thanks to:

  • easings.net for the standardized easing function library.
  • shiki-magic-move for the inspiration behind the token-based code transition logic.