# Magnum::Animation::Easing namespace#include <Magnum/Animation/Easing.h>

Easing functions.

### Contents

A collection of predefined easing / tweening functions for adding life to animation interpolation.

This library is built as part of Magnum by default. To use this library with CMake, find the Magnum package and link to the Magnum::Magnum target:

find_package(Magnum REQUIRED)

# ...
target_link_libraries(your-app PRIVATE Magnum::Magnum)

The easing function is meant to be used to modify the interpolation factor, such as:

Vector3 result = Math::lerp(a, b, Animation::Easing::quadraticInOut(t));

The Animation library also provides the ease() utility that combines the interpolator together with the easing function:

auto lerpQuadraticInOut =

Vector3 result = lerpQuadraticInOut(a, b, t);

## Equations

Every function documentation shows a plot of its behavior, together with a direction in which it extrapolates. Green color means the extrapolation goes in a reasonable monotonic direction outside of the range (also denoted by E in the above list), red color means the extrapolation is defined, but behaves in a probably unwanted or non-monotonic way (denoted by E in the above list). If neither is present, it means the function is not defined outside of the range and produces a NaN. You may want to ensure the factor stays in bounds, using either Math::clamp() or the easeClamped() function — the following two expressions are equivalent:

auto lerpCircularOutClamped = Animation::easeClamped<

Vector3 result1 = Math::lerp(a, b,
Math::clamp(0.0f, 1.0f, Animation::Easing::circularOut(t)));
Vector3 result2 = lerpCircularOutClamped(a, b, t);

Out-function for a corresponding in-function is defined as the following, the equations in the docs usually just show the final derived form. Similarly goes for combined in-/out-function :

Easing functions defined by simple polynomials can have an exact (denoted by B in the above list) or approximate (denoted by B in the above list) cubic Math::Bezier curve representation (and thus, in turn, convertible to Cubic Hermite splines using Math::CubicHermite::fromBezier()). If that's the case, given function documentation also lists the corresponding Bézier representation and plots it with a thin blue line. The curve is always normalized to go from to , apply arbitrary transformation to each point as needed:

Matrix3 transformation;
CubicBezier2D easing;
CubicBezier2D transformed{
transformation.transformPoint(easing),
transformation.transformPoint(easing),
transformation.transformPoint(easing),
transformation.transformPoint(easing)};

## References

Functions follow the common naming from Robert Penner's Easing functions, http://robertpenner.com/easing/. Implementation based on and inspired by https://easings.net/, https://github.com/warrenm/AHEasing, https://github.com/bkaradzic/bx, https://blog.demofox.org/2014/08/28/one-dimensional-bezier-curves/.

## Functions

auto linear(Float t) -> Float
Linear.
auto step(Float t) -> Float
Step.
auto smoothstep(Float t) -> Float
Smoothstep.
auto smootherstep(Float t) -> Float
Smootherstep.
auto cubicIn(Float t) -> Float
Cubic in.
auto cubicOut(Float t) -> Float
Cubic out.
auto cubicInOut(Float t) -> Float
Cubic in and out.
auto quarticIn(Float t) -> Float
Quartic in.
auto quarticOut(Float t) -> Float
Quartic out.
auto quarticInOut(Float t) -> Float
Quartic in and out.
auto quinticIn(Float t) -> Float
Quintic in.
auto quinticOut(Float t) -> Float
Quintic out.
auto quinticInOut(Float t) -> Float
Quintic in and out.
auto sineIn(Float t) -> Float
Sine in.
auto sineOut(Float t) -> Float
Sine out.
auto sineInOut(Float t) -> Float
Sine in and out.
auto circularIn(Float t) -> Float
Circular in.
auto circularOut(Float t) -> Float
Circular out.
auto circularInOut(Float t) -> Float
Circular in and out.
auto exponentialIn(Float t) -> Float
Exponential in.
auto exponentialOut(Float t) -> Float
Exponential out.
auto exponentialInOut(Float t) -> Float
Exponential in and out.
auto elasticIn(Float t) -> Float
Elastic in.
auto elasticOut(Float t) -> Float
Elastic out.
auto elasticInOut(Float t) -> Float
Elastic in and out.
auto backIn(Float t) -> Float
Back in.
auto backOut(Float t) -> Float
Back out.
auto backInOut(Float t) -> Float
Back in and out.
auto bounceIn(Float t) -> Float
Bounce in.
auto bounceOut(Float t) -> Float
Bounce out.
auto bounceInOut(Float t) -> Float
Bounce in and out.

## Function documentation

### Float Magnum::Animation::Easing::linear(Float t)

Linear.

One possible exact Bézier representation:

CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f},
Vector2{2.0f/3.0f}, Vector2{1.0f}}

### Float Magnum::Animation::Easing::step(Float t)

Step.

Similar to Math::select(), but does the step in the middle of the range instead of at the end. Implementation matching the GLSL step() function with edge = 0.5f.

### Float Magnum::Animation::Easing::smoothstep(Float t)

Implementation matching the GLSL smoothstep() function. Combine with Math::lerp() to get the equivalent result:

Math::lerp(a, b, Animation::Easing::smoothstep(t));

Exact Bézier representation:

CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f, 0.0f},
Vector2{2.0f/3.0f, 1.0f}, Vector2{1.0f}}

### Float Magnum::Animation::Easing::smootherstep(Float t)

Improved version of smoothstep() by Ken Perlin.

Exact Bézier representation:

CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f, 0.0f},
Vector2{2.0f/3.0f, 1.0f/3.0f}, Vector2{1.0f}}

Exact Bézier representation:

CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f, 2.0f/3.0f},
Vector2{2.0f/3.0f, 1.0f}, Vector2{1.0f}}

Approximate Bézier representation:

CubicBezier2D{Vector2{0.0f}, Vector2{0.455f, 0.0f},
Vector2{0.545f, 1.0f}, Vector2{1.0f}}

### Float Magnum::Animation::Easing::cubicIn(Float t)

Cubic in.

Exact Bézier representation:

CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f, 0.0f},
Vector2{2.0f/3.0f, 0.0f}, Vector2{1.0f}}

### Float Magnum::Animation::Easing::cubicOut(Float t)

Cubic out.

Exact Bézier representation:

CubicBezier2D{Vector2{0.0f}, Vector2{1.0f/3.0f, 1.0f},
Vector2{2.0f/3.0f, 1.0f}, Vector2{1.0f}}

### Float Magnum::Animation::Easing::cubicInOut(Float t)

Cubic in and out.

Combination of cubicIn() and cubicOut().

Approximate Bézier representation:

CubicBezier2D{Vector2{0.0f}, Vector2{0.645f, 0.0f},
Vector2{0.355f, 1.0f}, Vector2{1.0f}}

Quartic in.

Quartic out.

### Float Magnum::Animation::Easing::quarticInOut(Float t)

Quartic in and out.

Combination of quarticIn() and quarticOut().

Quintic in.

Quintic out.

### Float Magnum::Animation::Easing::quinticInOut(Float t)

Quintic in and out.

Combination of quinticIn() and quinticOut().

Sine in.

Sine out.

### Float Magnum::Animation::Easing::sineInOut(Float t)

Sine in and out.

Combination of sineIn() and sineOut().

Circular in.

Circular out.

### Float Magnum::Animation::Easing::circularInOut(Float t)

Circular in and out.

Combination of circularIn() and circularOut().

### Float Magnum::Animation::Easing::exponentialIn(Float t)

Exponential in.

Contrary to Robert Penner's book but consistently with other implementations has a special case for , because otherwise.

### Float Magnum::Animation::Easing::exponentialOut(Float t)

Exponential out.

Contrary to Robert Penner's book but consistently with other implementations has a special case for , because otherwise.

### Float Magnum::Animation::Easing::exponentialInOut(Float t)

Exponential in and out.

Combination of exponentialIn() and exponentialOut(). Contrary to Robert Penner's book but consistently with other implementations has a special case for , because otherwise.

### Float Magnum::Animation::Easing::elasticIn(Float t)

Elastic in.

Combines sineIn() and exponentialIn().

### Float Magnum::Animation::Easing::elasticOut(Float t)

Elastic out.

Combines sineOut() and exponentialOut().

### Float Magnum::Animation::Easing::elasticInOut(Float t)

Elastic in and out.

Combination of elasticIn() and elasticOut() (or sineInOut() and exponentialInOut()).

Back in.

Back out.

### Float Magnum::Animation::Easing::backInOut(Float t)

Back in and out.

Combination of backIn() and backOut().

Bounce in.

Bounce out.

### Float Magnum::Animation::Easing::bounceInOut(Float t)

Bounce in and out.

Combination of bounceIn() and bounceOut().