diff options
| author | jules <jules@okfoc.us> | 2014-12-16 04:13:12 -0500 |
|---|---|---|
| committer | jules <jules@okfoc.us> | 2014-12-16 04:13:12 -0500 |
| commit | bf3ba2a13ed3e97f1caabfcd04762a6a8ed5db8c (patch) | |
| tree | 37e0be1cc5170873a1be4257cb73cc30ebfbf74a | |
| parent | a36d9d57760c1b65a611316fc41a549e7882d791 (diff) | |
easing functions
| -rw-r--r-- | js/util.js | 29 |
1 files changed, 29 insertions, 0 deletions
@@ -114,3 +114,32 @@ function weave(a){ reverse(aa[1]).forEach(function(el){ b.push(el) }) return b } + +// easing functions +function circular (t) { return Math.sqrt( 1 - ( --t * t ) ) } +function quadratic (t) { return t * ( 2 - t ) } +function back (t) { + var b = 4; + return ( t = t - 1 ) * t * ( ( b + 1 ) * t + b ) + 1; +} +function bounce (t) { + if (t >= 1) return 1; + if ( ( t /= 1 ) < ( 1 / 2.75 ) ) { + return 7.5625 * t * t; + } else if ( t < ( 2 / 2.75 ) ) { + return 7.5625 * ( t -= ( 1.5 / 2.75 ) ) * t + 0.75; + } else if ( t < ( 2.5 / 2.75 ) ) { + return 7.5625 * ( t -= ( 2.25 / 2.75 ) ) * t + 0.9375; + } else { + return 7.5625 * ( t -= ( 2.625 / 2.75 ) ) * t + 0.984375; + } +} +function elastic (t) { + var f = 0.22, + e = 0.4; + + if ( t === 0 ) { return 0; } + if ( t == 1 ) { return 1; } + + return ( e * Math.pow( 2, - 10 * t ) * Math.sin( ( t - f / 4 ) * ( 2 * Math.PI ) / f ) + 1 ); +} |
