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§
- Back
InCurve f(t) = 2.70158 * t³ - 1.70158 * t²
- Back
InOut Curve - Behaves as
BackIn
for t < 0.5 and asBackOut
for t >= 0.5 - Back
OutCurve f(t) = 1.0 + 2.70158 * (t - 1.0)³ - 1.70158 * (t - 1.0)²
- Bounce
InCurve - bouncy at the start!
- Bounce
InOut Curve - Behaves as
BounceIn
for t < 0.5 and asBounceOut
for t >= 0.5 - Bounce
OutCurve - bouncy at the end!
- Circular
InCurve f(t) = 1.0 - sqrt(1.0 - t²)
- Circular
InOut Curve - Behaves as
CircularIn
for t < 0.5 and asCircularOut
for t >= 0.5 - Circular
OutCurve f(t) = sqrt((2.0 - t) * t)
- Cubic
InCurve f(t) = t³
- Cubic
InOut Curve - Behaves as
CubicIn
for t < 0.5 and asCubicOut
for t >= 0.5 - Cubic
OutCurve f(t) = (t - 1.0)³ + 1.0
- Easing
Curve - A
Curve
that is defined by - Elastic
Curve f(omega,t) = 1 - (1 - t)²(2sin(omega * t) / omega + cos(omega * t))
, parametrized byomega
- Elastic
InCurve f(t) = -2.0^(10.0 * t - 10.0) * sin((t * 10.0 - 10.75) * 2.0 * π / 3.0)
- Elastic
InOut Curve - Behaves as
ElasticIn
for t < 0.5 and asElasticOut
for t >= 0.5 - Elastic
OutCurve f(t) = 2.0^(-10.0 * t) * sin((t * 10.0 - 0.75) * 2.0 * π / 3.0) + 1.0
- Exponential
InCurve f(t) ≈ 2.0^(10.0 * (t - 1.0))
- Exponential
InOut Curve - Behaves as
ExponentialIn
for t < 0.5 and asExponentialOut
for t >= 0.5 - Exponential
OutCurve f(t) ≈ 1.0 - 2.0^(-10.0 * t)
- Linear
Curve f(t) = t
- Quadratic
InCurve f(t) = t²
- Quadratic
InOut Curve - Behaves as
QuadraticIn
for t < 0.5 and asQuadraticOut
for t >= 0.5 - Quadratic
OutCurve f(t) = -(t * (t - 2.0))
- Quartic
InCurve f(t) = t⁴
- Quartic
InOut Curve - Behaves as
QuarticIn
for t < 0.5 and asQuarticOut
for t >= 0.5 - Quartic
OutCurve f(t) = (t - 1.0)³ * (1.0 - t) + 1.0
- Quintic
InCurve f(t) = t⁵
- Quintic
InOut Curve - Behaves as
QuinticIn
for t < 0.5 and asQuinticOut
for t >= 0.5 - Quintic
OutCurve f(t) = (t - 1.0)⁵ + 1.0
- Sine
InCurve f(t) = 1.0 - cos(t * π / 2.0)
- Sine
InOut Curve - Behaves as
SineIn
for t < 0.5 and asSineOut
for t >= 0.5 - Sine
OutCurve f(t) = sin(t * π / 2.0)
- Smooth
Step Curve f(t) = 3t² - 2t³
- Smooth
Step InCurve - Behaves as the first half of
SmoothStepCurve
. - Smooth
Step OutCurve - Behaves as the second half of
SmoothStepCurve
. - Smoother
Step Curve f(t) = 6t⁵ - 15t⁴ + 10t³
- Smoother
Step InCurve - Behaves as the first half of
SmootherStepCurve
. - Smoother
Step OutCurve - Behaves as the second half of
SmootherStepCurve
. - Steps
Curve n
steps connecting the start and the end. Jumping behavior is customizable viaJumpAt
. SeeJumpAt
for all the options and visual examples.
Enums§
- Ease
Function - 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.