Easing Functions
28 easing functions in four categories: basic, In, Out, and InOut.
The Ease.Fn interface
Every easing function implements Ease.Fn, which takes a progress Double
(0.0–1.0) and returns the eased value. You can create custom easing functions with
easeFn:
import io.peekandpoke.ultra.maths.Ease
// Use a built-in function
val result = Ease.Out.cubic(0.5) // 0.875
// Create a custom easing function
val custom = Ease.easeFn { x -> x * x * x } // same as cubic In Basic easing
| Function | Behavior |
|---|---|
Ease.linear | Constant speed — output equals input |
Ease.stuck | Always returns 0.0 — no progress |
Ease.immediate | Always returns 1.0 — instant completion |
Ease.In — start slow, accelerate
| Function | Curve |
|---|---|
Ease.In.sine | Sinusoidal acceleration |
Ease.In.quad | Power of 2 (x²) |
Ease.In.cubic | Power of 3 (x³) |
Ease.In.quart | Power of 4 |
Ease.In.quint | Power of 5 |
Ease.In.pow(n) | Custom power (xⁿ) |
Ease.In.circ | Circular arc |
Ease.In.elastic | Oscillating spring overshoot |
Ease.In.bounce | Bouncing ball effect |
Ease.Out — start fast, decelerate
Same set of curves, mirrored: Ease.Out.sine, .quad, .cubic,
.quart, .quint, .pow(n), .circ,
.elastic, .bounce.
// Ease.Out starts fast and decelerates
val x = Ease.Out.bounce(0.7) // bouncing deceleration at 70% progress Ease.InOut — accelerate then decelerate
Combines In and Out: accelerates through the first half, decelerates through the second.
Available: Ease.InOut.sine, .quad, .cubic,
.quart, .quint, .pow(n),
.elastic, .bounce.
circ. If you need it, compose it with easeFn.// Smooth start and end — good for UI transitions
val opacity = Ease.calc(
from = 0.0,
to = 1.0,
progress = 0.5,
fn = Ease.InOut.cubic,
) Binding to a range
bindFromTo locks an easing function to a specific numeric range. The result is itself an
Ease.Fn, so it composes with everything else:
val scroll = Ease.InOut.quad.bindFromTo(from = 0, to = 1000)
// At various progress points:
scroll(0.0) // 0.0
scroll(0.25) // 125.0
scroll(0.5) // 500.0
scroll(0.75) // 875.0
scroll(1.0) // 1000.0 Time-based easing
timed() creates an easing that uses wall-clock time via the
Kronos clock. Call it repeatedly to get the current eased value:
import kotlin.time.Duration.Companion.milliseconds
val anim = Ease.Out.elastic.timed(
from = 0,
to = 100,
duration = 600.milliseconds,
)
// In a render loop or coroutine:
val value = anim { progress, done ->
// progress: 0.0 to 1.0
// done: true when duration has elapsed
}
// Or just check:
if (anim.isDone) { /* animation complete */ } Kronos instance to timed() to control time in tests.
No flaky timing-dependent assertions.