anim

package
v0.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT, MIT Imports: 11 Imported by: 0 modules, 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

Package anim is the animation engine: easing curves, springs, tweens that sample them at a monotonic time, and the per-event table the config builds. It imports only the standard library and the solvers in lys-lib/motion.

Index

Constants

View Source
const (
	CommitAt = 0.5
)
View Source
const DefaultDuration = 250 * time.Millisecond
View Source
const FollowTolerance = 0.25
View Source
const (
	GenieStrips = 64
)
View Source
const (
	SettleTolerance = 1e-4
)

Variables

View Source
var (
	Linear    = Bezier{motion.NewCubicBezier(0, 0, 1, 1)}
	Ease      = Bezier{motion.NewCubicBezier(0.25, 0.1, 0.25, 1)}
	EaseIn    = Bezier{motion.NewCubicBezier(0.42, 0, 1, 1)}
	EaseOut   = Bezier{motion.NewCubicBezier(0, 0, 0.58, 1)}
	EaseInOut = Bezier{motion.NewCubicBezier(0.42, 0, 0.58, 1)}
	Smooth    = mustSpring(170, 26)

	Wobbly = mustSpring(200, 10)
)

Functions

func Builtins

func Builtins() map[string]Shape

func DefaultMotion

func DefaultMotion() map[Event]Setting

func FrugalMotion

func FrugalMotion() map[Event]Setting

func GenieAlongX

func GenieAlongX(from, to image.Rectangle) bool

func Lerp

func Lerp(from, to, p float64) float64

func LerpColor

func LerpColor(from, to [4]uint8, p float64) [4]uint8

func LerpRect

func LerpRect(from, to image.Rectangle, p float64) image.Rectangle

func Over

func Over(set, motion map[Event]Setting) map[Event]Setting

func RubberBand

func RubberBand(shown, delta, limit float64) float64

Types

type Bezier

type Bezier struct {
	// contains filtered or unexported fields
}

func NewBezier

func NewBezier(x1, y1, x2, y2 float64) (Bezier, error)

func (Bezier) Ease

func (b Bezier) Ease(x float64) float64

func (Bezier) Timed

func (b Bezier) Timed(d time.Duration, _ bool) (Curve, error)

type Curve

type Curve interface {
	At(elapsed time.Duration) float64
	Duration() time.Duration
}
var Instant Curve = instant{}

type Event

type Event uint8
const (
	Global Event = iota
	Windows
	WindowsMove
	WindowsIn
	WindowsOut
	Fade
	FadeIn
	FadeOut
	Workspaces
	Layers
	LayersIn
	LayersOut
	FadeSwitch
	FadeDim
	FadeShadow
	BorderAngle
	WindowsMinimize
	Zoom
	Snap
	FadeSnap
	Overview
	Scratchpad
)

func EventNamed

func EventNamed(name string) (Event, bool)

func Events

func Events() []Event

func (Event) String

func (e Event) String() string

type GenieStrip

type GenieStrip struct {
	From, Size float64
	Rect       image.Rectangle
}

func GenieLayout

func GenieLayout(out []GenieStrip, from, to image.Rectangle, p float64) (strips []GenieStrip, alongX bool)

GenieLayout cuts from into strips across the direction to to lies in and places them at progress p, 0 at from and 1 at to: the strips nearest to set off first, sliding down a funnel that narrows from from's width to to's.

func (GenieStrip) Source

func (s GenieStrip) Source(size image.Point, alongX bool) (x, y, w, h float64)

type Motion

type Motion struct {
	// contains filtered or unexported fields
}

func NewMotion

func NewMotion(at float64) Motion

func (Motion) At

func (m Motion) At(now time.Duration) float64

func (Motion) Done

func (m Motion) Done(now time.Duration) bool

func (*Motion) Jump

func (m *Motion) Jump(to float64)

func (*Motion) Set

func (m *Motion) Set(to float64, now time.Duration, c Curve)

type Progress

type Progress struct {
	// contains filtered or unexported fields
}

func NewProgress

func NewProgress(at float64) Progress

func (*Progress) At

func (p *Progress) At(now time.Duration) float64

func (*Progress) Done

func (p *Progress) Done(now time.Duration) bool

func (*Progress) Grab

func (p *Progress) Grab(now time.Duration)

func (*Progress) Projected

