-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEasing.cs
More file actions
62 lines (49 loc) · 1.64 KB
/
Copy pathEasing.cs
File metadata and controls
62 lines (49 loc) · 1.64 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
using System;
namespace Tween
{
public static class Easing
{
private static Random random = new Random();
public static float Linear(TweenBase t) => t.NormalizedTime;
public static float QuadIn(TweenBase t) => t.NormalizedTime * t.NormalizedTime;
public static float QuadOut(TweenBase t) => t.NormalizedTime * (2 - t.NormalizedTime);
public static float QuadInOut(TweenBase t)
{
var n = t.NormalizedTime;
if (n < 0.5f) return 2 * n * n;
return -1 + (4 - 2 * n) * n;
}
public static float QuadInOutLoop(TweenBase t)
{
var n = t.NormalizedTime;
if (n < 0.5f)
{
return 4 * n * n;
}
else
{
float t2 = (n - 0.5f) * 2;
return (1 - t2 * (2 - t2));
}
}
public static float RandomShake(TweenBase t)
{
var n = t.NormalizedTime;
//p1 = frequency
//p2 = amplitude
if (n >= 1f) return 0f;
float envelope = (1 - n) * (4 * n * (1 - n));
float noise = (float)(random.NextDouble() * 2 - 1);
return noise * t.Parameter2 * envelope * t.Parameter1;
}
// public static float RandomShakeFull(TweenBase t)
// {
// return RandomShake(frequency: 5f, amplitude: 2f)(t);
// }
public static float ParabolicUp(TweenBase t)
{
//p1 = peak height
return -4 * t.Parameter1 * (t.NormalizedTime - 0.5f) * (t.NormalizedTime - 0.5f) + t.Parameter1;
}
}
}