ArcBetweenPoints Example

This example demonstrates ArcBetweenPoints.

https://github.com/user-attachments/assets/9595ce1d-2390-4d4d-958f-9299755460b7

arc_between_points.mp4

1use itertools::Itertools;
2use log::LevelFilter;
3use ranim::animation::fading::FadingAnimSchedule;
4use ranim::color::HueDirection;
5use ranim::glam::{DMat2, dvec2};
6use ranim::items::group::Group;
7use ranim::items::vitem::ArcBetweenPoints;
8use ranim::prelude::*;
9use ranim::timeline::TimeMark;
10
11#[scene]
12struct ArcBetweenPointsScene;
13
14impl TimelineConstructor for ArcBetweenPointsScene {
15 fn construct(self, timeline: &RanimTimeline, _camera: &mut Rabject<CameraFrame>) {
16 let center = dvec2(0.0, 0.0);
17
18 let start_color = color!("#FF8080FF");
19 let end_color = color!("#58C4DDFF");
20 let ntan = 16;
21 let nrad = 5;
22
23 let arcs = (0..nrad)
24 .map(|i| {
25 let radius = 6.0 * (i + 1) as f64 / nrad as f64;
26 let width = 0.12 * ((nrad - i) as f64 / nrad as f64).powi(2);
27 let angle = std::f64::consts::PI * 7.0 / 4.0 * (i + 1) as f64 / nrad as f64;
28 (radius, width, angle)
29 })
30 .cartesian_product(0..ntan)
31 .map(|((rad, width, angle), j)| {
32 let color = start_color.lerp(
33 end_color,
34 j as f32 / (ntan - 1) as f32,
35 HueDirection::Increasing,
36 );
37 let vec = DMat2::from_angle(std::f64::consts::PI * 2.0 / ntan as f64 * j as f64)
38 * dvec2(rad, 0.0);
39 let mut arc = ArcBetweenPoints {
40 start: center.extend(0.0),
41 end: (center + vec).extend(0.0),
42 angle,
43 }
44 .build();
45 arc.set_color(color)
46 .set_fill_opacity(0.0)
47 .set_stroke_width(width as f32);
48 arc
49 })
50 .collect::<Group<_>>();
51 let mut arcs = timeline.insert(arcs);
52
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 timeline.insert_time_mark(
56 timeline.duration_secs(),
57 TimeMark::Capture("preview.png".to_string()),
58 );
59 }
60}
61
62fn main() {
63 #[cfg(debug_assertions)]
64 pretty_env_logger::formatted_timed_builder()
65 .filter(Some("ranim"), LevelFilter::Trace)
66 .init();
67 #[cfg(not(debug_assertions))]
68 pretty_env_logger::formatted_timed_builder()
69 .filter(Some("ranim"), LevelFilter::Info)
70 .init();
71
72 render_scene(ArcBetweenPointsScene, &AppOptions::default());
73}
74