47 lines
1.3 KiB
C#
Executable File
47 lines
1.3 KiB
C#
Executable File
using System.Drawing;
|
|
using System.Numerics;
|
|
|
|
namespace DaggerFramework
|
|
{
|
|
public static class MathUtils
|
|
{
|
|
public static float Lerp(float a, float b, double t) => a + (b - a) * (float)t;
|
|
|
|
public static Color LerpColor(Color colorA, Color colorB, double t)
|
|
{
|
|
var r = (byte)Lerp(colorA.R, colorB.R, t);
|
|
var g = (byte)Lerp(colorA.G, colorB.G, t);
|
|
var b = (byte)Lerp(colorA.B, colorB.B, t);
|
|
var a = (byte)Lerp(colorA.A, colorB.A, t);
|
|
|
|
return new Color(r, g, b, a);
|
|
}
|
|
|
|
public static Vector2 LerpVector2(Vector2 v1, Vector2 v2, double t)
|
|
{
|
|
var x = Lerp(v1.X, v2.X, t);
|
|
var y = Lerp(v1.X, v2.Y, t);
|
|
|
|
return new Vector2(x, y);
|
|
}
|
|
|
|
public static float EaseOutBack(float x)
|
|
{
|
|
var c1 = 1.70158f;
|
|
var c3 = c1 + 1f;
|
|
|
|
return 1f + c3 * (float)Math.Pow(x - 1f, 3f) + c1 * (float)Math.Pow(x - 1, 2);
|
|
}
|
|
|
|
public static float EaseOutElastic(float x)
|
|
{
|
|
var c4 = (2f * (float)Math.PI) / 3f;
|
|
|
|
return x == 0
|
|
? 0
|
|
: x == 1
|
|
? 1
|
|
: (float)Math.Pow(2, -10 * x) * (float)Math.Sin((x * 10 - 0.75f) * c4) + 1;
|
|
}
|
|
}
|
|
} |