anim

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 5 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Spring driven scalars and rectangles for terminal motion

Index

Constants

View Source
const (
	// Angular frequency that settles most moves in about a third of a second
	DefaultFrequency = 13.0
	// Damping ratio that overshoots slightly before coming to rest
	DefaultDamping = 0.8
)

Variables

View Source
var (
	// Chrome that keeps up with the hand, settled in a quarter second without overshoot
	Snappy = Spring{Frequency: 18, Damping: 1}
	// Layout moves that land with a hint of overshoot
	Smooth = Spring{Frequency: DefaultFrequency, Damping: DefaultDamping}
	// Fades and veils that ease in without a bounce
	Gentle = Spring{Frequency: 10, Damping: 1}
	// Refusals that swing a few times before resting
	Rattle = Spring{Frequency: 36, Damping: 0.2}
)

Functions

This section is empty.

Types

type Clock

type Clock struct {
	Active int
	Idle   int
	// contains filtered or unexported fields
}

Schedules frames quickly while motion is active and slowly while the screen is at rest

func NewClock

func NewClock(active, idle int) Clock

Builds a clock with the given active and idle frame rates, defaulting to 60 and 30

func (*Clock) Accept

func (c *Clock) Accept(msg FrameMsg) (FrameMsg, bool)

Stamps a frame with its delta time, rejecting frames from stale schedules or other clocks

func (*Clock) Next

func (c *Clock) Next(active bool) tea.Cmd

Schedules the following frame at the active or idle rate

func (*Clock) Wake

func (c *Clock) Wake() tea.Cmd

Requests a frame immediately and invalidates any frame already pending

type FrameMsg

type FrameMsg struct {
	At time.Time
	DT float64
	// contains filtered or unexported fields
}

Delivered once per animation frame with the seconds elapsed since the previous frame

type Rect

type Rect struct {
	X, Y, W, H Value
}

Box whose edges animate independently, with size springs that never overshoot

func NewRect

func NewRect(x, y, w, h float64) Rect

Builds a resting rectangle

func (Rect) Cells

func (r Rect) Cells() (x, y, w, h int)

Current box rounded to whole cells, the far edges rounded on their own so neither side jitters

func (Rect) Distance

func (r Rect) Distance() float64

Largest remaining gap between any edge and its target

func (*Rect) Set

func (r *Rect) Set(x, y, w, h float64)

Retargets all four edges

func (*Rect) Snap

func (r *Rect) Snap()

Jumps every edge straight to its target

func (*Rect) Step

func (r *Rect) Step(dt float64) bool

Advances every edge by dt seconds and reports whether any is still moving

func (Rect) Target

func (r Rect) Target() (x, y, w, h int)

Destination box rounded to whole cells

type Spring

type Spring struct {
	Frequency float64
	Damping   float64
}

Response and bounce of a spring, named for the motion it gives

type Value

type Value struct {
	Pos       float64
	Vel       float64
	Target    float64
	Frequency float64
	Damping   float64
}

Scalar that eases toward its target with damped spring motion

func NewValue

func NewValue(v float64) Value

Builds a resting scalar with the default spring parameters

func NewValueWith

func NewValueWith(v float64, s Spring) Value

Builds a resting scalar that moves with the spring

func (*Value) Kick

func (v *Value) Kick(impulse float64)

Adds velocity so the scalar overshoots and springs back to its target

func (*Value) Set

func (v *Value) Set(target float64)

Retargets the motion while keeping the current position and velocity

func (Value) Settled

func (v Value) Settled() bool

Reports whether position and velocity are both inside the rest tolerance

func (*Value) Snap

func (v *Value) Snap()

Jumps straight to the target and stops

func (*Value) Step

func (v *Value) Step(dt float64) bool

Advances the spring by dt seconds and reports whether it is still moving

func (*Value) Use

func (v *Value) Use(s Spring)

Switches the motion to the spring without disturbing the position

Jump to

Keyboard shortcuts

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