Vec2

#![allow(unused)]
fn main() {
pub struct Vec2 { pub x: f64, pub y: f64 }

impl Vec2 {
    pub fn new(x: f64, y: f64) -> Self;
    pub fn dot(self, o: Self) -> f64;
    pub fn length(self) -> f64;
    pub fn lerp(self, o: Self, t: f64) -> Self;
}
}

The 2D point / vector. f64 throughout — memory is cheap, drift is not. World space is y-up; the renderer flips y for the screen. Add, Sub, Neg, and Mul<f64> are implemented for the ergonomic uses (a + b, v * 0.5, etc.).

lerp(o, t) is the workhorse: linear interpolation between two points at parameter t. The demo below animates a.lerp(b, ease_in_out_cubic(phase)).

Source

#![allow(unused)]
fn main() {
use anim_core::*;

pub const DURATION: f64 = 2.0;

pub fn scene(t: f64) -> DrawList {
    let a = Vec2::new(-220.0, -60.0);
    let b = Vec2::new(220.0, 60.0);
    let phase = (t / DURATION).clamp(0.0, 1.0);
    let s = ease_in_out_cubic(phase);
    let p = a.lerp(b, s);

    // Draw the segment as a degenerate cubic (straight line: control points on the line).
    let seg = CubicBez::new(a, a.lerp(b, 1.0 / 3.0), a.lerp(b, 2.0 / 3.0), b);

    vec![
        Cmd::Stroke {
            path: seg,
            width: 2.0,
            color: Color::rgb(120, 120, 130),
        },
        Cmd::FillCircle {
            center: a,
            r: 5.0,
            color: Color::rgb(120, 120, 130),
        },
        Cmd::FillCircle {
            center: b,
            r: 5.0,
            color: Color::rgb(120, 120, 130),
        },
        Cmd::FillCircle {
            center: p,
            r: 10.0,
            color: Color::rgb(255, 127, 80),
        },
    ]
}
}