-
Notifications
You must be signed in to change notification settings - Fork 0
/
easings.js
47 lines (46 loc) · 1.14 KB
/
easings.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
//
// these easing functions are based on the code of glsl-easing module.
// https://github.com/glslify/glsl-easings
//
const ease = {
exponentialIn: (t) => {
return t == 0.0 ? t : Math.pow(2.0, 10.0 * (t - 1.0));
},
exponentialOut: (t) => {
return t == 1.0 ? t : 1.0 - Math.pow(2.0, -10.0 * t);
},
exponentialInOut: (t) => {
return t == 0.0 || t == 1.0
? t
: t < 0.5
? +0.5 * Math.pow(2.0, (20.0 * t) - 10.0)
: -0.5 * Math.pow(2.0, 10.0 - (t * 20.0)) + 1.0;
},
sineOut: (t) => {
const HALF_PI = 1.5707963267948966;
return Math.sin(t * HALF_PI);
},
circularInOut: (t) => {
return t < 0.5
? 0.5 * (1.0 - Math.sqrt(1.0 - 4.0 * t * t))
: 0.5 * (Math.sqrt((3.0 - 2.0 * t) * (2.0 * t - 1.0)) + 1.0);
},
cubicIn: (t) => {
return t * t * t;
},
cubicOut: (t) => {
const f = t - 1.0;
return f * f * f + 1.0;
},
cubicInOut: (t) => {
return t < 0.5
? 4.0 * t * t * t
: 0.5 * Math.pow(2.0 * t - 2.0, 3.0) + 1.0;
},
quadraticOut: (t) => {
return -t * (t - 2.0);
},
quarticOut: (t) => {
return Math.pow(t - 1.0, 3.0) * (1.0 - t) + 1.0;
},
}