Skip to content

Instantly share code, notes, and snippets.

@SharpCoder
Created March 14, 2022 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SharpCoder/aedcb5456450b3f90a6298031ef15e9f to your computer and use it in GitHub Desktop.
Save SharpCoder/aedcb5456450b3f90a6298031ef15e9f to your computer and use it in GitHub Desktop.
Basic interpolation method written in rust
pub fn interpolate(start: u32, end: u32, elapsed: u64, duration: u64) -> u32 {
// Calculate step
let x0 = 0f32;
let y0 = min(start, end) as f32;
let x1 = duration as f32;
let y1 = max(end, start) as f32;
let x = min(elapsed, duration) as f32;
let delta = (x * ((y1 - y0)/(x1 - x0))) as u32;
if start > end {
return start - delta;
} else {
return start + delta;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment