Arc⁋
This example demonstrates Arc
.
https://github.com/user-attachments/assets/4f8c6f36-e6b7-429b-8d2a-91c21e17dec2
arc.mp4
1 | use glam::dvec2;
|
2 | use itertools::Itertools;
|
3 | use log::LevelFilter;
|
4 | use ranim::animation::fading::FadingAnimSchedule;
|
5 | use ranim::color::HueDirection;
|
6 | use ranim::components::Anchor;
|
7 | use ranim::items::group::Group;
|
8 | use ranim::items::vitem::Arc;
|
9 | use ranim::prelude::*;
|
10 | use ranim::timeline::TimeMark;
|
11 |
|
12 | #[scene]
|
13 | struct ArcScene;
|
14 |
|
15 | impl TimelineConstructor for ArcScene {
|
16 | fn construct(self, timeline: &RanimTimeline, _camera: &mut Rabject<CameraFrame>) {
|
17 | |
18 | let frame_size = dvec2(8.0 * 16.0 / 9.0, 8.0);
|
19 | let frame_start = dvec2(frame_size.x / -2.0, frame_size.y / -2.0);
|
20 |
|
21 | let start_color = color!("#FF8080FF");
|
22 | let end_color = color!("#58C4DDFF");
|
23 |
|
24 | let nrow = 10;
|
25 | let ncol = 10;
|
26 | let step_x = frame_size.x / ncol as f64;
|
27 | let step_y = frame_size.y / nrow as f64;
|
28 |
|
29 | let arcs = (0..nrow)
|
30 | .cartesian_product(0..ncol)
|
31 | .map(|(i, j)| {
|
32 | let (i, j) = (i as f64, j as f64);
|
33 |
|
34 | let angle = std::f64::consts::PI * (j + 1.0) / ncol as f64 * 360.0 / 180.0;
|
35 | let radius = step_y / 2.0 * 0.8;
|
36 | let color = start_color.lerp(
|
37 | end_color,
|
38 | i as f32 / (nrow - 1) as f32,
|
39 | HueDirection::Increasing,
|
40 | );
|
41 | let offset =
|
42 | frame_start + dvec2(j * step_x + step_x / 2.0, i * step_y + step_y / 2.0);
|
43 | let mut arc = Arc { angle, radius }.build();
|
44 | arc.set_stroke_width(0.12 * (j as f32 + 0.02) / ncol as f32)
|
45 | .set_stroke_color(color)
|
46 | .set_fill_color(color.with_alpha(0.0))
|
47 | .put_anchor_on(Anchor::center(), offset.extend(0.0));
|
48 | arc
|
49 | })
|
50 | .collect::<Group<_>>();
|
51 |
|
52 | let mut arcs = timeline.insert(arcs);
|
53 | let arcs_fade_in = arcs.lagged_anim(0.2, |item| item.fade_in());
|
54 | timeline.play(arcs_fade_in.with_total_duration(3.0)).sync();
|
55 |
|
56 | timeline.insert_time_mark(
|
57 | timeline.duration_secs(),
|
58 | TimeMark::Capture("preview.png".to_string()),
|
59 | );
|
60 | }
|
61 | }
|
62 |
|
63 | fn main() {
|
64 | #[cfg(debug_assertions)]
|
65 | pretty_env_logger::formatted_timed_builder()
|
66 | .filter(Some("ranim"), LevelFilter::Trace)
|
67 | .init();
|
68 | #[cfg(not(debug_assertions))]
|
69 | pretty_env_logger::formatted_timed_builder()
|
70 | .filter(Some("ranim"), LevelFilter::Info)
|
71 | .init();
|
72 |
|
73 | #[cfg(feature = "app")]
|
74 | run_scene_app(ArcScene);
|
75 | #[cfg(not(feature = "app"))]
|
76 | render_scene(ArcScene, &AppOptions::default());
|
77 | }
|
78 |
|