Skip to content

Easing

Easing functions for smooth animations and transitions.

Header: #include <asw/modules/easing.h>Namespace: asw::easing

Type Alias

cpp
using EaseFunc = float (*)(float);

All easing functions take a progress value t (0.0 - 1.0) and return the eased value.

Functions

Linear

FunctionDescription
linear(float t)No easing, linear interpolation

Quadratic

FunctionDescription
easeInQuad(float t)Accelerating from zero
easeOutQuad(float t)Decelerating to zero
easeInOutQuad(float t)Acceleration then deceleration

Cubic

FunctionDescription
easeInCubic(float t)Accelerating from zero (steeper)
easeOutCubic(float t)Decelerating to zero (steeper)
easeInOutCubic(float t)Acceleration then deceleration (steeper)

Sine

FunctionDescription
easeInSine(float t)Sinusoidal ease in
easeOutSine(float t)Sinusoidal ease out
easeInOutSine(float t)Sinusoidal ease in and out

Exponential

FunctionDescription
easeInExpo(float t)Exponential ease in
easeOutExpo(float t)Exponential ease out
easeInOutExpo(float t)Exponential ease in and out

Elastic

FunctionDescription
easeInElastic(float t)Elastic spring effect (ease in)
easeOutElastic(float t)Elastic spring effect (ease out)

Bounce

FunctionDescription
easeInBounce(float t)Bounce effect (ease in)
easeOutBounce(float t)Bounce effect (ease out)

Back (Overshoot)

FunctionDescription
easeInBack(float t)Slight overshoot (ease in)
easeOutBack(float t)Slight overshoot (ease out)

Convenience

ease

cpp
template <typename T>
T ease(const T& a, const T& b, float t, EaseFunc func);

Apply an easing function and interpolate between two values. The progress t is clamped to 0.0 - 1.0.

ParameterTypeDescription
aconst T&Start value
bconst T&End value
tfloatProgress (0.0 - 1.0)
funcEaseFuncEasing function to apply

Example

cpp
float progress = elapsedTime / totalTime;

// Ease a float value
float x = asw::easing::ease(0.0f, 100.0f, progress, asw::easing::easeOutQuad);

// Ease a Vec2
asw::Vec2<float> start(0.0f, 0.0f);
asw::Vec2<float> end(200.0f, 100.0f);
auto pos = asw::easing::ease(start, end, progress, asw::easing::easeInOutCubic);

// Use individual functions directly
float t = asw::easing::easeOutBounce(progress);

Released under the MIT License.