Expand description
Tweening for self-drawn content (docs/tween.md): the pieces a canvas animation needs that native widgets get from their toolkit.
with_animation hands native widgets intent and lets each toolkit
animate on its own compositor. A canvas has no compositor to hand anything to: it re-records a
display list, so something has to decide, frame by frame, what the in-between picture is. That
something is built from four parts, each usable on its own:
Lerp: how a value moves between two states. Numbers, points, rects, tuples, arrays, vectors, and colors (blended in OKLab, so a heat map’s mid-transition cells are the colors in between rather than a muddy detour through gray).Timing: anAnimSpecsampled over elapsed seconds: delay, easing curve or spring, repeats and autoreverse, and a definite end, so a driver knows when to stop asking for frames.animate: a driver on the window’sFrameClock, calling a step closure once per display frame until the timing completes, then releasing the clock.Tweened: a reactive value that glides to each new target, starting from wherever it is when retargeted, so an interrupted transition bends instead of jumping.
stagger offsets one spec per item, for sequences (bars rising left to right).
Pairs is the step before any of them when what changed is a collection: it matches the
items of two states by key, gives the ones only one side has somewhere to come from or go to,
and interpolates the lot, so bars that trade places slide and a new one grows out of its
neighbor instead of the whole picture cross-fading.
Structs§
- Pair
- One item of a transition between two collections: where it starts, where it ends, and why.
- Pairs
- Two states of a collection, matched item by item, ready to be sampled at any
t. - Sample
- One sample of a
Timing: how far the value has come, and whether it has arrived. - Timing
- An
AnimSpecas a function of elapsed seconds. - Tweened
- A value that animates toward whatever it is told to become.
Enums§
Traits§
- Lerp
- A value that can be interpolated:
a.lerp(&b, 0.0)isa,a.lerp(&b, 1.0)isb.
Functions§
- animate
- Call
step(sample)once per display frame ofclockuntiltimingis done, then stop. - lerp
a + (b - a) * t, the scalar every other implementation is built from.- mix_
oklab - Blend two colors in OKLab by
t, alpha linearly.toutside0..=1extrapolates the lightness and hue axes and clamps the result into gamut. - stagger
spec, delayed for itemindexofcountso the items startspread_msapart in total: the first starts on time, the lastspread_mslater. Bars rising left to right, points popping in along a line: a sequence is one spec per item, and this is the arithmetic.