Preview App ellipse 示例输出

scenes.rs(共享场景与项目装配)

use ranim::{
    anims::{creation::WritingAnim, fading::FadingAnim, morph::MorphAnim},
    color::palettes::manim,
    core::animation::eval::StaticAnim,
    glam::dvec2,
    items::vitem::{
        VItem,
        geometry::{Circle, Ellipse},
    },
    prelude::*,
    utils::rate_functions::smooth,
};

#[scene]
#[wasm_demo_doc]
#[output(dir = "./output/ellipse")]
fn ellipse(r: &mut RanimScene) {
    // Create an ellipse (semi-axes: 3.0 x 1.5) and write it in
    let ellipse = Ellipse::new(dvec2(3.0, 1.5)).with(|e| {
        e.set_stroke_color(manim::BLUE_C);
    });
    let mut vitem = VItem::from(ellipse);

    let mut content = seq![vitem.write().with_rate_func(smooth)];

    // Transform to a circle
    let circle = Circle::new(2.0).with(|c| {
        c.set_stroke_color(manim::RED_C);
    });
    content.push(vitem.morph_to(VItem::from(circle)).with_rate_func(smooth));

    // Transform to a vertical ellipse
    let ellipse_v = Ellipse::new(dvec2(1.0, 2.5)).with(|e| {
        e.set_stroke_color(manim::GREEN_C);
    });
    content.push(
        vitem
            .morph_to(VItem::from(ellipse_v))
            .with_rate_func(smooth),
    );

    // Fade out
    content.push(vitem.fade_out().with_rate_func(smooth));

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

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

/// Register the scenes provided by this example.
pub struct ScenesPlugin;

impl ranim::Plugin for ScenesPlugin {
    fn build(&self, app: &mut bevy_app::App) {
        app.add_scenes([ellipse::scene()]);
    }
}

main.rs(平台入口)

mod scenes;

#[cfg(not(target_arch = "wasm32"))]
fn main() {
    #[cfg(feature = "cmd-render")]
    {
        use ranim::prelude::*;
        let mut app = App::new();
        app.add_plugins(scenes::ScenesPlugin);
        run_cli(app.build());
    }
    #[cfg(not(feature = "cmd-render"))]
    compile_error!("native examples require the `cmd-render` feature (enabled by default)");
}

// The WASM module is driven by JavaScript through app().
#[cfg(target_arch = "wasm32")]
fn main() {}

#[cfg(target_arch = "wasm32")]
#[wasm_bindgen::prelude::wasm_bindgen]
pub fn app() -> ranim::wasm::WasmApp {
    use ranim::prelude::*;

    let mut app = App::new();
    app.add_plugins(scenes::ScenesPlugin);
    ranim::wasm::WasmApp::new(app.build())
}