-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ease.js
108 lines (97 loc) · 2.96 KB
/
Ease.js
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
/*
──────────────────────────────────────────
──────────────────────────────────────────
EASE
──────────────────────────────────────────
──────────────────────────────────────────
PROPERTIES
──────────
i In
o Out
io InOut
1 Sine
2 Quad
3 Cubic
4 Quart
5 Quint
6 Expo
USAGE
─────
const eased = Ease['linear'](multiplier);
*/
/**
* Ease
*
* @type {{o1: (function(*): number), linear: (function(*): *), o2: (function(*): number), o3: (function(*): number), o4: (function(*): number), o5: (function(*): number), o6: (function(*): number), i1: (function(*): number), i2: (function(*): number), io1: (function(*): number), i3: (function(*): number), i4: (function(*): number), io3: (function(*): number), i5: (function(*): number), io2: (function(*): number), i6: (function(*): number), io5: (function(*): number), io4: (function(*): number), io6: Ease.io6}}
*/
var Ease = {
linear: function (t) {
return t;
},
// Sine (Sinusoidal)
i1: function (t) {
return -Math.cos(t * (Math.PI / 2)) + 1;
},
o1: function (t) {
return Math.sin(t * (Math.PI / 2));
},
io1: function (t) {
return -0.5 * (Math.cos(Math.PI * t) - 1);
},
// Quadratic (Quad)
i2: function (t) {
return t * t;
},
o2: function (t) {
return t * (2 - t);
},
io2: function (t) {
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
},
// Cubic
i3: function (t) {
return t * t * t;
},
o3: function (t) {
return (--t) * t * t + 1;
},
io3: function (t) {
return t < 0.5 ? 4 * t * t * t : (t - 1) * (2 * t - 2) * (2 * t - 2) + 1;
},
// Quartic (Quart)
i4: function (t) {
return t * t * t * t;
},
o4: function (t) {
return 1 - (--t) * t * t * t;
},
io4: function (t) {
return t < 0.5 ? 8 * t * t * t * t : 1 - 8 * (--t) * t * t * t;
},
// Quintic (Quint)
i5: function (t) {
return t * t * t * t * t;
},
o5: function (t) {
return 1 + (--t) * t * t * t * t;
},
io5: function (t) {
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * (--t) * t * t * t * t;
},
// Exponential (Expo)
i6: function (t) {
return (t === 0) ? 0 : Math.pow(2, 10 * (t - 1));
},
o6: function (t) {
var OUT_EXPO_CORRECTION = 1.000976;
return (t === 1) ? 1 : 1 * OUT_EXPO_CORRECTION * (-Math.pow(2, -10 * t) + 1);
// return (t === 1) ? 1 : 1 - Math.pow(2, -10 * t);
},
io6: function (t) {
if (t === 0) return 0;
if (t === 1) return 1;
if ((t /= 0.5) < 1) return 0.5 * Math.pow(2, 10 * (t - 1));
return 0.5 * (-Math.pow(2, -10 * --t) + 2);
}
};
export default Ease;