Easing
#![allow(unused)] fn main() { pub fn ease_in_out_cubic(t: f64) -> f64; }
Easing functions remap a linear time t ∈ [0,1] into a curve that starts
and ends slow. ease_in_out_cubic is the default: two cubic segments
meeting at (0.5, 0.5), continuous in position and slope.
Input outside [0,1] is clamped, so it's safe to feed the raw phase in from the harness without a preceding clamp.
Source
#![allow(unused)] fn main() { use anim_core::*; pub const DURATION: f64 = 2.5; type Lane = (&'static str, fn(f64) -> f64, Color); const LANES: &[Lane] = &[( "ease_in_out_cubic", ease_in_out_cubic, Color::rgb(255, 127, 80), )]; fn line(a: Vec2, b: Vec2) -> CubicBez { CubicBez::new(a, a.lerp(b, 1.0 / 3.0), a.lerp(b, 2.0 / 3.0), b) } pub fn scene(t: f64) -> DrawList { let phase = (t / DURATION).clamp(0.0, 1.0); let x_left = -260.0; let x_right = 260.0; let mut out: DrawList = Vec::new(); let n = LANES.len() as f64; for (i, (_name, easing, color)) in LANES.iter().enumerate() { let y = if n <= 1.0 { 0.0 } else { 80.0 - (i as f64 / (n - 1.0)) * 160.0 }; let a = Vec2::new(x_left, y); let b = Vec2::new(x_right, y); out.push(Cmd::Stroke { path: line(a, b), width: 1.0, color: Color::rgba(140, 140, 150, 0.5), }); let s = easing(phase); let p = a.lerp(b, s); out.push(Cmd::FillCircle { center: p, r: 9.0, color: *color, }); } out } }