Skip to content

Instantly share code, notes, and snippets.

Created March 4, 2015 19:24
Show Gist options
  • Save anonymous/1e8523b038cd11e1e483 to your computer and use it in GitHub Desktop.
Save anonymous/1e8523b038cd11e1e483 to your computer and use it in GitHub Desktop.
Linear Interpolated Array
var a = [1,2,3,4,9,20];
a.lerp = function(n){
var a = this[Math.floor(n)];
//console.log("a: " + a);
var b = this[Math.ceil(n)];
//console.log("b: " + b);
var t = n-Math.floor(n);
//console.log("t: " + t);
return (1-t)*a + t*b;
}
console.log(a.lerp(4.5))
//could be expanded to bezier, maybe b splines too.
//The idea was to have a[4.5] be an alias for a.lerp(4.5)
//but I suppose this works...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment