animclock

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: MIT Imports: 3 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 animclock is the animation scheduler the application loop drives: launched pieces, the frame deadlines the loop wakes on, and the tick that advances them. The public timeline API lives in package anim; only the loop and tests reach this package.

Index

Constants

View Source
const FrameInterval = time.Second / 60

FrameInterval is the frame period: the fallback pacing when the compositor's frame callbacks stop arriving, and the deadline granularity of Next while a piece is mid-flight.

Variables

This section is empty.

Functions

func Active

func Active() bool

Active reports whether any piece is still running or scheduled.

func Drive

func Drive(fn func(now time.Time) bool) (cancel func())

Drive runs fn once per frame with the frame's instant until it reports false (settled) or the returned cancel runs.

func Launch

func Launch(pieces []Piece) (cancel func())

Launch schedules pieces from the current instant and returns the cancel that stops every piece not yet finished. A piece with no duration and no offset lands at once, outside the schedule.

func Next

func Next() (time.Time, bool)

Next returns the earliest instant the loop must wake to keep the clock running: one frame past the last tick while a piece is mid-flight, or a later piece's start while a timeline holds in a delay. False means nothing runs and the loop may park.

func Now

func Now() time.Time

Now is the scheduler's current instant: the pinned one under SetClock.

func Reset

func Reset()

Reset drops every scheduled piece and driver.

func SetClock

func SetClock(fn func() time.Time) (restore func())

SetClock replaces the time source launches and deadlines read and returns the restore function; nil restores time.Now.

func Tick

func Tick(now time.Time) bool

Tick advances every running piece to now and drops finished or cancelled ones. Callbacks run after the pass settles with the lock released, so they may launch or cancel freely; a callback cancelling its own timeline still stops that timeline's later pieces in the same tick. It reports whether any callback ran.

Types

type Piece

type Piece struct {
	At, Dur time.Duration
	Fn      func(t float64)
	Easing  func(t float64) float64
}

Piece is one flattened step of a timeline: fn runs with Easing of linear progress over [At, At+Dur) from the launch instant.

Jump to

Keyboard shortcuts

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