ArcBetweenPoints Example

This example demonstrates ArcBetweenPoints.

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

arc_between_points.mp4

Preview App
use itertools::Itertools;
use ranim::{
    anims::{fading::FadingAnim, lagged::LaggedAnim},
    color,
    color::HueDirection,
    glam::{DMat2, dvec2},
    items::vitem::geometry::ArcBetweenPoints,
    prelude::*,
    utils::rate_functions::smooth,
};

#[scene]
#[output(dir = "./output/arc_between_points")]
fn arc_between_points(r: &mut RanimScene) {
    let center = dvec2(0.0, 0.0);

    let start_color = color::color("#FF8080FF");
    let end_color = color::color("#58C4DDFF");
    let ntan = 16;
    let nrad = 5;

    let mut arcs = (0..nrad)
        .map(|i| {
            let radius = 6.0 * (i + 1) as f64 / nrad as f64;
            let width = 0.12 * ((nrad - i) as f64 / nrad as f64).powi(2);
            let angle = std::f64::consts::PI * 7.0 / 4.0 * (i + 1) as f64 / nrad as f64;
            (radius, width, angle)
        })
        .cartesian_product(0..ntan)
        .map(|((rad, width, angle), j)| {
            let color = start_color.lerp(
                end_color,
                j as f32 / (ntan - 1) as f32,
                HueDirection::Increasing,
            );
            let vec = DMat2::from_angle(std::f64::consts::PI * 2.0 / ntan as f64 * j as f64)
                * dvec2(rad, 0.0);
            ArcBetweenPoints::new(center.extend(0.0), (center + vec).extend(0.0), angle).with(
                |arc| {
                    arc.stroke_width = width as f32;
                    arc.set_stroke_color(color);
                },
            )
        })
        .collect::<Vec<_>>();
    let total_secs = 3.0;
    let content = arcs
        .lagged(0.2, |arc| {
            let animation = arc.fade_in();
            move |alpha| animation.eval_alpha(smooth(alpha))
        })
        .with_duration(total_secs);

    r.play(CameraFrame::default().show().with_duration(total_secs));
    r.play(content);

    r.insert_time_mark(total_secs, TimeMark::Capture("preview.png".to_string()));
}