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

use ranim::{
    anims::{creation::WritingAnim, fading::FadingAnim, morph::MorphAnim},
    color::palettes::manim,
    items::vitem::{
        VItem,
        geometry::{Circle, Square},
    },
    prelude::*,
};

#[scene]
#[output(dir = "./output/hello_ranim")]
fn hello_ranim(r: &mut RanimScene) {
    let _r_cam = r.insert(CameraFrame::default());

    let mut square = Square::new(2.0);
    square.set_color(manim::BLUE_C);

    let r_square = r.insert_empty();
    {
        let t = r.timeline_mut(r_square);
        t.play(square.clone().fade_in());
    }

    let mut circle = Circle::new(2.0);
    circle
        .set_color(manim::RED_C)
        .with_origin(AabbPoint::CENTER, |x| {
            x.rotate_on_z(PI / 4.0 - PI);
        });

    let mut vitem = VItem::from(square);
    {
        let t = r.timeline_mut(r_square);
        t.play(vitem.morph_to(circle.into()));
        t.forward(1.0);
        t.play(vitem.clone().unwrite());
        t.play(vitem.write());
        t.play(vitem.fade_out());
    };

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

#[allow(unused)]
fn hello_ranim_chained(r: &mut RanimScene) {
    let _r_cam = r.insert(CameraFrame::default());
    let square = Square::new(2.0).with(|square| {
        square.set_color(manim::BLUE_C);
    });

    let r_square = r.insert_empty();
    {
        let t = r.timeline_mut(r_square);
        t.play(square.clone().fade_in());
    }

    let circle = Circle::new(2.0).with(|circle| {
        circle
            .set_color(manim::RED_C)
            .with_origin(AabbPoint::CENTER, |x| {
                x.rotate_on_z(-PI / 4.0 + PI);
            });
    });

    let mut vitem = VItem::from(square);
    r.timeline_mut(r_square)
        .play(vitem.morph_to(circle.into()))
        .forward(1.0)
        .play(vitem.clone().unwrite())
        .play(vitem.write())
        .play(vitem.fade_out());

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