|
| 1 | +export type TEasing = (time: number) => number; |
| 2 | + |
| 3 | +export interface IEasingMap { |
| 4 | + linear: TEasing; |
| 5 | + inQuad: TEasing; |
| 6 | + outQuad: TEasing; |
| 7 | + inOutQuad: TEasing; |
| 8 | + inCubic: TEasing; |
| 9 | + outCubic: TEasing; |
| 10 | + inOutCubic: TEasing; |
| 11 | + inQuart: TEasing; |
| 12 | + outQuart: TEasing; |
| 13 | + inOutQuart: TEasing; |
| 14 | + inQuint: TEasing; |
| 15 | + outQuint: TEasing; |
| 16 | + inOutQuint: TEasing; |
| 17 | +} |
| 18 | + |
| 19 | +// From: https://gist.github.com/gre/1650294 |
| 20 | +export const easing: IEasingMap = { |
| 21 | + // no easing, no acceleration |
| 22 | + linear: (t) => t, |
| 23 | + |
| 24 | + // accelerating from zero velocity |
| 25 | + inQuad: (t) => t*t, |
| 26 | + |
| 27 | + // decelerating to zero velocity |
| 28 | + outQuad: (t) => t*(2-t), |
| 29 | + |
| 30 | + // acceleration until halfway, then deceleration |
| 31 | + inOutQuad: (t) => t<.5 ? 2*t*t : -1+(4-2*t)*t, |
| 32 | + |
| 33 | + // accelerating from zero velocity |
| 34 | + inCubic: (t) => t*t*t, |
| 35 | + |
| 36 | + // decelerating to zero velocity |
| 37 | + outCubic: (t) => (--t)*t*t+1, |
| 38 | + |
| 39 | + // acceleration until halfway, then deceleration |
| 40 | + inOutCubic: (t) => t<.5 ? 4*t*t*t : (t-1)*(2*t-2)*(2*t-2)+1, |
| 41 | + |
| 42 | + // accelerating from zero velocity |
| 43 | + inQuart: (t) => t*t*t*t, |
| 44 | + |
| 45 | + // decelerating to zero velocity |
| 46 | + outQuart: (t) => 1-(--t)*t*t*t, |
| 47 | + |
| 48 | + // acceleration until halfway, then deceleration |
| 49 | + inOutQuart: (t) => t<.5 ? 8*t*t*t*t : 1-8*(--t)*t*t*t, |
| 50 | + |
| 51 | + // accelerating from zero velocity |
| 52 | + inQuint: (t) => t*t*t*t*t, |
| 53 | + |
| 54 | + // decelerating to zero velocity |
| 55 | + outQuint: (t) => 1+(--t)*t*t*t*t, |
| 56 | + |
| 57 | + // acceleration until halfway, then deceleration |
| 58 | + inOutQuint: (t) => t<.5 ? 16*t*t*t*t*t : 1+16*(--t)*t*t*t*t |
| 59 | +}; |
0 commit comments