Last active
December 26, 2015 02:28
-
-
Save Gerhut/7078257 to your computer and use it in GitHub Desktop.
Simple Easing Method.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Easing Function f(t) where t, f(t) <- [0, 1] | |
* return an Easing Factory. | |
*/ | |
function easing(f) { | |
/** | |
* x = f(t) where x <- [x0, x1], t <- [0, t1] | |
* return an Easing Instance. | |
*/ | |
return function(x0, x1, t1) { // x = f(t), x <-[x0, x1] | |
var t = 0; | |
/** | |
* Each call returns the next value. | |
* Return null means no more value. | |
*/ | |
return function () { | |
return (t <= t1) | |
? f(t++ / t1) * (x1 - x0) + x0 | |
: null; | |
} | |
} | |
} | |
var linearFunc = function (x) { return x; } | |
, linearEasingFactory = easing(linearFunc) | |
, myEasingInstance = linearEasingFactory(5, 10, 10) | |
, x; | |
while((x = myEasingInstance()) !== null) | |
console.log(x); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment