motion

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 2 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

Package motion holds the two solvers animation is built on, a damped harmonic spring and a CSS cubic-bezier timing function, as pure maths over floats. lys-ui's anim and lys-wm's anim keep their own configuration on top: a response and damping fraction there, stiffness, damping and mass here. Results are the same bits on every architecture: products never fuse into an FMA and the transcendental functions come from gomath.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OverdampedRoots

func OverdampedRoots(omega, zeta float64) (r1, r2 float64)

OverdampedRoots are the two decay rates of an overdamped spring (zeta above 1), both negative, r1 the slower one that governs how long it takes to settle.

func SpringPosition

func SpringPosition(omega, zeta, x0, v0, dt float64) float64

SpringPosition is SpringStep's displacement alone, the same bits, for a caller that has no use for the velocity.

func SpringStep

func SpringStep(omega, zeta, x0, v0, dt float64) (x, v float64)

SpringStep is the damped harmonic oscillator's exact solution at angular frequency omega and damping ratio zeta: the displacement from the target and the velocity dt seconds after displacement x0 at velocity v0. A zeta of exactly 1 is the critically damped case, a negative one reads as 0, and a dt that is not positive returns the start unchanged.

Types

type CubicBezier

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

CubicBezier is a CSS cubic-bezier timing function, its control points reduced to polynomial coefficients. The zero value is not a curve; use NewCubicBezier. It is comparable.

func NewCubicBezier

func NewCubicBezier(x1, y1, x2, y2 float64) CubicBezier

NewCubicBezier returns cubic-bezier(x1, y1, x2, y2). x1 and x2 clamp to [0, 1], the range CSS admits, so the curve stays a function of time; the y controls are free, and overshoot when they leave [0, 1].

func (CubicBezier) Ease

func (b CubicBezier) Ease(x float64) float64

Ease is the progress at time x: exactly 0 at or before 0, exactly 1 at or after 1, and in between the curve's y where its x is x, the curve's parameter solved by Newton where it converges and bisection where it does not.

Jump to

Keyboard shortcuts

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