-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy patheasing.js
More file actions
141 lines (96 loc) · 2.34 KB
/
easing.js
File metadata and controls
141 lines (96 loc) · 2.34 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
Penner's easing equations adapted to accept a single normalised alpha value
---
a Number 'alpha' value (from 0-1)
---
Returns Number Normalised value with easing applied
*/
// Linear
// ------
export function linear ( a ) {
return a
}
// Sine
// ----
export function easeInSine ( a ) {
return -1 * Math.cos( a * ( Math.PI / 2 ) ) + 1
}
export function easeOutSine ( a ) {
return 1 * Math.sin( a * ( Math.PI / 2 ) )
}
export function easeInOutSine ( a ) {
return -0.5 * ( Math.cos( Math.PI * a / 1 ) - 1 )
}
// Quad
// ----
export function easeInQuad ( a ) {
return a * a
}
export function easeOutQuad ( a ) {
return -1 * a * ( a - 2 )
}
export function easeInOutQuad ( a ) {
a /= 0.5
if ( a < 1 ) return 0.5 * a * a
a--
return -0.5 * ( a * ( a - 2 ) - 1 )
}
// Cubic
// -----
export function easeInCubic ( a ) {
return a * a * a
}
export function easeOutCubic ( a ) {
a--
return ( a * a * a + 1 )
}
export function easeInOutCubic ( a ) {
a /= 0.5
if ( a < 1 ) return 0.5 * a * a * a
a -= 2
return 0.5 * ( a * a * a + 2 )
}
// Quart
// -----
export function easeInQuart ( a ) {
return a * a * a * a
}
export function easeOutQuart ( a ) {
a--
return -1 * ( a * a * a * a - 1 )
}
export function easeInOutQuart ( a ) {
a /= 0.5
if ( a < 1 ) return 0.5 * a * a * a * a
a -= 2
return -0.5 * ( a * a * a * a - 2 )
}
// Quint
// -----
export function easeInQuint ( a ) {
return a * a * a * a * a
}
export function easeOutQuint ( a ) {
a--
return a * a * a * a * a + 1
}
export function easeInOutQuint ( a ) {
a /= 0.5
if ( a < 1 ) return 0.5 * a * a * a * a * a
a -= 2
return 0.5 * ( a * a * a * a * a + 2 )
}
// Expo
// ----
export function easeInExpo ( a ) {
return Math.pow( 2, 10 * ( a - 1 ) )
}
export function easeOutExpo ( a ) {
return -Math.pow( 2, -10 * a ) + 1
}
export function easeInOutExpo ( a ) {
a /= 0.5
if ( a < 1 ) return 0.5 * Math.pow( 2, 10 * ( a - 1 ) )
a--
return 0.5 * ( -Math.pow( 2, -10 * a ) + 2 )
}