2019-10-30 00:03:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
2020-02-20 23:29:57 +00:00
|
|
|
|
namespace MoonTools
|
2019-10-30 00:03:51 +00:00
|
|
|
|
{
|
|
|
|
|
public static class Easing
|
|
|
|
|
{
|
2019-10-30 00:30:34 +00:00
|
|
|
|
// argument checker
|
|
|
|
|
|
2019-10-30 00:03:51 +00:00
|
|
|
|
private static void CheckTime(float time, float duration)
|
|
|
|
|
{
|
|
|
|
|
if (time > duration) { throw new ArgumentException($"{time} is invalid. Must be less than {duration}."); }
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 00:30:34 +00:00
|
|
|
|
private static void CheckTime(double time, double duration)
|
|
|
|
|
{
|
|
|
|
|
if (time > duration) { throw new ArgumentException($"{time} is invalid. Must be less than {duration}."); }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// function transformations
|
2019-10-30 00:03:51 +00:00
|
|
|
|
private static float NormalizedTime(Func<float, float, float, float, float> easingFunction, float t) => easingFunction(t, 0, 1, 1);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
private static float TimeRange(Func<float, float> easingFunction, float time, float start, float end) => start + ((end - start) * easingFunction((time - start) / (end - start)));
|
2019-10-30 00:03:51 +00:00
|
|
|
|
|
2019-10-31 01:17:02 +00:00
|
|
|
|
private static float OutIn(Func<float, float, float, float, float> outFunc,
|
|
|
|
|
Func<float, float, float, float, float> inFunc,
|
|
|
|
|
float t,
|
|
|
|
|
float b,
|
|
|
|
|
float c,
|
|
|
|
|
float d)
|
|
|
|
|
{
|
|
|
|
|
if (t < d / 2)
|
|
|
|
|
{
|
|
|
|
|
return outFunc(t * 2, b, c / 2, d);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return inFunc((t * 2) - d, b + (c / 2), c / 2, d);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 00:30:34 +00:00
|
|
|
|
private static double NormalizedTime(Func<double, double, double, double, double> easingFunction, double t) => easingFunction(t, 0, 1, 1);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
private static double TimeRange(Func<double, double> easingFunction, double time, double start, double end) => start + ((end - start) * easingFunction((time - start) / (end - start)));
|
2019-10-30 00:30:34 +00:00
|
|
|
|
|
2019-10-31 01:17:02 +00:00
|
|
|
|
private static double OutIn(Func<double, double, double, double, double> outFunc,
|
|
|
|
|
Func<double, double, double, double, double> inFunc,
|
|
|
|
|
double t,
|
|
|
|
|
double b,
|
|
|
|
|
double c,
|
|
|
|
|
double d)
|
|
|
|
|
{
|
|
|
|
|
if (t < d / 2)
|
|
|
|
|
{
|
|
|
|
|
return outFunc(t * 2, b, c / 2, d);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return inFunc((t * 2) - d, b + (c / 2), c / 2, d);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 00:30:34 +00:00
|
|
|
|
/********* EASING FUNCTIONS ********/
|
|
|
|
|
|
|
|
|
|
// LINEAR
|
|
|
|
|
|
2019-10-30 00:03:51 +00:00
|
|
|
|
public static float Linear(float t) => NormalizedTime(Linear, t);
|
|
|
|
|
public static float Linear(float time, float start, float end) => TimeRange(Linear, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float Linear(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c * t / d) + b;
|
2019-10-30 00:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 00:30:34 +00:00
|
|
|
|
public static double Linear(double t) => NormalizedTime(Linear, t);
|
|
|
|
|
public static double Linear(double time, double start, double end) => TimeRange(Linear, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double Linear(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c * t / d) + b;
|
2019-10-30 00:30:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN QUAD
|
|
|
|
|
|
2019-10-30 00:03:51 +00:00
|
|
|
|
public static float InQuad(float t) => NormalizedTime(InQuad, t);
|
|
|
|
|
public static float InQuad(float time, float start, float end) => TimeRange(InQuad, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float InQuad(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (c * (t * t)) + b;
|
2019-10-30 00:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 00:30:34 +00:00
|
|
|
|
public static double InQuad(double t) => NormalizedTime(InQuad, t);
|
|
|
|
|
public static double InQuad(double time, double start, double end) => TimeRange(InQuad, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InQuad(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (c * (t * t)) + b;
|
2019-10-30 00:30:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT QUAD
|
|
|
|
|
|
2019-10-30 00:03:51 +00:00
|
|
|
|
public static float OutQuad(float t) => NormalizedTime(OutQuad, t);
|
|
|
|
|
public static float OutQuad(float time, float start, float end) => TimeRange(OutQuad, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float OutQuad(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (-c * t * (t - 2)) + b;
|
2019-10-30 00:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-10-30 00:30:34 +00:00
|
|
|
|
public static double OutQuad(double t) => NormalizedTime(OutQuad, t);
|
|
|
|
|
public static double OutQuad(double time, double start, double end) => TimeRange(OutQuad, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double OutQuad(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (-c * t * (t - 2)) + b;
|
2019-10-30 00:30:34 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN OUT QUAD
|
|
|
|
|
|
2019-10-30 00:03:51 +00:00
|
|
|
|
public static float InOutQuad(float t) => NormalizedTime(InOutQuad, t);
|
|
|
|
|
public static float InOutQuad(float time, float start, float end) => TimeRange(InOutQuad, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float InOutQuad(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c / 2 * (t * t)) + b;
|
2019-10-30 00:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (-c / 2 * (((t - 1) * (t - 3)) - 1)) + b;
|
2019-10-30 00:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-30 00:30:34 +00:00
|
|
|
|
|
|
|
|
|
public static double InOutQuad(double t) => NormalizedTime(InOutQuad, t);
|
|
|
|
|
public static double InOutQuad(double time, double start, double end) => TimeRange(InOutQuad, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InOutQuad(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c / 2 * (t * t)) + b;
|
2019-10-30 00:30:34 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (-c / 2 * (((t - 1) * (t - 3)) - 1)) + b;
|
2019-10-30 00:30:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-30 00:38:04 +00:00
|
|
|
|
|
|
|
|
|
// OUT IN QUAD
|
|
|
|
|
|
|
|
|
|
public static float OutInQuad(float t) => NormalizedTime(OutInQuad, t);
|
|
|
|
|
public static float OutInQuad(float time, float start, float end) => TimeRange(OutInQuad, time, start, end);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
public static float OutInQuad(float t, float b, float c, float d) => OutIn(OutQuad, InQuad, t, b, c, d);
|
2019-10-30 00:38:04 +00:00
|
|
|
|
|
|
|
|
|
public static double OutInQuad(double t) => NormalizedTime(OutInQuad, t);
|
|
|
|
|
public static double OutInQuad(double time, double start, double end) => TimeRange(OutInQuad, time, start, end);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
public static double OutInQuad(double t, double b, double c, double d) => OutIn(OutQuad, InQuad, t, b, c, d);
|
2019-10-30 00:57:24 +00:00
|
|
|
|
|
|
|
|
|
// IN CUBIC
|
|
|
|
|
|
|
|
|
|
public static float InCubic(float t) => NormalizedTime(InCubic, t);
|
|
|
|
|
public static float InCubic(float time, float start, float end) => TimeRange(InCubic, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float InCubic(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (c * (t * t * t)) + b;
|
2019-10-30 00:57:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double InCubic(double t) => NormalizedTime(InCubic, t);
|
|
|
|
|
public static double InCubic(double time, double start, double end) => TimeRange(InCubic, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InCubic(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (c * (t * t * t)) + b;
|
2019-10-30 00:57:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT CUBIC
|
|
|
|
|
|
|
|
|
|
public static float OutCubic(float t) => NormalizedTime(OutCubic, t);
|
|
|
|
|
public static float OutCubic(float time, float start, float end) => TimeRange(OutCubic, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float OutCubic(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t = (t / d) - 1;
|
|
|
|
|
return (c * ((t * t * t) + 1)) + b;
|
2019-10-30 00:57:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double OutCubic(double t) => NormalizedTime(OutCubic, t);
|
|
|
|
|
public static double OutCubic(double time, double start, double end) => TimeRange(OutCubic, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double OutCubic(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t = (t / d) - 1;
|
|
|
|
|
return (c * ((t * t * t) + 1)) + b;
|
2019-10-30 00:57:24 +00:00
|
|
|
|
}
|
2019-10-30 02:45:08 +00:00
|
|
|
|
|
|
|
|
|
// IN OUT CUBIC
|
|
|
|
|
|
|
|
|
|
public static float InOutCubic(float t) => NormalizedTime(InOutCubic, t);
|
|
|
|
|
public static float InOutCubic(float time, float start, float end) => TimeRange(InOutCubic, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float InOutCubic(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c / 2 * t * t * t) + b;
|
2019-10-30 02:45:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= 2;
|
|
|
|
|
return (c / 2 * ((t * t * t) + 2)) + b;
|
2019-10-30 02:45:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN OUT CUBIC
|
|
|
|
|
|
|
|
|
|
public static double InOutCubic(double t) => NormalizedTime(InOutCubic, t);
|
|
|
|
|
public static double InOutCubic(double time, double start, double end) => TimeRange(InOutCubic, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InOutCubic(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c / 2 * t * t * t) + b;
|
2019-10-30 02:45:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= 2;
|
|
|
|
|
return (c / 2 * ((t * t * t) + 2)) + b;
|
2019-10-30 02:45:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT IN CUBIC
|
|
|
|
|
|
|
|
|
|
public static float OutInCubic(float t) => NormalizedTime(OutInCubic, t);
|
|
|
|
|
public static float OutInCubic(float time, float start, float end) => TimeRange(OutInCubic, time, start, end);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
public static float OutInCubic(float t, float b, float c, float d) => OutIn(OutCubic, InCubic, t, b, c, d);
|
2019-10-30 02:45:08 +00:00
|
|
|
|
|
|
|
|
|
public static double OutInCubic(double t) => NormalizedTime(OutInCubic, t);
|
|
|
|
|
public static double OutInCubic(double time, double start, double end) => TimeRange(OutInCubic, time, start, end);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
public static double OutInCubic(double t, double b, double c, double d) => OutIn(OutCubic, InCubic, t, b, c, d);
|
2019-10-30 23:24:47 +00:00
|
|
|
|
|
|
|
|
|
// IN QUARTIC
|
|
|
|
|
|
|
|
|
|
public static float InQuart(float t) => NormalizedTime(InQuart, t);
|
|
|
|
|
public static float InQuart(float time, float start, float end) => TimeRange(InQuart, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float InQuart(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (c * (t * t * t * t)) + b;
|
2019-10-30 23:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double InQuart(double t) => NormalizedTime(InQuart, t);
|
|
|
|
|
public static double InQuart(double time, double start, double end) => TimeRange(InQuart, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InQuart(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (c * (t * t * t * t)) + b;
|
2019-10-30 23:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT QUARTIC
|
|
|
|
|
|
|
|
|
|
public static float OutQuart(float t) => NormalizedTime(OutQuart, t);
|
|
|
|
|
public static float OutQuart(float time, float start, float end) => TimeRange(OutQuart, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float OutQuart(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t = (t / d) - 1;
|
|
|
|
|
return (-c * ((t * t * t * t) - 1)) + b;
|
2019-10-30 23:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double OutQuart(double t) => NormalizedTime(OutQuart, t);
|
|
|
|
|
public static double OutQuart(double time, double start, double end) => TimeRange(OutQuart, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double OutQuart(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t = (t / d) - 1;
|
|
|
|
|
return (-c * ((t * t * t * t) - 1)) + b;
|
2019-10-30 23:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN OUT QUARTIC
|
|
|
|
|
|
|
|
|
|
public static float InOutQuart(float t) => NormalizedTime(InOutQuart, t);
|
|
|
|
|
public static float InOutQuart(float time, float start, float end) => TimeRange(InOutQuart, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float InOutQuart(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c / 2 * (t * t * t * t)) + b;
|
2019-10-30 23:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= 2;
|
|
|
|
|
return (-c / 2 * ((t * t * t * t) - 2)) + b;
|
2019-10-30 23:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double InOutQuart(double t) => NormalizedTime(InOutQuart, t);
|
|
|
|
|
public static double InOutQuart(double time, double start, double end) => TimeRange(InOutQuart, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InOutQuart(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c / 2 * (t * t * t * t)) + b;
|
2019-10-30 23:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= 2;
|
|
|
|
|
return (-c / 2 * ((t * t * t * t) - 2)) + b;
|
2019-10-30 23:24:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT IN QUARTIC
|
|
|
|
|
|
|
|
|
|
public static float OutInQuart(float t) => NormalizedTime(OutInQuart, t);
|
|
|
|
|
public static float OutInQuart(float time, float start, float end) => TimeRange(OutInQuart, time, start, end);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
public static float OutInQuart(float t, float b, float c, float d) => OutIn(OutQuart, InQuart, t, b, c, d);
|
2019-10-30 23:24:47 +00:00
|
|
|
|
|
|
|
|
|
public static double OutInQuart(double t) => NormalizedTime(OutInQuart, t);
|
|
|
|
|
public static double OutInQuart(double time, double start, double end) => TimeRange(OutInQuart, time, start, end);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
public static double OutInQuart(double t, double b, double c, double d) => OutIn(OutQuart, InQuart, t, b, c, d);
|
2019-10-30 23:45:37 +00:00
|
|
|
|
|
|
|
|
|
// IN QUINTIC
|
|
|
|
|
|
|
|
|
|
public static float InQuint(float t) => NormalizedTime(InQuint, t);
|
|
|
|
|
public static float InQuint(float time, float start, float end) => TimeRange(InQuint, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float InQuint(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (c * (t * t * t * t * t)) + b;
|
2019-10-30 23:45:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double InQuint(double t) => NormalizedTime(InQuint, t);
|
|
|
|
|
public static double InQuint(double time, double start, double end) => TimeRange(InQuint, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InQuint(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (c * (t * t * t * t * t)) + b;
|
2019-10-30 23:45:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT QUINTIC
|
|
|
|
|
|
|
|
|
|
public static float OutQuint(float t) => NormalizedTime(OutQuint, t);
|
|
|
|
|
public static float OutQuint(float time, float start, float end) => TimeRange(OutQuint, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float OutQuint(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t = (t / d) - 1;
|
|
|
|
|
return (c * ((t * t * t * t * t) + 1)) + b;
|
2019-10-30 23:45:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double OutQuint(double t) => NormalizedTime(OutQuint, t);
|
|
|
|
|
public static double OutQuint(double time, double start, double end) => TimeRange(OutQuint, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double OutQuint(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t = (t / d) - 1;
|
|
|
|
|
return (c * ((t * t * t * t * t) + 1)) + b;
|
2019-10-30 23:45:37 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN OUT QUINTIC
|
|
|
|
|
|
|
|
|
|
public static float InOutQuint(float t) => NormalizedTime(InOutQuint, t);
|
|
|
|
|
public static float InOutQuint(float time, float start, float end) => TimeRange(InOutQuint, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static float InOutQuint(float t, float b, float c, float d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c / 2 * (t * t * t * t * t)) + b;
|
2019-10-30 23:45:37 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= 2;
|
|
|
|
|
return (c / 2 * ((t * t * t * t * t) + 2)) + b;
|
2019-10-30 23:45:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static double InOutQuint(double t) => NormalizedTime(InOutQuint, t);
|
|
|
|
|
public static double InOutQuint(double time, double start, double end) => TimeRange(InOutQuint, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InOutQuint(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c / 2 * (t * t * t * t * t)) + b;
|
2019-10-30 23:45:37 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= 2;
|
|
|
|
|
return (c / 2 * ((t * t * t * t * t) + 2)) + b;
|
2019-10-30 23:45:37 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT IN QUINTIC
|
|
|
|
|
|
|
|
|
|
public static float OutInQuint(float t) => NormalizedTime(OutInQuint, t);
|
|
|
|
|
public static float OutInQuint(float time, float start, float end) => TimeRange(OutInQuint, time, start, end);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
public static float OutInQuint(float t, float b, float c, float d) => OutIn(OutQuint, InQuint, t, b, c, d);
|
2019-10-30 23:45:37 +00:00
|
|
|
|
|
|
|
|
|
public static double OutInQuint(double t) => NormalizedTime(OutInQuint, t);
|
|
|
|
|
public static double OutInQuint(double time, double start, double end) => TimeRange(OutInQuint, time, start, end);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
public static double OutInQuint(double t, double b, double c, double d) => OutIn(OutQuint, InQuint, t, b, c, d);
|
2019-10-31 00:14:47 +00:00
|
|
|
|
|
|
|
|
|
// note: no float implementations because trig functions are double precision
|
|
|
|
|
|
|
|
|
|
// IN SINE
|
|
|
|
|
|
|
|
|
|
public static double InSine(double t) => NormalizedTime(InSine, t);
|
|
|
|
|
public static double InSine(double time, double start, double end) => TimeRange(InSine, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InSine(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (-c * Math.Cos(t / d * (Math.PI / 2))) + c + b;
|
2019-10-31 00:14:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT SINE
|
|
|
|
|
|
|
|
|
|
public static double OutSine(double t) => NormalizedTime(OutSine, t);
|
|
|
|
|
public static double OutSine(double time, double start, double end) => TimeRange(OutSine, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double OutSine(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c * Math.Sin(t / d * (Math.PI / 2))) + b;
|
2019-10-31 00:14:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN OUT SINE
|
|
|
|
|
|
|
|
|
|
public static double InOutSine(double t) => NormalizedTime(InOutSine, t);
|
|
|
|
|
public static double InOutSine(double time, double start, double end) => TimeRange(InOutSine, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InOutSine(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (-c / 2 * (Math.Cos(Math.PI * t / d) - 1)) + b;
|
2019-10-31 00:14:47 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT IN SINE
|
|
|
|
|
|
|
|
|
|
public static double OutInSine(double t) => NormalizedTime(OutInSine, t);
|
|
|
|
|
public static double OutInSine(double time, double start, double end) => TimeRange(OutInSine, time, start, end);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
public static double OutInSine(double t, double b, double c, double d) => OutIn(OutSine, InSine, t, b, c, d);
|
|
|
|
|
|
|
|
|
|
// IN EXPONENTIAL
|
2019-10-31 00:14:47 +00:00
|
|
|
|
|
2019-10-31 01:17:02 +00:00
|
|
|
|
public static double InExpo(double t) => NormalizedTime(InExpo, t);
|
|
|
|
|
public static double InExpo(double time, double start, double end) => TimeRange(InExpo, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InExpo(double t, double b, double c, double d)
|
2019-10-31 00:14:47 +00:00
|
|
|
|
{
|
2019-10-31 01:17:02 +00:00
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
if (t == 0)
|
2019-10-31 00:14:47 +00:00
|
|
|
|
{
|
2019-10-31 01:17:02 +00:00
|
|
|
|
return b;
|
2019-10-31 00:14:47 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c * Math.Pow(2, 10 * ((t / d) - 1))) + b - (c * 0.001);
|
2019-10-31 00:14:47 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-31 01:17:02 +00:00
|
|
|
|
|
|
|
|
|
// OUT EXPONENTIAL
|
|
|
|
|
|
|
|
|
|
public static double OutExpo(double t) => NormalizedTime(OutExpo, t);
|
|
|
|
|
public static double OutExpo(double time, double start, double end) => TimeRange(OutExpo, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double OutExpo(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
if (t == d)
|
|
|
|
|
{
|
|
|
|
|
return b + c;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c * 1.001 * (-Math.Pow(2, -10 * t / d) + 1)) + b;
|
2019-10-31 01:17:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN OUT EXPONENTIAL
|
|
|
|
|
|
|
|
|
|
public static double InOutExpo(double t) => NormalizedTime(InOutExpo, t);
|
|
|
|
|
public static double InOutExpo(double time, double start, double end) => TimeRange(InOutExpo, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InOutExpo(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
if (t == 0) { return b; }
|
|
|
|
|
if (t == d) { return b + c; }
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c / 2 * Math.Pow(2, 10 * (t - 1))) + b - (c * 0.0005);
|
2019-10-31 01:17:02 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t--;
|
|
|
|
|
return (c / 2 * 1.0005 * (-Math.Pow(2, -10 * t) + 2)) + b;
|
2019-10-31 01:17:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT IN EXPONENTIAL
|
|
|
|
|
|
|
|
|
|
public static double OutInExpo(double t) => NormalizedTime(OutInExpo, t);
|
|
|
|
|
public static double OutInExpo(double time, double start, double end) => TimeRange(OutInExpo, time, start, end);
|
|
|
|
|
public static double OutInExpo(double t, double b, double c, double d) => OutIn(OutExpo, InExpo, t, b, c, d);
|
|
|
|
|
|
|
|
|
|
// IN CIRCULAR
|
|
|
|
|
|
|
|
|
|
public static double InCirc(double t) => NormalizedTime(InCirc, t);
|
|
|
|
|
public static double InCirc(double time, double start, double end) => TimeRange(InCirc, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InCirc(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (-c * (Math.Sqrt(1 - (t * t)) - 1)) + b;
|
2019-10-31 01:17:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT CIRCULAR
|
|
|
|
|
|
|
|
|
|
public static double OutCirc(double t) => NormalizedTime(OutCirc, t);
|
|
|
|
|
public static double OutCirc(double time, double start, double end) => TimeRange(OutCirc, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double OutCirc(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t = (t / d) - 1;
|
|
|
|
|
return (c * Math.Sqrt(1 - (t * t))) + b;
|
2019-10-31 01:17:02 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN OUT CIRCULAR
|
|
|
|
|
|
|
|
|
|
public static double InOutCirc(double t) => NormalizedTime(InOutCirc, t);
|
|
|
|
|
public static double InOutCirc(double time, double start, double end) => TimeRange(InOutCirc, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InOutCirc(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (-c / 2 * (Math.Sqrt(1 - (t * t)) - 1)) + b;
|
2019-10-31 01:17:02 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= 2;
|
|
|
|
|
return (c / 2 * (Math.Sqrt(1 - (t * t)) + 1)) + b;
|
2019-10-31 01:17:02 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT IN CIRCULAR
|
|
|
|
|
|
|
|
|
|
public static double OutInCirc(double t) => NormalizedTime(OutInCirc, t);
|
|
|
|
|
public static double OutInCirc(double time, double start, double end) => TimeRange(OutInCirc, time, start, end);
|
|
|
|
|
public static double OutInCirc(double t, double b, double c, double d) => OutIn(OutCirc, InCirc, t, b, c, d);
|
2019-10-31 01:55:45 +00:00
|
|
|
|
|
2019-10-31 02:57:00 +00:00
|
|
|
|
// ELASTIC functions have two optional extra arguments
|
2019-10-31 01:55:45 +00:00
|
|
|
|
// a: amplitude
|
|
|
|
|
// p: period
|
|
|
|
|
|
2019-10-31 02:57:00 +00:00
|
|
|
|
// IN ELASTIC
|
|
|
|
|
|
2019-10-31 01:55:45 +00:00
|
|
|
|
public static double InElasticNormalized(double t) => InElastic(t, 0, 1, 1);
|
|
|
|
|
public static double InElasticNormalized(double t, double a) => InElastic(t, 0, 1, 1, a);
|
|
|
|
|
public static double InElasticNormalized(double t, double a, double p) => InElastic(t, 0, 1, 1, a, p);
|
|
|
|
|
|
2019-12-09 04:00:34 +00:00
|
|
|
|
public static double InElasticTimeRange(double time, double start, double end) => start + ((end - start) * InElasticNormalized((time - start) / (end - start)));
|
|
|
|
|
public static double InElasticTimeRange(double time, double start, double end, double a) => start + ((end - start) * InElasticNormalized((time - start) / (end - start), a));
|
|
|
|
|
public static double InElasticTimeRange(double time, double start, double end, double a, double p) => start + ((end - start) * InElasticNormalized((time - start) / (end - start), a, p));
|
2019-10-31 01:55:45 +00:00
|
|
|
|
|
|
|
|
|
public static double InElastic(double t, double b, double c, double d, double? a = null, double? p = null)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
|
|
|
|
|
if (t == 0) { return b; }
|
|
|
|
|
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
2019-10-31 01:55:45 +00:00
|
|
|
|
|
|
|
|
|
if (t == 1) { return b + c; }
|
|
|
|
|
|
|
|
|
|
if (!p.HasValue) { p = d * 0.3; }
|
|
|
|
|
|
|
|
|
|
double s;
|
|
|
|
|
if (!a.HasValue || a.Value < Math.Abs(c))
|
|
|
|
|
{
|
|
|
|
|
a = c;
|
|
|
|
|
s = p.Value / 4;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
s = p.Value / (2 * Math.PI) * Math.Asin(c / a.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t--;
|
2019-10-31 01:55:45 +00:00
|
|
|
|
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return -(a.Value * Math.Pow(2, 10 * t) * Math.Sin(((t * d) - s) * (2 * Math.PI) / p.Value)) + b;
|
2019-10-31 01:55:45 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT ELASTIC
|
|
|
|
|
|
|
|
|
|
public static double OutElasticNormalized(double t) => OutElastic(t, 0, 1, 1);
|
|
|
|
|
public static double OutElasticNormalized(double t, double a) => OutElastic(t, 0, 1, 1, a);
|
|
|
|
|
public static double OutElasticNormalized(double t, double a, double p) => OutElastic(t, 0, 1, 1, a, p);
|
|
|
|
|
|
2019-12-09 04:00:34 +00:00
|
|
|
|
public static double OutElasticTimeRange(double time, double start, double end) => start + ((end - start) * OutElasticNormalized((time - start) / (end - start)));
|
|
|
|
|
public static double OutElasticTimeRange(double time, double start, double end, double a) => start + ((end - start) * OutElasticNormalized((time - start) / (end - start), a));
|
|
|
|
|
public static double OutElasticTimeRange(double time, double start, double end, double a, double p) => start + ((end - start) * OutElasticNormalized((time - start) / (end - start), a, p));
|
2019-10-31 01:55:45 +00:00
|
|
|
|
|
|
|
|
|
public static double OutElastic(double t, double b, double c, double d, double? a = null, double? p = null)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
|
|
|
|
|
if (t == 0) { return b; }
|
|
|
|
|
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
2019-10-31 01:55:45 +00:00
|
|
|
|
|
|
|
|
|
if (t == 1) { return b + c; }
|
|
|
|
|
|
|
|
|
|
if (!p.HasValue) { p = d * 0.3; }
|
|
|
|
|
|
|
|
|
|
double s;
|
|
|
|
|
|
|
|
|
|
if (!a.HasValue || a.Value < Math.Abs(c))
|
|
|
|
|
{
|
|
|
|
|
a = c;
|
|
|
|
|
s = p.Value / 4;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
s = p.Value / (2 * Math.PI) * Math.Asin(c / a.Value);
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (a.Value * Math.Pow(2, -10 * t) * Math.Sin(((t * d) - s) * (2 * Math.PI) / p.Value)) + c + b;
|
2019-10-31 01:55:45 +00:00
|
|
|
|
}
|
2019-10-31 02:57:00 +00:00
|
|
|
|
|
|
|
|
|
// IN OUT ELASTIC
|
|
|
|
|
|
|
|
|
|
public static double InOutElasticNormalized(double t) => InOutElastic(t, 0, 1, 1);
|
|
|
|
|
public static double InOutElasticNormalized(double t, double a) => InOutElastic(t, 0, 1, 1, a);
|
|
|
|
|
public static double InOutElasticNormalized(double t, double a, double p) => InOutElastic(t, 0, 1, 1, a, p);
|
|
|
|
|
|
2019-12-09 04:00:34 +00:00
|
|
|
|
public static double InOutElasticTimeRange(double time, double start, double end) => start + ((end - start) * InOutElasticNormalized((time - start) / (end - start)));
|
|
|
|
|
public static double InOutElasticTimeRange(double time, double start, double end, double a) => start + ((end - start) * InOutElasticNormalized((time - start) / (end - start), a));
|
|
|
|
|
public static double InOutElasticTimeRange(double time, double start, double end, double a, double p) => start + ((end - start) * InOutElasticNormalized((time - start) / (end - start), a, p));
|
2019-10-31 02:57:00 +00:00
|
|
|
|
|
|
|
|
|
public static double InOutElastic(double t, double b, double c, double d, double? a = null, double? p = null)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
|
|
|
|
|
if (t == 0) { return b; }
|
|
|
|
|
|
|
|
|
|
t = t / d * 2;
|
|
|
|
|
|
|
|
|
|
if (t == 2) { return b + c; }
|
|
|
|
|
|
|
|
|
|
if (!p.HasValue) { p = d * (0.3 * 1.5); }
|
|
|
|
|
if (!a.HasValue) { a = 0; }
|
|
|
|
|
|
|
|
|
|
double s;
|
|
|
|
|
|
|
|
|
|
if (!a.HasValue || a < Math.Abs(c))
|
|
|
|
|
{
|
|
|
|
|
a = c;
|
|
|
|
|
s = p.Value / 4;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
s = p.Value / (2 * Math.PI) * Math.Asin(c / a.Value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t--;
|
|
|
|
|
return (-0.5 * (a.Value * Math.Pow(2, 10 * t) * Math.Sin(((t * d) - s) * (2 * Math.PI) / p.Value))) + b;
|
2019-10-31 02:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t--;
|
|
|
|
|
return (a.Value * Math.Pow(2, -10 * t) * Math.Sin(((t * d) - s) * (2 * Math.PI) / p.Value) * 0.5) + c + b;
|
2019-10-31 02:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT IN ELASTIC
|
|
|
|
|
|
|
|
|
|
public static double OutInElasticNormalized(double t) => OutInElastic(t, 0, 1, 1);
|
|
|
|
|
public static double OutInElasticNormalized(double t, double a) => OutInElastic(t, 0, 1, 1, a);
|
|
|
|
|
public static double OutInElasticNormalized(double t, double a, double p) => OutInElastic(t, 0, 1, 1, a, p);
|
|
|
|
|
|
2019-12-09 04:00:34 +00:00
|
|
|
|
public static double OutInElasticTimeRange(double time, double start, double end) => start + ((end - start) * OutInElasticNormalized((time - start) / (end - start)));
|
|
|
|
|
public static double OutInElasticTimeRange(double time, double start, double end, double a) => start + ((end - start) * OutInElasticNormalized((time - start) / (end - start), a));
|
|
|
|
|
public static double OutInElasticTimeRange(double time, double start, double end, double a, double p) => start + ((end - start) * OutInElasticNormalized((time - start) / (end - start), a, p));
|
2019-10-31 02:57:00 +00:00
|
|
|
|
|
|
|
|
|
public static double OutInElastic(double t, double b, double c, double d, double? a = null, double? p = null)
|
|
|
|
|
{
|
|
|
|
|
if (t < d / 2)
|
|
|
|
|
{
|
|
|
|
|
return OutElastic(t * 2, b, c / 2, d, a, p);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return InElastic((t * 2) - d, b + (c / 2), c / 2, d, a, p);
|
2019-10-31 02:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// back functions take an optional parameter
|
|
|
|
|
// s: size
|
|
|
|
|
|
|
|
|
|
// IN BACK
|
|
|
|
|
|
|
|
|
|
public static double InBackNormalized(double t) => InBack(t, 0, 1, 1);
|
|
|
|
|
public static double InBackNormalized(double t, double s) => InBack(t, 0, 1, 1, s);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
public static double InBackTimeRange(double time, double start, double end) => start + ((end - start) * InBackNormalized((time - start) / (end - start)));
|
|
|
|
|
public static double InBackTimeRange(double time, double start, double end, double s) => start + ((end - start) * InBackNormalized((time - start) / (end - start), s));
|
2019-10-31 02:57:00 +00:00
|
|
|
|
|
|
|
|
|
public static double InBack(double t, double b, double c, double d, double s = 1.70158)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
|
|
|
|
return (c * t * t * (((s + 1) * t) - s)) + b;
|
2019-10-31 02:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT BACK
|
|
|
|
|
|
|
|
|
|
public static double OutBackNormalized(double t) => OutBack(t, 0, 1, 1);
|
|
|
|
|
public static double OutBackNormalized(double t, double s) => OutBack(t, 0, 1, 1, s);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
public static double OutBackTimeRange(double time, double start, double end) => start + ((end - start) * OutBackNormalized((time - start) / (end - start)));
|
|
|
|
|
public static double OutBackTimeRange(double time, double start, double end, double s) => start + ((end - start) * OutBackNormalized((time - start) / (end - start), s));
|
2019-10-31 02:57:00 +00:00
|
|
|
|
|
|
|
|
|
public static double OutBack(double t, double b, double c, double d, double s = 1.70158)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t = (t / d) - 1;
|
|
|
|
|
return (c * ((t * t * (((s + 1) * t) + s)) + 1)) + b;
|
2019-10-31 02:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN OUT BACK
|
|
|
|
|
|
|
|
|
|
public static double InOutBackNormalized(double t) => InOutBack(t, 0, 1, 1);
|
|
|
|
|
public static double InOutBackNormalized(double t, double s) => InOutBack(t, 0, 1, 1, s);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
public static double InOutBackTimeRange(double time, double start, double end) => start + ((end - start) * InOutBackNormalized((time - start) / (end - start)));
|
|
|
|
|
public static double InOutBackTimeRange(double time, double start, double end, double s) => start + ((end - start) * InOutBackNormalized((time - start) / (end - start), s));
|
2019-10-31 02:57:00 +00:00
|
|
|
|
|
|
|
|
|
public static double InOutBack(double t, double b, double c, double d, double s = 1.70158)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
s *= 1.525;
|
2019-10-31 02:57:00 +00:00
|
|
|
|
t = t / d * 2;
|
|
|
|
|
if (t < 1)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c / 2 * (t * t * (((s + 1) * t) - s))) + b;
|
2019-10-31 02:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= 2;
|
|
|
|
|
return (c / 2 * ((t * t * (((s + 1) * t) + s)) + 2)) + b;
|
2019-10-31 02:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT IN BACK
|
|
|
|
|
|
|
|
|
|
public static double OutInBackNormalized(double t) => OutInBack(t, 0, 1, 1);
|
|
|
|
|
public static double OutInBackNormalized(double t, double s) => OutInBack(t, 0, 1, 1, s);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
public static double OutInBackTimeRange(double time, double start, double end) => start + ((end - start) * OutInBackNormalized((time - start) / (end - start)));
|
|
|
|
|
public static double OutInBackTimeRange(double time, double start, double end, double s) => start + ((end - start) * OutInBackNormalized((time - start) / (end - start), s));
|
2019-10-31 02:57:00 +00:00
|
|
|
|
|
|
|
|
|
public static double OutInBack(double t, double b, double c, double d, double s = 1.70158)
|
|
|
|
|
{
|
|
|
|
|
if (t < d / 2)
|
|
|
|
|
{
|
|
|
|
|
return OutBack(t * 2, b, c / 2, d, s);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return InBack((t * 2) - d, b + (c / 2), c / 2, d, s);
|
2019-10-31 02:57:00 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-31 03:14:08 +00:00
|
|
|
|
|
|
|
|
|
// OUT BOUNCE
|
|
|
|
|
|
|
|
|
|
public static double OutBounce(double t) => NormalizedTime(OutBounce, t);
|
|
|
|
|
public static double OutBounce(double time, double start, double end) => TimeRange(OutBounce, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double OutBounce(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t /= d;
|
2019-10-31 03:14:08 +00:00
|
|
|
|
if (t < 1 / 2.75)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (c * (7.5625 * t * t)) + b;
|
2019-10-31 03:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
else if (t < 2 / 2.75)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= (1.5 / 2.75);
|
|
|
|
|
return (c * ((7.5625 * t * t) + 0.75)) + b;
|
2019-10-31 03:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
else if (t < 2.5 / 2.75)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= (2.25 / 2.75);
|
|
|
|
|
return (c * ((7.5625 * t * t) + 0.9375)) + b;
|
2019-10-31 03:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
t -= (2.625 / 2.75);
|
|
|
|
|
return (c * ((7.5625 * t * t) + 0.984375)) + b;
|
2019-10-31 03:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN BOUNCE
|
|
|
|
|
|
|
|
|
|
public static double InBounce(double t) => NormalizedTime(InBounce, t);
|
|
|
|
|
public static double InBounce(double time, double start, double end) => TimeRange(InBounce, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InBounce(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
return c - OutBounce(d - t, 0, c, d) + b;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// IN OUT BOUNCE
|
|
|
|
|
|
|
|
|
|
public static double InOutBounce(double t) => NormalizedTime(InOutBounce, t);
|
|
|
|
|
public static double InOutBounce(double time, double start, double end) => TimeRange(InOutBounce, time, start, end);
|
|
|
|
|
|
|
|
|
|
public static double InOutBounce(double t, double b, double c, double d)
|
|
|
|
|
{
|
|
|
|
|
CheckTime(t, d);
|
|
|
|
|
if (t < d / 2)
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (InBounce(t * 2, 0, c, d) * 0.5) + b;
|
2019-10-31 03:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2019-12-09 04:00:34 +00:00
|
|
|
|
return (OutBounce((t * 2) - d, 0, c, d) * 0.5) + (c * 0.5) + b;
|
2019-10-31 03:14:08 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// OUT IN BOUNCE
|
|
|
|
|
|
|
|
|
|
public static double OutInBounce(double t) => NormalizedTime(OutInBounce, t);
|
|
|
|
|
public static double OutInBounce(double time, double start, double end) => TimeRange(OutInBounce, time, start, end);
|
|
|
|
|
public static double OutInBounce(double t, double b, double c, double d) => OutIn(OutBounce, InBounce, t, b, c, d);
|
2019-10-30 00:03:51 +00:00
|
|
|
|
}
|
|
|
|
|
}
|