Skip to content

Instantly share code, notes, and snippets.

@tioover
Last active August 29, 2015 14:24
Show Gist options
  • Save tioover/fe8d34aa2a8ea92acf07 to your computer and use it in GitHub Desktop.
Save tioover/fe8d34aa2a8ea92acf07 to your computer and use it in GitHub Desktop.
fn curve(ms: Ms, p: [Vec2<f32>; 4]) -> State {
time_func(Timer::new(ms), box move |sprite, timer| -> Option<State> {
// Cubic Bézier curves
use num::Float;
if timer.is_out() { return Some (Static) }
let t = timer.ratio();
let r = 1.0 - t;
let a = r.powi(3);
let b = 3.0*t *r.powi(2);
let c = 3.0*t.powi(2)*r ;
let d = t.powi(3) ;
sprite.transform.position = p[0] * a + p[1] * b + p[2] * c + p[3] * d;
return None;
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment