31 #ifndef TWEENY_EASING_H
32 #define TWEENY_EASING_H
35 #include <type_traits>
38 #define M_PI 3.14159265358979323846
180 static T run(
float position, T start, T end) {
190 template<
class...>
struct voidify {
using type = void; };
191 template<
class... Ts>
using void_t =
typename voidify<Ts...>::type;
193 template<
class T,
class =
void>
194 struct supports_arithmetic_operations : std::false_type {};
197 struct supports_arithmetic_operations<T, void_t<
198 decltype(std::declval<T>() + std::declval<T>()),
199 decltype(std::declval<T>() - std::declval<T>()),
200 decltype(std::declval<T>() * std::declval<T>()),
201 decltype(std::declval<T>() * std::declval<float>()),
202 decltype(std::declval<float>() * std::declval<T>())
203 >> : std::true_type{};
207 static typename std::enable_if<std::is_integral<T>::value, T>::type run(
float position, T start, T end) {
208 return static_cast<T
>(roundf((end - start) * position + start));
212 static typename std::enable_if<supports_arithmetic_operations<T>::value && !std::is_integral<T>::value, T>::type run(
float position, T start, T end) {
213 return static_cast<T
>((end - start) * position + start);
217 static typename std::enable_if<!supports_arithmetic_operations<T>::value, T>::type run(
float position, T start, T end) {
228 static typename std::enable_if<std::is_integral<T>::value, T>::type run(
float position, T start, T end) {
229 return static_cast<T
>(roundf((end - start) * position + start));
233 static typename std::enable_if<!std::is_integral<T>::value, T>::type run(
float position, T start, T end) {
234 return static_cast<T
>((end - start) * position + start);
244 static T run(
float position, T start, T end) {
245 return static_cast<T
>((end - start) * position * position + start);
255 static T run(
float position, T start, T end) {
256 return static_cast<T
>((-(end - start)) * position * (position - 2) + start);
266 static T run(
float position, T start, T end) {
269 return static_cast<T
>(((end - start) / 2) * position * position + start);
273 return static_cast<T
>((-(end - start) / 2) * (position * (position - 2) - 1) + start);
283 static T run(
float position, T start, T end) {
284 return static_cast<T
>((end - start) * position * position * position + start);
294 static T run(
float position, T start, T end) {
296 return static_cast<T
>((end - start) * (position * position * position + 1) + start);
306 static T run(
float position, T start, T end) {
309 return static_cast<T
>(((end - start) / 2) * position * position * position + start);
312 return static_cast<T
>(((end - start) / 2) * (position * position * position + 2) + start);
322 static T run(
float position, T start, T end) {
323 return static_cast<T
>((end - start) * position * position * position * position + start);
333 static T run(
float position, T start, T end) {
335 return static_cast<T
>( -(end - start) * (position * position * position * position - 1) + start);
345 static T run(
float position, T start, T end) {
348 return static_cast<T
>(((end - start) / 2) * (position * position * position * position) +
352 return static_cast<T
>((-(end - start) / 2) * (position * position * position * position - 2) +
363 static T run(
float position, T start, T end) {
364 return static_cast<T
>((end - start) * position * position * position * position * position + start);
374 static T run(
float position, T start, T end) {
376 return static_cast<T
>((end - start) * (position * position * position * position * position + 1) +
387 static T run(
float position, T start, T end) {
390 return static_cast<T
>(
391 ((end - start) / 2) * (position * position * position * position * position) +
395 return static_cast<T
>(
396 ((end - start) / 2) * (position * position * position * position * position + 2) +
407 static T run(
float position, T start, T end) {
408 return static_cast<T
>(-(end - start) * cosf(position *
static_cast<float>(M_PI) / 2) + (end - start) + start);
418 static T run(
float position, T start, T end) {
419 return static_cast<T
>((end - start) * sinf(position *
static_cast<float>(M_PI) / 2) + start);
429 static T run(
float position, T start, T end) {
430 return static_cast<T
>((-(end - start) / 2) * (cosf(position *
static_cast<float>(M_PI)) - 1) + start);
440 static T run(
float position, T start, T end) {
441 return static_cast<T
>((end - start) * powf(2, 10 * (position - 1)) + start);
451 static T run(
float position, T start, T end) {
452 return static_cast<T
>((end - start) * (-powf(2, -10 * position) + 1) + start);
462 static T run(
float position, T start, T end) {
465 return static_cast<T
>(((end - start) / 2) * powf(2, 10 * (position - 1)) + start);
468 return static_cast<T
>(((end - start) / 2) * (-powf(2, -10 * position) + 2) + start);
478 static T run(
float position, T start, T end) {
479 return static_cast<T
>( -(end - start) * (sqrtf(1 - position * position) - 1) + start );
489 static T run(
float position, T start, T end) {
491 return static_cast<T
>((end - start) * (sqrtf(1 - position * position)) + start);
501 static T run(
float position, T start, T end) {
504 return static_cast<T
>((-(end - start) / 2) * (sqrtf(1 - position * position) - 1) + start);
508 return static_cast<T
>(((end - start) / 2) * (sqrtf(1 - position * position) + 1) + start);
518 static T run(
float position, T start, T end) {
519 return (end - start) - bounceOut.run((1 - position), T(), end) + start;
529 static T run(
float position, T start, T end) {
531 if (position < (1 / 2.75f)) {
532 return static_cast<T
>(c * (7.5625f * position * position) + start);
533 }
else if (position < (2.0f / 2.75f)) {
534 float postFix = position -= (1.5f / 2.75f);
535 return static_cast<T
>(c * (7.5625f * (postFix) * position + .75f) + start);
536 }
else if (position < (2.5f / 2.75f)) {
537 float postFix = position -= (2.25f / 2.75f);
538 return static_cast<T
>(c * (7.5625f * (postFix) * position + .9375f) + start);
540 float postFix = position -= (2.625f / 2.75f);
541 return static_cast<T
>(c * (7.5625f * (postFix) * position + .984375f) + start);
552 static T run(
float position, T start, T end) {
553 if (position < 0.5f)
return static_cast<T
>(bounceIn.run(position * 2, T(), end) * .5f + start);
554 else return static_cast<T
>(bounceOut.run((position * 2 - 1), T(), end) * .5f + (end - start) * .5f + start);
564 static T run(
float position, T start, T end) {
565 if (position <= 0.00001f)
return start;
566 if (position >= 0.999f)
return end;
568 auto a = end - start;
571 a * powf(2, 10 * (position -= 1));
572 return static_cast<T
>(-(postFix * sinf((position - s) * (2 *
static_cast<float>(M_PI)) / p)) + start);
582 static T run(
float position, T start, T end) {
583 if (position <= 0.00001f)
return start;
584 if (position >= 0.999f)
return end;
586 auto a = end - start;
588 return static_cast<T
>(a * powf(2, -10 * position) * sinf((position - s) * (2 *
static_cast<float>(M_PI)) / p) + end);
598 static T run(
float position, T start, T end) {
599 if (position <= 0.00001f)
return start;
600 if (position >= 0.999f)
return end;
602 float p = (.3f * 1.5f);
603 auto a = end - start;
608 postFix = a * powf(2, 10 * (position -= 1));
609 return static_cast<T
>(-0.5f * (postFix * sinf((position - s) * (2 *
static_cast<float>(M_PI)) / p)) + start);
611 postFix = a * powf(2, -10 * (position -= 1));
612 return static_cast<T
>(postFix * sinf((position - s) * (2 *
static_cast<float>(M_PI)) / p) * .5f + end);
622 static T run(
float position, T start, T end) {
624 float postFix = position;
625 return static_cast<T
>((end - start) * (postFix) * position * ((s + 1) * position - s) + start);
635 static T run(
float position, T start, T end) {
638 return static_cast<T
>((end - start) * ((position) * position * ((s + 1) * position + s) + 1) + start);
648 static T run(
float position, T start, T end) {
652 auto c = end - start;
655 if ((t /= d / 2) < 1)
return static_cast<T
>(c / 2 * (t * t * (((s) + 1) * t - s)) + b);
656 float postFix = t -= 2;
657 return static_cast<T
>(c / 2 * ((postFix) * t * (((s) + 1) * t + s) + 2) + b);
enumerated
Enumerates all easings to aid in runtime when adding easins to a tween using tween::via.
Definition: easing.h:138
The easing class holds all the bundled easings.
Definition: easing.h:130
The tweeny namespace contains all symbols and names for the Tweeny library.
Definition: MANUAL.dox:1
Acceelerate initial values with a "back" equation.
Definition: easing.h:620
Acceelerate initial and deaccelerate ending values with a "back" equation.
Definition: easing.h:646
Deaccelerate ending values with a "back" equation.
Definition: easing.h:633
Acceelerate initial values with a "bounce" equation.
Definition: easing.h:516
Acceelerate initial and deaccelerate ending values with a "bounce" equation.
Definition: easing.h:550
Deaccelerate ending values with a "bounce" equation.
Definition: easing.h:527
Acceelerate initial values with a circular equation.
Definition: easing.h:476
Acceelerate initial and deaccelerate ending values with a circular equation.
Definition: easing.h:499
Deaccelerate ending values with a circular equation.
Definition: easing.h:487
Aaccelerate initial values with a cubic equation.
Definition: easing.h:281
Acceelerate initial and deaccelerate ending values with a cubic equation.
Definition: easing.h:304
Deaccelerate ending values with a cubic equation.
Definition: easing.h:292
Values change with constant speed for arithmetic type only. The non-arithmetic it will be constant.
Definition: easing.h:189
Acceelerate initial values with an "elastic" equation.
Definition: easing.h:562
Acceelerate initial and deaccelerate ending values with an "elastic" equation.
Definition: easing.h:596
Deaccelerate ending values with an "elastic" equation.
Definition: easing.h:580
Acceelerate initial values with an exponential equation.
Definition: easing.h:438
Acceelerate initial and deaccelerate ending values with an exponential equation.
Definition: easing.h:460
Deaccelerate ending values with an exponential equation.
Definition: easing.h:449
Values change with constant speed.
Definition: easing.h:226
Accelerate initial values with a quadratic equation.
Definition: easing.h:242
Acceelerate initial and deaccelerate ending values with a quadratic equation.
Definition: easing.h:264
Deaccelerate ending values with a quadratic equation.
Definition: easing.h:253
Acceelerate initial values with a quartic equation.
Definition: easing.h:320
Acceelerate initial and deaccelerate ending values with a quartic equation.
Definition: easing.h:343
Deaccelerate ending values with a quartic equation.
Definition: easing.h:331
Acceelerate initial values with a quintic equation.
Definition: easing.h:361
Acceelerate initial and deaccelerate ending values with a quintic equation.
Definition: easing.h:385
Deaccelerate ending values with a quintic equation.
Definition: easing.h:372
Acceelerate initial values with a sinusoidal equation.
Definition: easing.h:405
Acceelerate initial and deaccelerate ending values with a sinusoidal equation.
Definition: easing.h:427
Deaccelerate ending values with a sinusoidal equation.
Definition: easing.h:416
Value is constant.
Definition: easing.h:178