Skip to main content

getting_started/
getting_started.rs

1use motion_canvas_rs::prelude::*;
2use std::time::Duration;
3
4fn main() {
5    // 1. Initialize the Project
6    let mut project = Project::default()
7        .with_fps(60)
8        .with_cache(true)
9        .with_title("Getting Started")
10        .close_on_finish();
11
12    // 2. Define Nodes
13    let circle = Circle::default()
14        .with_position(Vec2::new(400.0, 300.0))
15        .with_radius(50.0)
16        .with_fill(Color::rgb8(0xe1, 0x32, 0x38)); // Red
17
18    let text = TextNode::default()
19        .with_position(Vec2::new(400.0, 450.0))
20        .with_text("Hello Rust")
21        .with_font_size(40.0)
22        .with_fill(Color::rgb8(0xf2, 0xf2, 0xf2)); // White-ish
23
24    // 3. Add Nodes to the Scene
25    project.scene.add(Box::new(circle.clone()));
26    project.scene.add(Box::new(text.clone()));
27
28    // 4. Add Animations to the Timeline
29    project.scene.video_timeline.add(all![
30        circle.radius.to(100.0, Duration::from_secs(1)),
31        text.position
32            .to(Vec2::new(400.0, 500.0), Duration::from_secs(1)),
33    ]);
34
35    // 5. Show
36    project.show().expect("Failed to render");
37}