animate

– import “gomatcha.io/matcha/animate”

Package animate implements animations, easings and interpolaters.

func ColorInterpolate

func ColorInterpolate(n comm.Float64Notifier, l ColorInterpolater) comm.ColorNotifier

ColorInterpolate wraps n and returns a notifier with the corresponding interpolated colors.

func FloatInterpolate

func FloatInterpolate(w comm.Float64Notifier, l FloatInterpolater) comm.Float64Notifier

FloatInterpolate wraps n and returns a notifier with the corresponding interpolated floats.

type Animation

type Animation interface {
	Duration() time.Duration
	Tick(time.Duration) float64
}

Animation is an interface that represents a float64 that changes over a fixed duration.

type Basic

type Basic struct {
	Start float64
	End   float64
	Ease  FloatInterpolater
	Dur   time.Duration // Duration
}

Basic is an animation that goes from Start to End with duration Dur.

func (*Basic) Duration

func (a *Basic) Duration() time.Duration

Duration implements the Animation interface.

func (*Basic) Tick

func (a *Basic) Tick(t time.Duration) float64

Tick implements the Animation interface.

type ColorInterpolater

type ColorInterpolater interface {
	Interpolate(float64) color.Color
}

ColorInterpolater represents an object that interpolates between colors given a float64 between 0-1.

type CubicBezierEase

type CubicBezierEase struct {
	X0, Y0, X1, Y1 float64
}

CubicBezierEase interpolates between 1-0 using a Cubic Bézier curve. The parameters are cubic control parameters. The curve starts at (0,0) going toward (x0,y0), and arrives at (1,1) coming from (x1,y1).

func (CubicBezierEase) Interpolate

func (e CubicBezierEase) Interpolate(a float64) float64

Interpolate implements the Interpolater interface.

func (CubicBezierEase) Notifier

func (e CubicBezierEase) Notifier(a comm.Float64Notifier) comm.Float64Notifier

Notifier is a convenience method around animate.FloatInterpolate(n, e).

type FloatInterpolater

type FloatInterpolater interface {
	Interpolate(float64) float64
}

ColorInterpolater represents an object that interpolates between floats given a float64 between 0-1.

var (
	DefaultEase      FloatInterpolater = CubicBezierEase{0.25, 0.1, 0.25, 1}
	DefaultInEase    FloatInterpolater = CubicBezierEase{0.42, 0, 1, 1}
	DefaultOutEase   FloatInterpolater = CubicBezierEase{0, 0, 0.58, 1}
	DefaultInOutEase FloatInterpolater = CubicBezierEase{0.42, 0, 0.58, 1}
)

type FloatLerp

type FloatLerp struct {
	Start, End float64
}

FloatLerp interpolates between Start and End linearly.

func (FloatLerp) Interpolate

func (f FloatLerp) Interpolate(a float64) float64

Interpolate implements the Interpolater interface.

func (FloatLerp) Notifier

func (e FloatLerp) Notifier(a comm.Float64Notifier) comm.Float64Notifier

Notifier is a convenience method around animate.FloatInterpolate(n, e)

type LinearEase

type LinearEase struct {
}

LinearEase interpolates between 1-0 in a linear fashion.

func (LinearEase) Interpolate

func (e LinearEase) Interpolate(a float64) float64

Interpolate implements the Interpolater interface.

func (LinearEase) Notifier

func (e LinearEase) Notifier(a comm.Float64Notifier) comm.Float64Notifier

Notifier is a convenience method around animate.FloatInterpolate(n, e)

type PolyInEase

type PolyInEase struct {
	Exp float64
}

PolyInEase interpolates between Start and End with a polynomial easing.

func (PolyInEase) Interpolate

func (e PolyInEase) Interpolate(a float64) float64

Interpolate implements the Interpolater interface.

func (PolyInEase) Notifier

func (e PolyInEase) Notifier(a comm.Float64Notifier) comm.Float64Notifier

Notifier is a convenience method around animate.FloatInterpolate(n, e)

type PolyInOutEase

type PolyInOutEase struct {
	ExpIn  float64
	ExpOut float64
}

PolyInOutEase interpolates between Start and End with a symmetric polynomial easing.

func (PolyInOutEase) Interpolate

func (e PolyInOutEase) Interpolate(a float64) float64

Interpolate implements the Interpolater interface.

func (PolyInOutEase) Notifier

func (e PolyInOutEase) Notifier(a comm.Float64Notifier) comm.Float64Notifier

Notifier is a convenience method around animate.FloatInterpolate(n, e)

type PolyOutEase

type PolyOutEase struct {
	Exp float64
}

PolyOutEase interpolates between Start and End with a reverse polynomial easing.

func (PolyOutEase) Interpolate

func (e PolyOutEase) Interpolate(a float64) float64

Interpolate implements the Interpolater interface.

func (PolyOutEase) Notifier

func (e PolyOutEase) Notifier(a comm.Float64Notifier) comm.Float64Notifier

Notifier is a convenience method around animate.FloatInterpolate(n, e)

type RGBALerp

type RGBALerp struct {
	Start, End color.Color
}

RGBALerp interpolates between colors Start and End.

func (RGBALerp) Interpolate

func (e RGBALerp) Interpolate(a float64) color.Color

Interpolate implements the ColorInterpolater interface

func (RGBALerp) Notifier

func (e RGBALerp) Notifier(n comm.Float64Notifier) comm.ColorNotifier

Notifier is a convenience method around animate.ColorInterpolate(n, e)

type Value

type Value struct {
}

Value is an struct that runs Animations and emits float64s.

func (*Value) Notify

func (v *Value) Notify(f func()) comm.Id

Notify implements the comm.Notifier interface.

func (*Value) Run

func (v *Value) Run(a Animation) (cancelFunc func())

Run runs animation a on v. Cancels any previously running animations on v.

func (*Value) SetValue

func (v *Value) SetValue(val float64)

SetValue updates Value, calls any subscribed functions and cancels any running animations.

func (*Value) Unnotify

func (v *Value) Unnotify(id comm.Id)

Unnotify implements the comm.Notifier interface.

func (*Value) Value

func (v *Value) Value() float64

Value returns the current value of v.