tween

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2020 License: ISC Imports: 1 Imported by: 0

README

tween

Golang animation package.

Developer's Guide

The file curves/ease.go is auto-generated using the following command in the project root directory:

go generate ./...

If you want to make changes to the ease functions edit curves/gen/gen.go and re-run "go generate".

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Engine

type Engine struct {
	Duration   time.Duration  // The total duration of the tween.
	Framerate  int            // The number of tween data points per second (defaults to 60 fps - like the real gamers use).
	Transition TransitionFunc // Transition calculates the transition curve for the tween.
	Updater    Updater        // Updater updates the tween values for each frame.
	// contains filtered or unexported fields
}

Engine runs a tween relying on transitioner and updater.

func NewEngine

func NewEngine(duration time.Duration, transition TransitionFunc, updater Updater) *Engine

NewEngine creates a basic tween Engine with a framerate of 60fps.

func (*Engine) Start

func (e *Engine) Start()

Start begins the tween running.

func (*Engine) Stop

func (e *Engine) Stop()

Stop terminates the tween immediately.

type Frame

type Frame struct {
	Completed    float64       // Completed is the percentage 0.0 - 1.0 of elapsed time.
	Transitioned float64       // Transitioned is the percentage 0.0 - 1.0 of transition between start and end values of the tween.
	Index        int           // Index is the current frame index
	Elapsed      time.Duration // Elapsed is the current elapsed time in the tween.
}

Frame captures information about the current "frame" of a tween transition.

type TransitionFunc

type TransitionFunc func(completed float64) float64

TransitionFunc calculates the percentage of the transition between the start and end values based tween (elapsed time) completion status. For example, a linear tween simply has a 1:1 ratio between completed and transition percentages and returns the completed value unchanged. An "ease in" transition may create a logorithmic relationship between the completion time and transition value for the first third, then a linear relationship for the remainder.

type Updater

type Updater interface {
	// Start signals the beginning of a tween and is sent before the tweening
	// begins. Start may be used to setup or pre-calculate updates.
	//
	// framerate is the number of frames per second in the tween
	// frames is the total number of frames that be generated
	// frameTime is the duration for each frame
	// runningTime is the total duration for the entire tween
	Start(framerate, frames int, frameTime, runningTime time.Duration)
	// Update receives information about the current Tween Frame and should be
	// used to update output or state.
	Update(Frame Frame)
	// End signals the end of the tween and is called after all updates.
	// End may be used to clean up resources (e.g. update channels).
	End()
}

Updater is the interface for updating the current value as it tweens between start and end values of a Tween.

Directories

Path Synopsis
Package curves adds standard transition curve implementations for the most commonly used tweens.
Package curves adds standard transition curve implementations for the most commonly used tweens.
gen

Jump to

Keyboard shortcuts

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