Repository navigation
Expand file tree
/
Copy pathEasing.ts
More file actions
113 lines (102 loc) · 2.82 KB
/
Copy pathEasing.ts
File metadata and controls
113 lines (102 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/**
* Easing functions for the Tween Library
* Adapted from Flash ActionScript
* http://www.robertpenner.com/easing/penner_chapter7_tweening.pdf
*/
module Tween {
/**
* Standard linear tween.
* @param t - time *dynamic
* @param b - begin value *static
* @param c - change from b *static
* @param d - duration of tween *static
*/
export function linear(t:number, b:number, c:number, d:number):number {
return t * c / d + b;
}
export function quadratic(t:number, b:number, c:number, d:number):number {
t /= d / 2;
if (t < 1) return c / 2 * t * t + b;
t--;
return -c / 2 * (t * (t - 2) - 1) + b;
}
export function cubic(t:number, b:number, c:number, d:number):number {
t /= d / 2;
if (t < 1) return c / 2 * t * t * t + b;
t -= 2;
return c / 2 * (t * t * t + 2) + b;
}
export function quartic(t:number, b:number, c:number, d:number):number {
t /= d / 2;
if (t < 1) return c / 2 * t * t * t * t + b;
t -= 2;
return -c / 2 * (t * t * t * t - 2) + b;
}
export function quintic(t:number, b:number, c:number, d:number):number {
t /= d / 2;
if (t < 1) return c / 2 * t * t * t * t * t + b;
t -= 2;
return c / 2 * (t * t * t * t * t + 2) + b;
}
export function circuar(t:number, b:number, c:number, d:number):number {
t /= d / 2;
if (t < 1) return -c / 2 * (Math.sqrt(1 - t * t) - 1) + b;
t -= 2;
return c / 2 * (Math.sqrt(1 - t * t) + 1) + b;
}
export function sine(t:number, b:number, c:number, d:number):number {
return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b;
}
export function exponential(t:number, b:number, c:number, d:number):number {
t /= d / 2;
if (t < 1) return c / 2 * Math.pow(2, 10 * (t - 1)) + b;
t--;
return c / 2 * ( -Math.pow(2, -10 * t) + 2 ) + b;
}
/**
* Extends the input object with easing functions
* @param runtime - Runtime to extend the easing function to
*/
export function extendWithEasingFunctions(runtime:any):void {
/** TODO: Remove when BSE no longer requires this **/
var load:Object = {
linear: Tween.linear,
back: null,
bounce: null,
circular: Tween.circuar,
cubic: Tween.cubic,
elastic: null,
exponential: Tween.exponential,
sine: Tween.sine,
quintic: Tween.quintic
};
for (var i in load) {
runtime[i] = load[i];
}
}
export function getEasingFuncByName(easing:string = "None"):Function {
easing = easing.toLowerCase();
switch (easing) {
case "none":
case "linear":
default:
return Tween.linear;
case "exponential":
return Tween.exponential;
case "circular":
return Tween.circuar;
case "quadratic":
return Tween.quadratic;
case "cubic":
return Tween.cubic;
case "quartic":
return Tween.quartic;
case "quintic":
return Tween.quintic;
case "sine":
return Tween.sine;
}
}
}
/** Remove when unnecessary **/
Tween.extendWithEasingFunctions(self);