animation

package
v0.0.0-...-b509ac4 Latest Latest
Warning

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

Go to latest
Published: Dec 7, 2023 License: GPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrFramebufferOverflow = errors.New("framebuffer overflow")

ErrFramebufferOverflow is returned when the framebuffer is full.

Functions

This section is empty.

Types

type Frame

type Frame[Image any] struct {
	Image          Image
	JumpBackAmount int32
	DurationMs     Milliseconds
}

Frame is a single frame of an animation.

func (Frame[Image]) Duration

func (f Frame[Image]) Duration() time.Duration

Duration returns the duration of the frame as a time.Duration.

type Milliseconds

type Milliseconds uint32

Milliseconds is a duration in milliseconds.

func DurationToMs

func DurationToMs(d time.Duration) Milliseconds

DurationToMs converts a time.Duration to Milliseconds. The duration is rounded down to the nearest millisecond.

type Player

type Player[Image any] struct {
	C <-chan Frame[Image]
	// contains filtered or unexported fields
}

Player is an animation player. It is safe to use from multiple goroutines.

func NewPlayer

func NewPlayer[Image any]() *Player[Image]

NewPlayer creates a new animation player that can hold up to maxFrames frames.

func NewPlayerWithSize

func NewPlayerWithSize[Image any](maxFrames int) *Player[Image]

NewPlayerWithSize creates a new animation player that can hold up to maxFrames frames.

func (*Player[Image]) AddFrame

func (p *Player[Image]) AddFrame(ctx context.Context, frame Frame[Image]) error

AddFrames adds a frame to the animation. If the player is full, the function blocks until there is room for the frame.

func (*Player[Image]) AddFrames

func (p *Player[Image]) AddFrames(ctx context.Context, frames []Frame[Image]) error

AddFrames adds multiple frames to the animation. If the player is full, the function blocks until there is room for the frames.

func (*Player[Image]) Run

func (p *Player[Image]) Run(ctx context.Context) error

Run starts playing the animation. Run returns when the animation is finished or when the context is canceled.

Jump to

Keyboard shortcuts

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