use ranim::{
    anims::{
        creation::{CreationAnim, WritingAnim},
        morph::MorphAnim,
    },
    color::palettes::manim,
    items::vitem::{
        VItem,
        geometry::{Circle, Rectangle, Square},
    },
    prelude::*,
    utils::rate_functions::linear,
};

#[scene]
#[output(dir = "./output/getting_started2")]
fn getting_started2(r: &mut RanimScene) {
    let _r_cam = r.insert(CameraFrame::default());
    let rect = Rectangle::new(4.0, 9.0 / 4.0).with(|rect| {
        rect.set_stroke_color(manim::GREEN_C);
    });

    // The new initialized timeline is hidden by default, use show to start encoding a static anim and make it show
    let r_rect = r.insert(rect.clone());

    r.timelines_mut().forward(1.0);

    let square: VItem = Square::new(2.0)
        .with(|square| {
            square.set_color(manim::BLUE_C);
        })
        .into();
    let circle: VItem = Circle::new(2.0)
        .with(|circle| {
            circle.set_color(manim::RED_C);
        })
        .into();
    let r_vitem = r.insert(square.clone());
    {
        let timeline = r.timeline_mut(r_vitem);
        timeline
            .forward(1.0)
            .play(square.clone().create())
            .play(
                square
                    .clone()
                    .morph_to(circle.clone())
                    .with_rate_func(linear),
            )
            .play(circle.clone().unwrite());
    }

    r.timeline_mut(r_rect).play(VItem::from(rect).uncreate());
}
