unit Utils.Easing.Core;
interface
uses Math;
type
TUtilsEasingCore =
class
public
class function EaseInQuart(T, B, C, D: Integer): Integer;
static;
class function EaseOutQuart(T, B, C, D: Integer): Integer;
static;
class function EaseInQuint(T, B, C, D: Integer): Integer;
static;
class function EaseOutQuint(T, B, C, D: Integer): Integer;
static;
class function EaseOutBounce(T, B, C, D: Integer): Integer;
static;
class function EaseOutElastic(T, B, C, D: Integer): Integer;
static;
end;
implementation
// Quart easing
// ==============================================================================================================================================
class function TUtilsEasingCore.EaseInQuart(T, B, C, D: Integer): Integer;
var
T2: Single;
begin
T2 := T / D;
Result := Round(C * T2 * T2 * T2 * T2) + B;
end;
class function TUtilsEasingCore.EaseOutQuart(T, B, C, D: Integer): Integer;
var
T2: Single;
begin
T2 := T / D - 1;
Result := Round(-C * (T2 * T2 * T2 * T2 - 1)) + B;
end;
// ==============================================================================================================================================
// Quint easing
// ==============================================================================================================================================
class function TUtilsEasingCore.EaseInQuint(T, B, C, D: Integer): Integer;
var
T2: Single;
begin
T2 := T / D;
Result := Round(C * T2 * T2 * T2 * T2 * T2) + B;
end;
class function TUtilsEasingCore.EaseOutQuint(T, B, C, D: Integer): Integer;
var
T2: Single;
begin
T2 := T / D - 1;
Result := Round(C * (T2 * T2 * T2 * T2 * T2 + 1)) + B;
end;
// ==============================================================================================================================================
// Bounce/elastic easing
// ==============================================================================================================================================
class function TUtilsEasingCore.EaseOutBounce(T, B, C, D: Integer): Integer;
var
T2: Single;
begin
T2 := T / D;
if (T2 < (1.0 / 2.75))
then
begin
Result := Round(C * (7.5625 * T2 * T2)) + B;
end
else if (T2 < (2.0 / 2.75))
then
begin
T2 := T2 - (1.5 / 2.75);
Result := Round(C * (7.5625 * T2 * T2 + 0.75)) + B;
end
else if (T2 < (2.5 / 2.75))
then
begin
T2 := T2 - (2.25 / 2.75);
Result := Round(C * (7.5625 * T2 * T2 + 0.9375)) + B;
end
else
begin
T2 := T2 - (2.625 / 2.75);
Result := Round(C * (7.5625 * T2 * T2 + 0.984375)) + B;
end;
end;
class function TUtilsEasingCore.EaseOutElastic(T, B, C, D: Integer): Integer;
var
S, P, A, T2: Double;
begin
if (T = 0)
then
begin
Exit(B);
end;
T2 := T / D;
if (T2 = 1)
then
begin
Exit(B + C);
end;
P := D * 0.3;
A := C;
if (A < Abs(C))
then
begin
S := P / 4;
end
else
begin
S := P / (2 * PI) * ArcSin(C / A);
end;
Result := Round(A * Power(2, -10 * T2) * Sin((T2 * D - S) * (2 * PI) / P)) + C + B;
end;
// ==============================================================================================================================================
end.