code_animation/
code_animation.rs1use motion_canvas_rs::prelude::*;
2use std::time::Duration;
3
4fn main() {
5 let mut project = Project::default()
6 .with_dimensions(800, 800)
7 .with_title("Code Animation")
8 .close_on_finish();
9
10 let code = CodeNode::default()
11 .with_position(Vec2::new(50.0, 50.0))
12 .with_code("")
13 .with_language("rust")
14 .with_theme("Solarized (dark)")
15 .with_font("JetBrains Mono");
16
17 project.scene.add(Box::new(code.clone()));
18
19 let interval = Duration::from_secs(4);
20 let code_duration = Duration::from_secs(1);
21 project.scene.video_timeline.add(sequence!(
22 interval,
23 code.edit(
24 r#"use motion_canvas_rs::prelude::*;
25use std::time::Duration;"#,
26 code_duration,
27 ),
28 code.edit(
29 r#"use motion_canvas_rs::prelude::*;
30use std::time::Duration;
31
32fn main() {
33 // 1. Initialize the Project
34 let mut project = Project::default()
35 .with_dimensions(800, 600)
36 .with_fps(60);
37}"#,
38 code_duration,
39 ),
40 code.edit(
41 r#"use motion_canvas_rs::prelude::*;
42use std::time::Duration;
43
44fn main() {
45 // 1. Initialize the Project
46 // 2. Define Nodes
47 // Red
48 let circle = Circle::default()
49 .with_position(Vec2::new(400.0, 300.0))
50 .with_radius(50.0)
51 .with_fill(Color::rgb8(0xe1, 0x32, 0x38));
52
53 // White-ish
54 let text = TextNode::default()
55 .with_position(Vec2::new(400.0, 450.0))
56 .with_text("Hello Rust")
57 .with_font_size(40.0)
58 .with_fill(Color::rgb8(0xf2, 0xf2, 0xf2));
59}"#,
60 code_duration,
61 ),
62 code.edit(
63 r#"use motion_canvas_rs::prelude::*;
64use std::time::Duration;
65
66fn main() {
67 // 1. Initialize the Project
68 // 2. Define Nodes
69 // 3. Add Nodes to the Scene
70 project.scene.add(Box::new(circle.clone()));
71 project.scene.add(Box::new(text.clone()));
72}"#,
73 code_duration,
74 ),
75 code.edit(
76 r#"use motion_canvas_rs::prelude::*;
77use std::time::Duration;
78
79fn main() {
80 // 1. Initialize the Project
81 // 2. Define Nodes
82 // 3. Add Nodes to the Scene
83 // 4. Add Animations to the Timeline
84 project.scene.video_timeline.add(all![
85 circle.radius.to(
86 100.0,
87 Duration::from_secs(1)
88 ),
89 text.position.to(
90 Vec2::new(400.0, 500.0),
91 Duration::from_secs(1)
92 ),
93 ]);
94}"#,
95 code_duration,
96 ),
97 code.edit(
98 r#"use motion_canvas_rs::prelude::*;
99use std::time::Duration;
100
101fn main() {
102 // 1. Initialize the Project
103 // 2. Define Nodes
104 // 3. Add Nodes to the Scene
105 // 4. Add Animations to the Timeline
106 // 5. Show
107 project.show().expect("Failed to render");
108}"#,
109 code_duration,
110 ),
111 ));
112
113 project.show().expect("Failed to render");
114}