-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathEasing.cs
More file actions
53 lines (37 loc) · 1.76 KB
/
Copy pathEasing.cs
File metadata and controls
53 lines (37 loc) · 1.76 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
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
namespace Microsoft.Maui.Platform.Linux;
public class Easing
{
private readonly Func<double, double> _easingFunc;
public static readonly Easing Linear = new(v => v);
public static readonly Easing SinIn = new(v => 1.0 - Math.Cos(v * Math.PI / 2.0));
public static readonly Easing SinOut = new(v => Math.Sin(v * Math.PI / 2.0));
public static readonly Easing SinInOut = new(v => -(Math.Cos(Math.PI * v) - 1.0) / 2.0);
public static readonly Easing CubicIn = new(v => v * v * v);
public static readonly Easing CubicOut = new(v => 1.0 - Math.Pow(1.0 - v, 3.0));
public static readonly Easing CubicInOut = new(v =>
v < 0.5 ? 4.0 * v * v * v : 1.0 - Math.Pow(-2.0 * v + 2.0, 3.0) / 2.0);
// BounceOut must be declared before BounceIn since BounceIn references it
public static readonly Easing BounceOut = new(v =>
{
const double n1 = 7.5625;
const double d1 = 2.75;
if (v < 1 / d1)
return n1 * v * v;
if (v < 2 / d1)
return n1 * (v -= 1.5 / d1) * v + 0.75;
if (v < 2.5 / d1)
return n1 * (v -= 2.25 / d1) * v + 0.9375;
return n1 * (v -= 2.625 / d1) * v + 0.984375;
});
public static readonly Easing BounceIn = new(v => 1.0 - BounceOut.Ease(1.0 - v));
public static readonly Easing SpringIn = new(v => v * v * (2.70158 * v - 1.70158));
public static readonly Easing SpringOut = new(v =>
(v - 1.0) * (v - 1.0) * (2.70158 * (v - 1.0) + 1.70158) + 1.0);
public Easing(Func<double, double> easingFunc)
{
_easingFunc = easingFunc;
}
public double Ease(double v) => _easingFunc(v);
}