9constexpr float pi = 3.14159265358979323846f;
10constexpr float half_pi = pi * 0.5f;
12float linearInterpolation(
float a)
17float quadraticEaseIn(
float a)
22float quadraticEaseOut(
float a)
24 return -(
a * (
a -
static_cast<float>(2)));
27float quadraticEaseInOut(
float a)
29 if(
a <
static_cast<float>(0.5))
31 return static_cast<float>(2) *
a *
a;
34 return (-
static_cast<float>(2) *
a *
a) + (4 *
a) - 1.0f;
37float cubicEaseIn(
float a)
42float cubicEaseOut(
float a)
44 float const f =
a - 1.0f;
45 return f *
f *
f + 1.0f;
48float cubicEaseInOut(
float a)
50 if(
a <
static_cast<float>(0.5))
52 return static_cast<float>(4) *
a *
a *
a;
55 float const f = ((
static_cast<float>(2) *
a) -
static_cast<float>(2));
56 return static_cast<float>(0.5) * f * f * f + 1.0f;
59float quarticEaseIn(
float a)
64float quarticEaseOut(
float a)
66 float const f = (
a - 1.0f);
67 return f *
f *
f * (1.0f -
a) + 1.0f;
70float quarticEaseInOut(
float a)
72 if(
a <
static_cast<float>(0.5))
74 return static_cast<float>(8) *
a *
a *
a *
a;
77 float const f = (
a - 1.0f);
78 return -
static_cast<float>(8) * f * f * f * f + 1.0f;
81float quinticEaseIn(
float a)
83 return a *
a *
a *
a *
a;
86float quinticEaseOut(
float a)
88 float const f = (
a - 1.0f);
89 return f *
f *
f *
f *
f + 1.0f;
92float quinticEaseInOut(
float a)
94 if(
a <
static_cast<float>(0.5))
96 return static_cast<float>(16) *
a *
a *
a *
a *
a;
99 float const f = ((
static_cast<float>(2) *
a) -
static_cast<float>(2));
100 return static_cast<float>(0.5) * f * f * f * f * f + 1.0f;
103float sineEaseIn(
float a)
105 return std::sin((
a - 1.0f) * half_pi) + 1.0f;
108float sineEaseOut(
float a)
110 return std::sin(
a * half_pi);
113float sineEaseInOut(
float a)
115 return static_cast<float>(0.5) * (1.0f - std::cos(
a *
static_cast<float>(pi)));
118float circularEaseIn(
float a)
120 return 1.0f - std::sqrt(1.0f - (
a *
a));
123float circularEaseOut(
float a)
125 return std::sqrt((
static_cast<float>(2) -
a) *
a);
128float circularEaseInOut(
float a)
130 if(
a <
static_cast<float>(0.5))
132 return static_cast<float>(0.5) * (1.0f - std::sqrt(1.0f -
static_cast<float>(4) * (
a *
a)));
135 return static_cast<float>(0.5) *
136 (std::sqrt(-((
static_cast<float>(2) *
a) -
static_cast<float>(3)) * ((
static_cast<float>(2) *
a) - 1.0f)) +
140float exponentialEaseIn(
float a)
147 float const Complementary =
a - 1.0f;
148 float const Two = 2.0f;
150 return std::pow(Two, Complementary *
static_cast<float>(10));
153float exponentialEaseOut(
float a)
160 return 1.0f - std::pow(
static_cast<float>(2), -
static_cast<float>(10) *
a);
163float exponentialEaseInOut(
float a)
165 if(
a <
static_cast<float>(0.5))
167 return static_cast<float>(0.5) *
168 std::pow(
static_cast<float>(2), (
static_cast<float>(20) *
a) -
static_cast<float>(10));
171 return -
static_cast<float>(0.5) *
172 std::pow(
static_cast<float>(2), (-
static_cast<float>(20) *
a) +
static_cast<float>(10)) +
176float elasticEaseIn(
float a)
178 return std::sin(
static_cast<float>(13) * half_pi *
a) *
179 std::pow(
static_cast<float>(2),
static_cast<float>(10) * (
a - 1.0f));
182float elasticEaseOut(
float a)
184 return std::sin(-
static_cast<float>(13) * half_pi * (
a + 1.0f)) *
185 std::pow(
static_cast<float>(2), -
static_cast<float>(10) *
a) +
189float elasticEaseInOut(
float a)
191 if(
a <
static_cast<float>(0.5))
193 return static_cast<float>(0.5) * std::sin(
static_cast<float>(13) * half_pi * (
static_cast<float>(2) *
a)) *
194 std::pow(
static_cast<float>(2),
static_cast<float>(10) * ((
static_cast<float>(2) *
a) - 1.0f));
197 return static_cast<float>(0.5) *
198 (std::sin(-
static_cast<float>(13) * half_pi * ((
static_cast<float>(2) *
a - 1.0f) + 1.0f)) *
199 std::pow(
static_cast<float>(2), -
static_cast<float>(10) * (
static_cast<float>(2) *
a - 1.0f)) +
200 static_cast<float>(2));
203float backEaseIn(
float a,
float const& o)
205 float z = ((
o + 1.0f) *
a) - o;
209float backEaseOut(
float a,
float const& o)
212 float z = ((
o + 1.0f) *
n) + o;
213 return (n * n *
z) + 1.0f;
216float backEaseInOut(
float a,
float const& o)
218 float s =
o *
static_cast<float>(1.525);
220 float n =
a /
static_cast<float>(0.5);
222 if(n <
static_cast<float>(1))
224 float z = ((
s +
static_cast<float>(1)) *
n) - s;
229 n -=
static_cast<float>(2);
230 float z = ((
s +
static_cast<float>(1)) *
n) + s;
231 float m = (
n *
n *
z) +
static_cast<float>(2);
235float backEaseIn(
float a)
237 return backEaseIn(
a,
static_cast<float>(1.70158));
240float backEaseOut(
float a)
242 return backEaseOut(
a,
static_cast<float>(1.70158));
245float backEaseInOut(
float a)
247 return backEaseInOut(
a,
static_cast<float>(1.70158));
250float bounceEaseOut(
float a)
252 if(
a <
static_cast<float>(4.0 / 11.0))
254 return (
static_cast<float>(121) *
a *
a) /
static_cast<float>(16);
256 if(
a <
static_cast<float>(8.0 / 11.0))
258 return (
static_cast<float>(363.0 / 40.0) *
a *
a) - (
static_cast<float>(99.0 / 10.0) *
a) +
259 static_cast<float>(17.0 / 5.0);
261 if(
a <
static_cast<float>(9.0 / 10.0))
263 return (
static_cast<float>(4356.0 / 361.0) *
a *
a) - (
static_cast<float>(35442.0 / 1805.0) *
a) +
264 static_cast<float>(16061.0 / 1805.0);
266 return (
static_cast<float>(54.0 / 5.0) *
a *
a) - (
static_cast<float>(513.0 / 25.0) *
a) +
267 static_cast<float>(268.0 / 25.0);
270float bounceEaseIn(
float a)
272 return 1.0f - bounceEaseOut(1.0f -
a);
275float bounceEaseInOut(
float a)
277 if(
a <
static_cast<float>(0.5))
279 return static_cast<float>(0.5) * (1.0f - bounceEaseOut(
a *
static_cast<float>(2)));
282 return static_cast<float>(0.5) * bounceEaseOut(
a *
static_cast<float>(2) - 1.0f) +
static_cast<float>(0.5);
294 return linearInterpolation(progress);
300 return sineEaseIn(progress);
306 return sineEaseOut(progress);
312 return sineEaseInOut(progress);
318 return quadraticEaseIn(progress);
324 return quadraticEaseOut(progress);
332 return quadraticEaseInOut(progress);
338 return cubicEaseIn(progress);
344 return cubicEaseOut(progress);
352 return cubicEaseInOut(progress);
358 return quarticEaseIn(progress);
364 return quarticEaseOut(progress);
372 return quarticEaseInOut(progress);
378 return quinticEaseIn(progress);
384 return quinticEaseOut(progress);
392 return quinticEaseInOut(progress);
398 return exponentialEaseIn(progress);
404 return exponentialEaseOut(progress);
412 return exponentialEaseInOut(progress);
418 return circularEaseIn(progress);
424 return circularEaseOut(progress);
432 return circularEaseInOut(progress);
438 return elasticEaseIn(progress);
444 return elasticEaseOut(progress);
452 return elasticEaseInOut(progress);
457 return backEaseIn(progress);
462 return backEaseOut(progress);
467 return backEaseInOut(progress);
472 return bounceEaseIn(progress);
477 return bounceEaseOut(progress);
482 return bounceEaseInOut(progress);
487 return progress * (1.0f - progress) * 4.0f;
502 return progress * progress * (1.0f - progress) * 8.0f;
507 const auto remaining = 1.0f - progress;
508 return progress * remaining * remaining * 8.0f;
513 return [overshoot](
float a)
515 return backEaseIn(
a, overshoot);
521 return [overshoot](
float a)
523 return backEaseOut(
a, overshoot);
529 return [overshoot](
float a)
531 return backEaseInOut(
a, overshoot);
535const std::vector<std::pair<std::string, std::function<float(
float)>>>&
get_ease_list()
537 static const std::vector<std::pair<std::string, std::function<float(
float)>>> list = {
float arch_smooth_start(float progress)
float bounce_start_stop(float progress)
float elastic_start(float progress)
Modelled after the damped sine wave y = sin(13pi/2*x)*pow(2, 10 * (x - 1))
float smooth_stop3(float progress)
Modelled after the cubic y = (x - 1)^3 + 1.
float smooth_stop4(float progress)
Modelled after the quartic y = 1 - (x - 1)^4.
float circular_stop(float progress)
Modelled after shifted quadrant II of unit circle.
float arch(float progress)
float smooth_stop2(float progress)
Modelled after the parabola y = -x^2 + 2x.
float smooth_start6(float progress)
Modelled after the exponential function y = 2^(10(x - 1))
float smooth_start2(float progress)
Modelled after the parabola y = x^2.
std::function< float(float)> create_back_stop(float overshoot)
float smooth_start_stop3(float progress)
float circular_start(float progress)
Modelled after shifted quadrant IV of unit circle.
float smooth_stop(float progress)
Modelled after quarter-cycle of sine wave (different phase)
float linear(float progress)
float arch_smooth_step(float progress)
float smooth_start_stop4(float progress)
float smooth_stop5(float progress)
Modelled after the quintic y = (x - 1)^5 + 1.
float smooth_stop6(float progress)
Modelled after the exponential function y = -2^(-10x) + 1.
float elastic_stop(float progress)
Modelled after the damped sine wave y = sin(-13pi/2*(x + 1))*pow(2, -10x) + 1.
std::function< float(float)> create_back_start(float overshoot)
float circular_start_stop(float progress)
float smooth_start_stop2(float progress)
float arch_smooth_stop(float progress)
float bounce_stop(float progress)
float back_stop(float progress)
float smooth_start_stop5(float progress)
float smooth_start_stop(float progress)
Modelled after half sine wave.
float arch_smooth_start_stop(float progress)
float smooth_start_stop6(float progress)
float bounce_start(float progress)
std::function< float(float)> create_back_stop_stop(float overshoot)
float smooth_start(float progress)
Modelled after quarter-cycle of sine wave.
float smooth_start3(float progress)
Modelled after the cubic y = x^3.
float smooth_start5(float progress)
Modelled after the quintic y = x^5.
float back_start_stop(float progress)
float back_start(float progress)
float smooth_start4(float progress)
Modelled after the quartic x^4.
const std::vector< std::pair< std::string, std::function< float(float)> > > & get_ease_list()
float elastic_start_stop(float progress)
Provides a sequence-based action management system for controlling and scheduling actions.
auto reverse_scale(float a, float t) -> float
Scales a value in reverse by a factor.