Skip to main content

Module tween

Module tween 

Source
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: an AnimSpec sampled 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’s FrameClock, 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 AnimSpec as a function of elapsed seconds.
Tweened
A value that animates toward whatever it is told to become.

Enums§

Change
Which side of a change an item of a Pairs is on.

Traits§

Lerp
A value that can be interpolated: a.lerp(&b, 0.0) is a, a.lerp(&b, 1.0) is b.

Functions§

animate
Call step(sample) once per display frame of clock until timing is 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. t outside 0..=1 extrapolates the lightness and hue axes and clamps the result into gamut.
stagger
spec, delayed for item index of count so the items start spread_ms apart in total: the first starts on time, the last spread_ms later. Bars rising left to right, points popping in along a line: a sequence is one spec per item, and this is the arithmetic.
Day API ↩ Guides· daybrite.dev