-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEasingFloat.cs
More file actions
248 lines (210 loc) · 6.45 KB
/
EasingFloat.cs
File metadata and controls
248 lines (210 loc) · 6.45 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
/*
* Package: Easing
* Author: Michel Fedde
*
* This class implements the different easing function.
* While I may be the author of this class, the actual formulas I got from https://easings.net/#.
*
* LICENSE:
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
namespace Easing;
public static partial class Easing
{
private const float F_C1 = 1.70158f;
private const float F_C2 = Easing.F_C1 + 1.525f;
private const float F_C3 = Easing.F_C1 + 1f;
private const float F_C4 = (2 * MathF.PI) / 3;
private const float F_C5 = (2 * MathF.PI) / 4.5f;
private const float F_N1 = 7.5625f;
private const float F_D1 = 2.75f;
#region | Ease In |
public static float InSine(float x)
{
return 1 - MathF.Cos((x * MathF.PI) / 2);
}
public static float InQuad(float x)
{
return x * x;
}
public static float InCubic(float x)
{
return x * x * x;
}
public static float InQuart(float x)
{
return x * x * x * x;
}
public static float InQuint(float x)
{
return x * x * x * x * x;
}
public static float InExpo(float x)
{
return x == 0 ? 0 : MathF.Pow(2, 10 * x - 10);
}
public static float InCirc(float x)
{
return 1 - MathF.Sqrt(1 - (x * x));
}
public static float InBack(float x)
{
return Easing.F_C3 * x * x * x - Easing.F_C1 * x * x;
}
public static float InElastic(float x)
{
if (x == 0)
{
return 0;
}
if (x >= 1)
{
return 1;
}
return -MathF.Pow(2, 10 * x - 10) * MathF.Sin((x * 10 - 10.75f) * Easing.F_C4);
}
public static float InBounce(float x)
{
return 1 - Easing.OutBounce(1 - x);
}
#endregion
#region | Ease Out |
public static float OutSine(float x)
{
return MathF.Sin((x * MathF.PI) / 2);
}
public static float OutQuad(float x)
{
return 1 - (1 - x) * (1 - x);
}
public static float OutCubic(float x)
{
return 1 - (1 - x) * (1 - x) * (1 - x);
}
public static float OutQuat(float x)
{
return 1 - (1 - x) * (1 - x) * (1 - x) * (1 - x);
}
public static float OutQuint(float x)
{
return 1 - (1 - x) * (1 - x) * (1 - x) * (1 - x) * (1 - x);
}
public static float OutExpo(float x)
{
return x >= 1 ? 1 : 1 - MathF.Pow(2, -10 * x);
}
public static float OutCirc(float x)
{
return MathF.Sqrt(1 - MathF.Pow(x - 1, 2));
}
public static float OutBack(float x)
{
return 1 + Easing.F_C3 * (x - 1) * (x - 1) * (x - 1) + Easing.F_C1 * (x - 1) * (x - 1);
}
public static float OutElastic(float x)
{
if (x == 0)
{
return 0;
}
if (x >= 1)
{
return 1;
}
return MathF.Pow(2, -10 * x) * MathF.Sin((x * 10 - 0.75f) * Easing.F_C4) + 1;
}
public static float OutBounce(float x)
{
if (x < 1 / Easing.F_D1)
{
return Easing.F_N1 * x * x;
}
if (x < 2 / Easing.F_D1)
{
x -= 1.5f / Easing.F_D1;
return Easing.F_N1 * x * x + 0.75f;
}
if (x < 2.5 / Easing.F_D1)
{
x -= 2.25f / Easing.F_D1;
return Easing.F_N1 * x * x + 0.9375f;
}
x -= 2.625f / Easing.F_D1;
return Easing.F_N1 * x * x + 0.984375f;
}
#endregion
#region InOut
public static float InOutSine(float x)
{
return -(MathF.Cos(MathF.PI * x) - 1) / 2;
}
public static float InOutQuad(float x)
{
return x < 0.5 ? 2 * x * x : 1 - MathF.Pow(-2 * x + 2, 2) / 2;
}
public static float InOutCubic(float x)
{
return x < 0.5 ? 4 * x * x * x : 1 - MathF.Pow(-2 * x + 2, 3) / 2;
}
public static float InOutQuart(float x)
{
return x < 0.5 ? 8 * x * x * x * x : 1 - MathF.Pow(-2 * x + 2, 4) / 2;
}
public static float InOutQuint(float x)
{
return x < 0.5 ? 16 * x * x * x * x * x : 1 - MathF.Pow(-2 * x + 2, 5) / 2;
}
public static float InOutExpo(float x)
{
if (x == 0)
{
return 0;
}
if (x >= 1)
{
return 1;
}
return x < 0.5 ? MathF.Pow(2, 20 * x - 10) / 2 : (2 - MathF.Pow(2, -20 * x + 10)) / 2;
}
public static float InOutCirc(float x)
{
return x < 0.5
? (1 - MathF.Sqrt(1 - MathF.Pow(2 * x, 2))) / 2
: (MathF.Sqrt(1 - MathF.Pow(-2 * x + 2, 2)) + 1) / 2;
}
public static float InOutBack(float x)
{
if (x < 0.5)
{
return (MathF.Pow(2 * x, 2) * ((Easing.F_C2 + 1) * 2 * x - Easing.F_C2)) / 2;
}
return (MathF.Pow(2 * x - 2, 2) * ((Easing.F_C2 + 1) * (x * 2 - 2) + Easing.F_C2) + 2) / 2;
}
public static float InOutElastic(float x)
{
if (x == 0)
{
return 0;
}
if (x >= 1)
{
return 1;
}
if (x < 0.5)
{
return -(MathF.Pow(2, 20 * x - 10) * MathF.Sin((20 * x - 11.125f) * Easing.F_C5)) / 2;
}
return (MathF.Pow(2, -20 * x + 10) * MathF.Sin((20 * x - 11.125f) * Easing.F_C5)) / 2 + 1;
}
public static float InOutBounce(float x)
{
return x < 0.5
? (1 - OutBounce(1 - 2 * x)) / 2
: (1 + OutBounce(2 * x - 1)) / 2;
}
#endregion
}