Module easing

Module easing 

Source
Expand description

Module containing different easing functions.

An easing function is a Curve that’s used to transition between two values. It takes a time parameter, where a time of zero means the start of the transition and a time of one means the end.

Easing functions come in a variety of shapes - one might transition smoothly, while another might have a bouncing motion.

There are several ways to use easing functions. The simplest option is a struct thats represents a single easing function, like SmoothStepCurve and StepsCurve. These structs can only transition from a value of zero to a value of one.

let smoothed_value = SmoothStepCurve.sample(time);
let stepped_value = StepsCurve(5, JumpAt::Start).sample(time);

Another option is EaseFunction. Unlike the single function structs, which require you to choose a function at compile time, EaseFunction lets you choose at runtime. It can also be serialized.

let mut curve = EaseFunction::Linear;

if make_it_smooth {
    curve = EaseFunction::SmoothStep;
}

let value = curve.sample(time);

The final option is EasingCurve. This lets you transition between any two values - not just zero to one. EasingCurve can use any value that implements the Ease trait, including vectors and directions.

// Make a curve that smoothly transitions between two positions.
let start_position = vec2(1.0, 2.0);
let end_position = vec2(5.0, 10.0);
let curve = EasingCurve::new(start_position, end_position, EaseFunction::SmoothStep);

let smoothed_position = curve.sample(time);

Like EaseFunction, the values and easing function of EasingCurve can be chosen at runtime and serialized.

Structs§

BackInCurve
f(t) = 2.70158 * t³ - 1.70158 * t²
BackInOutCurve
Behaves as BackIn for t < 0.5 and as BackOut for t >= 0.5
BackOutCurve
f(t) = 1.0 + 2.70158 * (t - 1.0)³ - 1.70158 * (t - 1.0)²
BounceInCurve
bouncy at the start!
BounceInOutCurve
Behaves as BounceIn for t < 0.5 and as BounceOut for t >= 0.5
BounceOutCurve
bouncy at the end!
CircularInCurve
f(t) = 1.0 - sqrt(1.0 - t²)
CircularInOutCurve
Behaves as CircularIn for t < 0.5 and as CircularOut for t >= 0.5
CircularOutCurve
f(t) = sqrt((2.0 - t) * t)
CubicInCurve
f(t) = t³
CubicInOutCurve
Behaves as CubicIn for t < 0.5 and as CubicOut for t >= 0.5
CubicOutCurve
f(t) = (t - 1.0)³ + 1.0
EasingCurve
A Curve that is defined by
ElasticCurve
f(omega,t) = 1 - (1 - t)²(2sin(omega * t) / omega + cos(omega * t)), parametrized by omega
ElasticInCurve
f(t) = -2.0^(10.0 * t - 10.0) * sin((t * 10.0 - 10.75) * 2.0 * π / 3.0)
ElasticInOutCurve
Behaves as ElasticIn for t < 0.5 and as ElasticOut for t >= 0.5
ElasticOutCurve
f(t) = 2.0^(-10.0 * t) * sin((t * 10.0 - 0.75) * 2.0 * π / 3.0) + 1.0
ExponentialInCurve
f(t) ≈ 2.0^(10.0 * (t - 1.0))
ExponentialInOutCurve
Behaves as ExponentialIn for t < 0.5 and as ExponentialOut for t >= 0.5
ExponentialOutCurve
f(t) ≈ 1.0 - 2.0^(-10.0 * t)
LinearCurve
f(t) = t
QuadraticInCurve
f(t) = t²
QuadraticInOutCurve
Behaves as QuadraticIn for t < 0.5 and as QuadraticOut for t >= 0.5
QuadraticOutCurve
f(t) = -(t * (t - 2.0))
QuarticInCurve
f(t) = t⁴
QuarticInOutCurve
Behaves as QuarticIn for t < 0.5 and as QuarticOut for t >= 0.5
QuarticOutCurve
f(t) = (t - 1.0)³ * (1.0 - t) + 1.0
QuinticInCurve
f(t) = t⁵
QuinticInOutCurve
Behaves as QuinticIn for t < 0.5 and as QuinticOut for t >= 0.5
QuinticOutCurve
f(t) = (t - 1.0)⁵ + 1.0
SineInCurve
f(t) = 1.0 - cos(t * π / 2.0)
SineInOutCurve
Behaves as SineIn for t < 0.5 and as SineOut for t >= 0.5
SineOutCurve
f(t) = sin(t * π / 2.0)
SmoothStepCurve
f(t) = 3t² - 2t³
SmoothStepInCurve
Behaves as the first half of SmoothStepCurve.
SmoothStepOutCurve
Behaves as the second half of SmoothStepCurve.
SmootherStepCurve
f(t) = 6t⁵ - 15t⁴ + 10t³
SmootherStepInCurve
Behaves as the first half of SmootherStepCurve.
SmootherStepOutCurve
Behaves as the second half of SmootherStepCurve.
StepsCurve
n steps connecting the start and the end. Jumping behavior is customizable via JumpAt. See JumpAt for all the options and visual examples.

Enums§

EaseFunction
Curve functions over the unit interval, commonly used for easing transitions.
JumpAt
Configuration options for the EaseFunction::Steps curves. This closely replicates the CSS step function specification.

Traits§

Ease
A type whose values can be eased between.