use std::f64::consts::PI;

use ranim::{
    anims::{fading::FadingAnim, lagged::LaggedAnim, rotating::RotatingAnim},
    color::palettes::manim,
    glam::DVec3,
    items::vitem::{VItem, geometry::Circle},
    prelude::*,
};

#[scene(clear_color = "#00000000")]
#[output(dir = "./output/output_formats", format = "mp4")]
#[output(dir = "./output/output_formats", format = "webm")]
#[output(dir = "./output/output_formats", format = "mov")]
#[output(dir = "./output/output_formats", format = "gif")]
fn output_formats(r: &mut RanimScene) {
    let _r_cam = r.insert(CameraFrame::default());

    let colors = [manim::RED_C, manim::GREEN_C, manim::BLUE_C];

    let radius = 1.4;
    let mut circles: Vec<VItem> = colors
        .iter()
        .enumerate()
        .map(|(i, &color)| {
            let angle = i as f64 * 2.0 * PI / colors.len() as f64 + PI / 2.0;
            let offset = DVec3::new(angle.cos() * radius, angle.sin() * radius, 0.0);
            Circle::new(radius)
                .with(|c| {
                    c.set_color(color.with_alpha(0.5)).move_to(offset);
                })
                .into()
        })
        .collect();

    r.insert_with(|t| {
        t.play(circles.lagged(0.3, |c| c.fade_in()).with_duration(1.0))
            .forward(1.0)
            .play(
                circles
                    .rotating_at(2.0 * PI / 3.0, DVec3::Z, DVec3::ZERO)
                    .with_duration(1.0),
            )
            .forward(1.0)
            .play(circles.lagged(0.3, |c| c.fade_out()).with_duration(1.0));
    });
    r.insert_time_mark(1.5, TimeMark::Capture("preview.png".to_string()));
}
