Ranim
是一个使用 Rust 编写的程序化动画引擎,
受 3b1b/manim 和 jkjkil4/JAnim 启发
- 矢量图形基于二阶贝塞尔曲线表示,使用 SDF 渲染
- 使用 wgpu,兼容多种后端图形 API
- 可编译到 wasm 支持 Web 平台
Preview
App
use std::f64::consts::PI;
use log::LevelFilter;
use ranim::{
animation::{creation::WritingAnim, fading::FadingAnim, transform::TransformAnim},
color::palettes::manim,
glam::DVec3,
items::vitem::{
geometry::{Circle, Square}, VItem
},
prelude::*, timeline::TimeMark,
};
#[scene]
#[preview]
#[output(dir = "hello_ranim")]
fn hello_ranim(r: &mut RanimScene) {
let _r_cam = r.insert_and_show(CameraFrame::default());
let square = Square::new(2.0).with(|square| {
square.set_color(manim::BLUE_C);
});
let r_square = r.insert(square);
{
let timeline = r.timeline_mut(&r_square);
timeline.play_with(|square| square.fade_in());
};
let circle = Circle::new(2.0).with(|circle| {
circle
.set_color(manim::RED_C)
.rotate(PI / 4.0 + PI, DVec3::Z);
});
let r_vitem = r.map(r_square, VItem::from);
{
let timeline = r.timeline_mut(&r_vitem);
timeline.play_with(|state| state.transform_to(circle.into()));
timeline.forward(1.0);
let circle = timeline.state().clone();
timeline.play_with(|circle| circle.unwrite());
timeline.play(circle.write());
timeline.play_with(|circle| circle.fade_out());
};
r.insert_time_mark(3.7, 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(hello_ranim_scene);
#[cfg(not(feature = "app"))]
render_scene(hello_ranim_scene)
}