anim

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

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

func EaseOutCubic(t float64) float64

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

func Shimmer(tick uint64, pos, width int) float64

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.

func Wave

func Wave(tick uint64, row int) float64

Wave is the brightness of one row of a running accent, offset per row so a column of them reads as a wave travelling down rather than as everything pulsing at once. The result is in [0.2, 1].

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL