forked from ghost-fvtt/fxmaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathease.js
75 lines (62 loc) · 1.63 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
export const easeFunctions = {
Linear: easeLinear,
InSine: easeInSine,
OutSine: easeOutSine,
InOutSine: easeInOutSine,
InBack: easeInBack,
OutBack: easeOutBack,
InOutBack: easeInOutBack,
InCubic: easeInCubic,
OutCubic: easeOutCubic,
InOutCubic: easeInOutCubic,
InCirc: easeInCirc,
OutCirc: easeOutCirc,
InOutCirc: easeInOutCirc,
};
export function easeLinear(x) {
return x;
}
export function easeInSine(x) {
return 1 - Math.cos((x * Math.PI) / 2);
}
export function easeOutSine(x) {
return Math.sin((x * Math.PI) / 2);
}
export function easeInOutSine(x) {
return -(Math.cos(Math.PI * x) - 1) / 2;
}
export function easeInBack(x) {
const c1 = 1.70158;
const c3 = c1 + 1;
return c3 * x * x * x - c1 * x * x;
}
export function easeOutBack(x) {
const c1 = 1.70158;
const c3 = c1 + 1;
return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
}
export function easeInOutBack(x) {
const c1 = 1.70158;
const c2 = c1 * 1.525;
return x < 0.5
? (Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2)) / 2
: (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2;
}
export function easeInCubic(x) {
return x * x * x;
}
export function easeOutCubic(x) {
return 1 - Math.pow(1 - x, 3);
}
export function easeInOutCubic(x) {
return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
}
export function easeInCirc(x) {
return 1 - Math.sqrt(1 - Math.pow(x, 2));
}
export function easeOutCirc(x) {
return Math.sqrt(1 - Math.pow(x - 1, 2));
}
export function easeInOutCirc(x) {
return x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
}