Basic Example⁋
This example demonstrates the basic usage of ranim
.
https://github.com/user-attachments/assets/dadab1ab-65e4-4cd3-bda4-b2ef97c61b0b
basic.mp4
Preview
App
use glam::DVec3;
use log::LevelFilter;
use ranim::{
animation::{creation::WritingAnim, fading::FadingAnim, lagged::LaggedAnim},
color::palettes::manim,
components::ScaleHint,
items::{
Group,
vitem::{VItem, svg::SvgItem, typst::typst_svg},
},
prelude::*,
timeline::TimeMark,
};
const SVG: &str = include_str!("../../assets/Ghostscript_Tiger.svg");
#[scene]
#[preview]
#[output(dir = "basic")]
fn basic(r: &mut RanimScene) {
let _r_cam = r.insert_and_show(CameraFrame::default());
r.timelines_mut().forward(0.2);
let svg = Group::<VItem>::from(SvgItem::new(SVG).with(|svg| {
svg.scale_to_with_stroke(ScaleHint::PorportionalY(3.0))
.put_center_on(DVec3::Y * 2.0);
}));
let text = Group::<VItem>::from(
SvgItem::new(typst_svg(
r#"
#align(center)[
#text(18pt)[Ranim]
#text(6pt)[Hello 你好]
]
"#,
))
.with(|text| {
text.scale_to_with_stroke(ScaleHint::PorportionalY(2.0))
.put_center_on(DVec3::NEG_Y * 2.0)
.set_color(manim::WHITE)
.set_fill_opacity(0.8);
}),
);
let r_svg = r.insert(svg);
let r_text = r.insert(text);
r.timeline_mut(&r_text)
.play_with(|text| text.lagged(0.2, |e| e.write()).with_duration(3.0));
r.timeline_mut(&r_svg)
.play_with(|svg| svg.fade_in().with_duration(3.0)); r.timelines_mut().sync();
r.insert_time_mark(
r.timelines().max_total_secs(),
TimeMark::Capture("preview.png".to_string()),
);
}
fn main() {
#[cfg(not(target_arch = "wasm32"))]
{
#[cfg(debug_assertions)]
pretty_env_logger::formatted_timed_builder()
.filter(Some("ranim"), LevelFilter::Trace)
.init();
#[cfg(not(debug_assertions))]
pretty_env_logger::formatted_timed_builder()
.filter(Some("ranim"), LevelFilter::Info)
.init();
}
#[cfg(feature = "app")]
preview(basic_scene);
#[cfg(not(feature = "app"))]
render_scene(basic_scene)
}