5 constexpr float PI = 3.14159265358979323846;
6 constexpr float C1 = 1.70158;
7 constexpr float C2 =
C1 * 1.525;
8 constexpr float C3 =
C1 + 1.0;
9 constexpr float C4 = (2.0 *
PI) / 3.0;
10 constexpr float C5 = (2.0 *
PI) / 4.5;
23 inline double Animate(
bool forward,
double duration,
double& from,
24 double dt,
double (*ease)(
double)) {
25 from = std::clamp(from + (forward ? dt : -dt), 0.0, duration);
26 return ease(from / duration);
44 inline double Springimate(
double& v,
double& current,
double target,
45 double stiffness,
double damping,
double dt) {
46 double force = (target - current) * stiffness - v * damping;
59 return 1.0 - cosf(t *
PI / 2.0);
62 return sinf(t *
PI / 2.0);
65 return -(cosf(
PI * t) - 1.0) / 2.0;
73 return 1.0 - (1.0 - t) * (1.0 - t);
76 return t < 0.5 ? 2.0 * t * t
77 : 1.0 - powf(-2.0 * t + 2.0, 2.0) / 2.0;
85 return 1.0 - powf(1.0 - t, 3.0);
88 return t < 0.5 ? 4.0 * t * t * t
89 : 1.0 - powf(-2.0 * t + 2.0, 3.0) / 2.0;
97 return 1.0 - powf(1.0 - t, 4.0);
100 return t < 0.5 ? 8.0 * t * t * t * t
101 : 1.0 - powf(-2.0 * t + 2.0, 4.0) / 2.0;
106 return t * t * t * t * t;
109 return 1.0 - powf(1.0 - t, 5.0);
112 return t < 0.5 ? 16.0 * t * t * t * t * t
113 : 1.0 - powf(-2.0 * t + 2.0, 5.0) / 2.0;
118 return t == 0.0 ? 0.0 : powf(2.0, 10.0 * t - 10.0);
121 return t == 1.0 ? 1.0 : 1.0 - powf(2.0, -10.0 * t);
128 return t < 0.5 ? powf(2.0, 20.0 * t - 10.0) / 2.0
129 : (2.0 - powf(2.0, -20.0 * t + 10.0)) / 2.0;
134 return 1.0 - sqrtf(1.0 - t * t);
137 return sqrtf(1.0 - powf(t - 1.0, 2.0));
141 ? (1.0 - sqrtf(1.0 - powf(2.0 * t, 2.0))) / 2.0
142 : (sqrtf(1.0 - powf(-2.0 * t + 2.0, 2.0)) + 1.0) / 2.0;
147 return C3 * t * t * t -
C1 * t * t;
150 return 1.0 +
C3 * powf(t - 1.0, 3.0) +
C1 * powf(t - 1.0, 2.0);
154 ? (powf(2.0 * t, 2.0) * ((
C2 + 1.0) * 2.0 * t -
C2)) /
156 : (powf(2.0 * t - 2.0, 2.0) *
157 ((
C2 + 1.0) * (2.0 * t - 2.0) +
C2) +
168 return -powf(2.0, 10.0 * t - 10.0) * sinf((t * 10.0 - 10.75) *
C4);
175 return powf(2.0, -10.0 * t) * sinf((t * 10.0 - 0.75) *
C4) + 1.0;
182 return t < 0.5 ? -(powf(2.0, 20.0 * t - 10.0) *
183 sinf((20.0 * t - 11.125) *
C5)) /
185 : (powf(2.0, -20.0 * t + 10.0) *
186 sinf((20.0 * t - 11.125) *
C5)) /
193 constexpr double n1 = 7.5625, d1 = 2.75;
198 return n1 * t * t + 0.75;
202 return n1 * t * t + 0.9375;
205 return n1 * t * t + 0.984375;
212 return t < 0.5 ? (1.0 -
OutBounce(1.0 - 2.0 * t)) / 2.0
213 : (1.0 +
OutBounce(2.0 * t - 1.0)) / 2.0;
218 return t > 0.0 ? 1.0 : 0.0;
221 return t >= 1.0 ? 1.0 : 0.0;
223 inline double Steps(
double t,
int steps) {
224 return floorf(t * (
double)steps) / (double)steps;
229 return t * t * (3.0 - 2.0 * t);
232 return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
236 inline double Spring(
double t,
double mass = 1.0,
237 double stiffness = 100.0,
double damping = 10.0) {
238 double w = sqrtf(stiffness / mass);
239 double d = damping / (2.0 * mass);
241 double wd = sqrtf(w * w - d * d);
243 expf(-d * t) * (cosf(wd * t) + (d / wd) * sinf(wd * t));
245 return 1.0 - expf(-d * t) * (1.0 + d * t);
double InOutCirc(double t)
Definition Anim.h:139
double OutSine(double t)
Definition Anim.h:61
double InQuad(double t)
Definition Anim.h:69
double StepEnd(double t)
Definition Anim.h:220
double OutCirc(double t)
Definition Anim.h:136
double Linear(double t)
Definition Anim.h:53
double InOutBack(double t)
Definition Anim.h:152
constexpr float C5
Definition Anim.h:10
double OutQuart(double t)
Definition Anim.h:96
double OutQuint(double t)
Definition Anim.h:108
double InElastic(double t)
Definition Anim.h:163
double StepStart(double t)
Definition Anim.h:217
double InOutCubic(double t)
Definition Anim.h:87
double Steps(double t, int steps)
Definition Anim.h:223
double InExpo(double t)
Definition Anim.h:117
double Animate(bool forward, double duration, double &from, double dt, double(*ease)(double))
Definition Anim.h:23
double OutElastic(double t)
Definition Anim.h:170
double SmootherStep(double t)
Definition Anim.h:231
constexpr float C1
Definition Anim.h:6
double InOutBounce(double t)
Definition Anim.h:211
constexpr float PI
Definition Anim.h:5
double InOutSine(double t)
Definition Anim.h:64
constexpr float C3
Definition Anim.h:8
constexpr float C2
Definition Anim.h:7
double InBounce(double t)
Definition Anim.h:208
double SmoothStep(double t)
Definition Anim.h:228
double InOutElastic(double t)
Definition Anim.h:177
double InOutQuint(double t)
Definition Anim.h:111
constexpr float C4
Definition Anim.h:9
double OutExpo(double t)
Definition Anim.h:120
double InSine(double t)
Definition Anim.h:58
double Spring(double t, double mass=1.0, double stiffness=100.0, double damping=10.0)
Definition Anim.h:236
double OutCubic(double t)
Definition Anim.h:84
double OutBounce(double t)
Definition Anim.h:192
double InCubic(double t)
Definition Anim.h:81
double OutQuad(double t)
Definition Anim.h:72
double InBack(double t)
Definition Anim.h:146
double InCirc(double t)
Definition Anim.h:133
double Springimate(double &v, double ¤t, double target, double stiffness, double damping, double dt)
Definition Anim.h:44
double InOutQuart(double t)
Definition Anim.h:99
double InOutExpo(double t)
Definition Anim.h:123
double InOutQuad(double t)
Definition Anim.h:75
double InQuart(double t)
Definition Anim.h:93
double OutBack(double t)
Definition Anim.h:149
double InQuint(double t)
Definition Anim.h:105
The FuncDoodle C++ namespace.
Definition Common.h:12