func (p *Progress) Projected(at time.Duration) float64

func (*Progress) Release

func (p *Progress) Release(target float64, at, now time.Duration, c Curve)

func (*Progress) Set

func (p *Progress) Set(target float64, now time.Duration, c Curve)

func (*Progress) Shift

func (p *Progress) Shift(by float64)

func (*Progress) Target

func (p *Progress) Target() float64

func (*Progress) Track

func (p *Progress) Track(to float64, at time.Duration)

func (*Progress) Tracking

func (p *Progress) Tracking() bool

func (*Progress) Velocity

func (p *Progress) Velocity(at time.Duration) float64

type RectMotion

type RectMotion struct {
	// contains filtered or unexported fields
}

func NewRectMotion

func NewRectMotion(at image.Rectangle) RectMotion

func (RectMotion) At

func (RectMotion) Done

func (m RectMotion) Done(now time.Duration) bool

func (*RectMotion) Jump

func (m *RectMotion) Jump(to image.Rectangle)

func (*RectMotion) Set

func (m *RectMotion) Set(to image.Rectangle, now time.Duration, c Curve)

func (RectMotion) Source

func (m RectMotion) Source() image.Rectangle

func (RectMotion) Target

func (m RectMotion) Target() image.Rectangle

func (RectMotion) Velocity

func (m RectMotion) Velocity(now time.Duration) [4]float64

type Setting

type Setting struct {
	Enabled  *bool
	Shape    Shape
	Duration *time.Duration
	Style    *Style
}

type Shape

type Shape interface {
	Timed(d time.Duration, explicit bool) (Curve, error)
}

type Spring

type Spring struct {
	// contains filtered or unexported fields
}

func NewSpring

func NewSpring(stiffness, damping, mass float64) (Spring, error)

func (Spring) At

func (s Spring) At(elapsed time.Duration) float64

func (Spring) Duration

func (s Spring) Duration() time.Duration

func (Spring) Timed

func (s Spring) Timed(_ time.Duration, explicit bool) (Curve, error)

type Style

type Style struct {
	Kind    StyleKind
	Percent float64
}

func ParseStyle

func ParseStyle(text string) (Style, error)

func (Style) String

func (s Style) String() string

type StyleKind

type StyleKind uint8
const (
	NoStyle StyleKind = iota
	Popin
	Slide
	SlideVert
	FadeStyle
	Once
	Loop
	Morph
	Elastic
	Goo
	Bud
	Genie
)

type Table

type Table struct {
	// contains filtered or unexported fields
}

func MustResolve

func MustResolve(motion map[Event]Setting) Table

func Resolve

func Resolve(enabled bool, settings map[Event]Setting) (Table, map[Event]error)

func ResolveReduced

func ResolveReduced(settings map[Event]Setting) (Table, map[Event]error)

func (Table) Curve

func (t Table) Curve(e Event) Curve

func (Table) Reduced

func (t Table) Reduced() bool

func (Table) Style

func (t Table) Style(e Event) Style

type Tween

type Tween[V any] struct {
	// contains filtered or unexported fields
}

func NewTween

func NewTween[V any](at V, lerp func(from, to V, p float64) V) Tween[V]

func (Tween[V]) At

func (t Tween[V]) At(now time.Duration) V

func (Tween[V]) Done

func (t Tween[V]) Done(now time.Duration) bool

func (*Tween[V]) Jump

func (t *Tween[V]) Jump(to V)

func (*Tween[V]) Set

func (t *Tween[V]) Set(to V, now time.Duration, c Curve)

func (Tween[V]) Source

func (t Tween[V]) Source() V

func (Tween[V]) Target

func (t Tween[V]) Target() V

type Wobble

type Wobble struct {
	// contains filtered or unexported fields
}

func NewWobble

func NewWobble(s Spring, cols, rows int, now time.Duration) *Wobble

func (*Wobble) Advance

func (w *Wobble) Advance(now time.Duration)

func (*Wobble) Grid

func (w *Wobble) Grid() (cols, rows int)

func (*Wobble) Offset

func (w *Wobble) Offset(i, j int) (dx, dy float64)

func (*Wobble) Resting

func (w *Wobble) Resting() bool

func (*Wobble) Shift

func (w *Wobble) Shift(dx, dy, grabU, grabV float64)

Jump to

Keyboard shortcuts

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