anim

package
v0.0.0-...-225857b Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2025 License: BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Overview

Package anim contains primitives for animation.

The core of the package is the Playable interface, which just represents a series of keyframes. What is at each keyframe is completely abstract and generic. For example, it could be a row/column pair indexing into a tilesheet, or it could be point on a parametric curve.

The package provides several wrappers for a Playable to generically modify its behavior, such as:

  • Reversed, which reverses the order of the keyframes.
  • Delayed, which inserts additional frames between each keyframe.
  • PingPonged, which plays the keyframes in reverse order after playing them forward once.

These wrappers compose with one another. This means that an animation's keyframes can generally be separated from how they're actually played back.

Player is a type which can actually play back a Playable, expressed loosely as a pull iterator (which is more flexible in, for example, game engine contexts).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Delayed

type Delayed[A Playable[T], T any] struct {
	// contains filtered or unexported fields
}

Delayed is a wrapper type that represents an animation with additional delays inserted between frames.

func Delay

func Delay[A Playable[T], T any](anim A, delay int) Delayed[A, T]

Delay inserts delays in between each frame.

That is, Next will advance through multiples of the same frame before advancing to the next one.

A delay of 0 represents no change. A delay of 1 is a doubling of every frame (half the frame rate).

func (Delayed[A, T]) At

func (d Delayed[A, T]) At(i int) T

At implements Playable.

func (Delayed[A, T]) Len

func (d Delayed[A, T]) Len() int

Len implements Playable.

type PingPonged

type PingPonged[A Playable[T], T any] struct {
	// contains filtered or unexported fields
}

PingPonged is a wrapper type that represents a reversed animation.

func PingPong

func PingPong[A Playable[T], T any](anim A) PingPonged[A, T]

PingPong causes the animation to ping pong (proceed forward, then backward) before completing.

func (PingPonged[A, T]) At

func (p PingPonged[A, T]) At(i int) T

At implements Playable.

func (PingPonged[A, T]) Len

func (p PingPonged[A, T]) Len() int

Len implements Playable.

type Playable

type Playable[T any] interface {
	// At returns the value at the i'th keyframe.
	At(i int) T

	// Len returns the number of keyframes.
	Len() int
}

Playable is an interface that describes an animation in terms of keyframes.

Really, it just describes any finite sequence.

type Player

type Player[T any] struct {
	// contains filtered or unexported fields
}

Player plays back an animation.

Really, it is a pull iterator that produces values from a finite sequence.

func (*Player[T]) Current

func (p *Player[T]) Current() T

Current returns the value of the current frame in the animation.

func (*Player[T]) Done

func (p *Player[T]) Done() bool

Done returns true if the animation has completed.

func (*Player[T]) Loop

func (p *Player[T]) Loop(anim Playable[T])

Loop begins playing back the provided animation. The animation will loop forever.

This immediately overrides any current animation playing.

func (*Player[T]) Next

func (p *Player[T]) Next() bool

Next advances the animation.

Returns true if the animation has completed.

func (*Player[T]) Start

func (p *Player[T]) Start(anim Playable[T])

Start begins playing back the provided animation. The animation will play through once, then stop.

This immediately overrides any current animation playing.

type Reversed

type Reversed[A Playable[T], T any] struct {
	// contains filtered or unexported fields
}

Reversed is a wrapper type that represents a reversed animation.

func Reverse

func Reverse[A Playable[T], T any](anim A) Reversed[A, T]

Reverse reverses an animation by wrapping it with a Reversed.

func (Reversed[A, T]) At

func (r Reversed[A, T]) At(i int) T

At implements Playable.

func (Reversed[A, T]) Len

func (r Reversed[A, T]) Len() int

Len implements Playable.

Jump to

Keyboard shortcuts

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