export class Easing { public static linear ( ) { return function ( t ) : number { return t ; } ; } public static inQuad ( ) { return function ( t ) : number { return t * t ; } ; } public static outQuad ( ) { return function ( t ) : number { return t * ( 2 - t ) ; } ; } public static inOutQuad ( ) { return function ( t ) : number { t *= 2 ; if ( t < 1 ) return 0.5 * t * t ; return - 0.5 * ( -- t * ( t - 2 ) - 1 ) ; } ; } public static inCubic ( ) { return function ( t ) : number { return t * t * t ; } ; } public static outCubic ( ) { return function ( t ) : number { return -- t * t * t + 1 ; } ; } public static inOutCubic ( ) { return function ( t ) : number { t *= 2 ; if ( t < 1 ) return 0.5 * t * t * t ; t -= 2 ; return 0.5 * ( t * t * t + 2 ) ; } ; } public static inQuart ( ) { return function ( t ) : number { return t * t * t * t ; } ; } public static outQuart ( ) { return function ( t ) : number { return 1 - -- t * t * t * t ; } ; } public static inOutQuart ( ) { return function ( t ) : number { t *= 2 ; if ( t < 1 ) return 0.5 * t * t * t * t ; t -= 2 ; return - 0.5 * ( t * t * t * t - 2 ) ; } ; } public static inQuint ( ) { return function ( t ) : number { return t * t * t * t * t ; } ; } public static outQuint ( ) { return function ( t ) : number { return -- t * t * t * t * t + 1 ; } ; } public static inOutQuint ( ) { return function ( t ) : number { t *= 2 ; if ( t < 1 ) return 0.5 * t * t * t * t * t ; t -= 2 ; return 0.5 * ( t * t * t * t * t + 2 ) ; } ; } public static inSine ( ) { return function ( t ) : number { return 1 - Math . cos ( ( t * Math . PI ) / 2 ) ; } ; } public static outSine ( ) { return function ( t ) : number { return Math . sin ( ( t * Math . PI ) / 2 ) ; } ; } public static inOutSine ( ) { return function ( t ) : number { return 0.5 * ( 1 - Math . cos ( Math . PI * t ) ) ; } ; } public static inExpo ( ) { return function ( t ) : number { return t === 0 ? 0 : Math . pow ( 1024 , t - 1 ) ; } ; } public static outExpo ( ) { return function ( t ) : number { return t === 1 ? 1 : 1 - Math . pow ( 2 , - 10 * t ) ; } ; } public static inOutExpo ( ) { return function ( t ) : number { if ( t === 0 ) return 0 ; if ( t === 1 ) return 1 ; t *= 2 ; if ( t < 1 ) return 0.5 * Math . pow ( 1024 , t - 1 ) ; return 0.5 * ( - Math . pow ( 2 , - 10 * ( t - 1 ) ) + 2 ) ; } ; } public static inCirc ( ) { return function ( t ) : number { return 1 - Math . sqrt ( 1 - t * t ) ; } ; } public static outCirc ( ) { return function ( t ) : number { return Math . sqrt ( 1 - -- t * t ) ; } ; } public static inOutCirc ( ) { return function ( t ) : number { t *= 2 ; if ( t < 1 ) return - 0.5 * ( Math . sqrt ( 1 - t * t ) - 1 ) ; return 0.5 * ( Math . sqrt ( 1 - ( t - 2 ) * ( t - 2 ) ) + 1 ) ; } ; } public static inElastic ( a = 0.1 , p = 0.4 ) { return function ( t ) : number { let s ; if ( t === 0 ) return 0 ; if ( t === 1 ) return 1 ; if ( ! a || a < 1 ) { a = 1 ; s = p / 4 ; } else s = ( p * Math . asin ( 1 / a ) ) / ( 2 * Math . PI ) ; return - ( a * Math . pow ( 2 , 10 * ( t - 1 ) ) * Math . sin ( ( ( t - 1 - s ) * ( 2 * Math . PI ) ) / p ) ) ; } ; } public static outElastic ( a = 0.1 , p = 0.4 ) { return function ( t ) : number { let s ; if ( t === 0 ) return 0 ; if ( t === 1 ) return 1 ; if ( ! a || a < 1 ) { a = 1 ; s = p / 4 ; } else s = ( p * Math . asin ( 1 / a ) ) / ( 2 * Math . PI ) ; return ( a * Math . pow ( 2 , - 10 * t ) * Math . sin ( ( ( t - s ) * ( 2 * Math . PI ) ) / p ) + 1 ) ; } ; } public static inOutElastic ( a = 0.1 , p = 0.4 ) { return function ( t ) : number { let s ; if ( t === 0 ) return 0 ; if ( t === 1 ) return 1 ; if ( ! a || a < 1 ) { a = 1 ; s = p / 4 ; } else s = ( p * Math . asin ( 1 / a ) ) / ( 2 * Math . PI ) ; t *= 2 ; if ( t < 1 ) return ( - 0.5 * ( a * Math . pow ( 2 , 10 * ( t - 1 ) ) * Math . sin ( ( ( t - 1 - s ) * ( 2 * Math . PI ) ) / p ) ) ) ; return ( a * Math . pow ( 2 , - 10 * ( t - 1 ) ) * Math . sin ( ( ( t - 1 - s ) * ( 2 * Math . PI ) ) / p ) * 0.5 + 1 ) ; } ; } public static inBack ( v ? ) { return function ( t ) : number { let s = v || 1.70158 ; return t * t * ( ( s + 1 ) * t - s ) ; } ; } public static outBack ( v ? ) { return function ( t ) : number { let s = v || 1.70158 ; return -- t * t * ( ( s + 1 ) * t + s ) + 1 ; } ; } public static inOutBack ( v ? ) { return function ( t ) : number { let s = ( v || 1.70158 ) * 1.525 ; t *= 2 ; if ( t < 1 ) return 0.5 * ( t * t * ( ( s + 1 ) * t - s ) ) ; return 0.5 * ( ( t - 2 ) * ( t - 2 ) * ( ( s + 1 ) * ( t - 2 ) + s ) + 2 ) ; } ; } public static inBounce ( ) { return function ( t ) : number { return 1 - Easing . outBounce ( ) ( 1 - t ) ; } ; } public static outBounce ( ) { return function ( t ) : number { if ( t < 1 / 2.75 ) { return 7.5625 * t * t ; } else if ( t < 2 / 2.75 ) { t = t - 1.5 / 2.75 ; return 7.5625 * t * t + 0.75 ; } else if ( t < 2.5 / 2.75 ) { t = t - 2.25 / 2.75 ; return 7.5625 * t * t + 0.9375 ; } else { t -= 2.625 / 2.75 ; return 7.5625 * t * t + 0.984375 ; } } ; } public static inOutBounce ( ) { return function ( t ) : number { if ( t < 0.5 ) return Easing . inBounce ( ) ( t * 2 ) * 0.5 ; return Easing . outBounce ( ) ( t * 2 - 1 ) * 0.5 + 0.5 ; } ; } }