Documentation
¶
Overview ¶
Package anim is the arithmetic behind things that move.
It is pure functions of a tick and an eased value that advances one step at a time. Nothing here holds a clock, opens anything, or knows what a cell is: the loop decides when time passes, and what these numbers are then used for — brightening a colour, growing a pane — is the caller's.
Why ticks rather than durations ¶
A transition measured in wall-clock time has to ask what time it is, and a widget that asks what time it is cannot be stepped by a test or paused by a loop that parked because nothing was happening. Everything here counts ticks instead, and a tick is whatever the caller decided one is when they started a clock with Loop.Every. That makes an animation exactly as deterministic as the thing driving it, which is the property the rest of this library is built on.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EaseOutCubic ¶
EaseOutCubic maps a linear position in [0,1] to an eased one.
Out-cubic rather than anything else because it is the curve that reads as "arrived": most of the distance is covered early and the last part settles, which is what makes a pane that grows look like it stopped rather than like it was cut off.
func Shimmer ¶
Shimmer is the brightness at one column of a row being swept by a moving highlight — the "this is still arriving" effect on streamed text.
pos is the column, width the row's width, and the result is in [0.35, 1]. It is meant for [grid.Color.Blend]: blend the text's colour toward the background by one minus this, and the sweep reads as light rather than as characters changing.
Types ¶
type Transition ¶
type Transition struct {
// contains filtered or unexported fields
}
Transition moves a value toward a target over a number of ticks, eased.
The zero Transition is settled at zero and animates nothing, so a caller who never starts one pays for nothing. Transition.Tick is what advances it, and a caller with several can drive them all from the one clock they already have.
func (*Transition) Done ¶
func (t *Transition) Done() bool
Done reports whether the transition has arrived, which is what tells a loop it can stop the clock driving it.
func (*Transition) Tick ¶
func (t *Transition) Tick()
Tick advances the transition by one step. It is safe to keep calling after it has arrived, so a caller does not have to check before stepping.
func (*Transition) To ¶
func (t *Transition) To(target float64, span uint64)
To retargets the transition, starting from wherever it is now. A span of zero arrives immediately, which is how to set a value without animating it.
func (*Transition) Value ¶
func (t *Transition) Value() float64
Value is where the transition is now.