animation

package
v0.33.0 Latest Latest
Warning

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

Go to latest
Published: May 2, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCurve = LinearCurve{}
View Source
var DefaultDirection = DirectionNormal
View Source
var DefaultFillMode = FillModeForwards{}
View Source
var DefaultOrigin = Origin{
	X: Percentage{0.5},
	Y: Percentage{0.5},
}
View Source
var DefaultRounding = Round{}
View Source
var DirectionAlternate = DirectionImpl{Alternate: true, Reverse: false}
View Source
var DirectionAlternateReverse = DirectionImpl{Alternate: true, Reverse: true}
View Source
var DirectionNormal = DirectionImpl{Alternate: false, Reverse: false}
View Source
var DirectionReverse = DirectionImpl{Alternate: false, Reverse: true}
View Source
var EaseIn = CubicBezierCurve{0.3, 0, 1, 1}
View Source
var EaseInOut = CubicBezierCurve{0.65, 0, 0.35, 1}

TODO: figure out if what curve to use here. unless we're going back to Ivo's curve (0.3, 0, 0, 1), make sure to update the unit tests

var EaseInOut = CubicBezierCurve{0.3, 0, 0, 1}

View Source
var EaseOut = CubicBezierCurve{0, 0, 0, 1}
View Source
var RotateDefault = Rotate{0.0}
View Source
var ScaleDefault = Scale{Vec2f{1.0, 1.0}}
View Source
var TranslateDefault = Translate{Vec2f{0.0, 0.0}}

Functions

func Lerp added in v0.17.7

func Lerp(from, to, t float64) float64

func Rescale added in v0.17.7

func Rescale(fromMin, fromMax, toMin, toMax, v float64) float64

Types

type AnimatedPositioned

type AnimatedPositioned struct {
	render.Widget
	Child    render.Widget `starlark:"child,required"`
	XStart   int           `starlark:"x_start"`
	XEnd     int           `starlark:"x_end"`
	YStart   int           `starlark:"y_start"`
	YEnd     int           `starlark:"y_end"`
	Duration int           `starlark:"duration,required"`
	Curve    Curve         `starlark:"curve,required"`
	Delay    int           `starlark:"delay"`
	Hold     int           `starlark:"hold"`
}

Animate a widget from start to end coordinates.

**DEPRECATED**: Please use `animation.Transformation` instead.

DOC(Child): Widget to animate DOC(XStart): Horizontal start coordinate DOC(XEnd): Horizontal end coordinate DOC(YStart): Vertical start coordinate DOC(YEnd): Vertical end coordinate DOC(Duration): Duration of animation in frames DOC(Curve): Easing curve to use, default is 'linear' DOC(Delay): Delay before animation in frames DOC(Hold): Delay after animation in frames

func (AnimatedPositioned) FrameCount

func (o AnimatedPositioned) FrameCount() int

func (AnimatedPositioned) Paint

func (o AnimatedPositioned) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (AnimatedPositioned) PaintBounds added in v0.17.16

func (o AnimatedPositioned) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type CubicBezierCurve

type CubicBezierCurve struct {
	// contains filtered or unexported fields
}

Bezier curve defined by a, b, c and d.

func (CubicBezierCurve) Transform

func (cb CubicBezierCurve) Transform(t float64) float64

type Curve

type Curve interface {
	Transform(t float64) float64
}

func ParseCurve added in v0.17.1

func ParseCurve(str string) (Curve, error)

type CustomCurve added in v0.17.1

type CustomCurve struct {
	Function *starlark.Function
}

Custom curve implemented as a starlark function

func (CustomCurve) Transform added in v0.17.1

func (cc CustomCurve) Transform(t float64) float64

type Direction added in v0.17.7

type Direction interface {
	FrameCount(delay, duration int) int
	Progress(delay, duration int, fill float64, frameIdx int) float64
}

type DirectionImpl added in v0.17.7

type DirectionImpl struct {
	Alternate bool
	Reverse   bool
}

func (DirectionImpl) FrameCount added in v0.17.7

func (self DirectionImpl) FrameCount(delay, duration int) int

func (DirectionImpl) Progress added in v0.17.7

func (self DirectionImpl) Progress(delay, duration int, fill float64, frameIdx int) (progress float64)

type FillMode added in v0.17.7

type FillMode interface {
	Value() float64
}

type FillModeBackwards added in v0.17.7

type FillModeBackwards struct{}

func (FillModeBackwards) Value added in v0.17.7

func (self FillModeBackwards) Value() float64

type FillModeForwards added in v0.17.7

type FillModeForwards struct{}

func (FillModeForwards) Value added in v0.17.7

func (self FillModeForwards) Value() float64

type Keyframe added in v0.17.7

type Keyframe struct {
	Percentage Percentage  `starlark:"percentage,required"`
	Transforms []Transform `starlark:"transforms,required"`
	Curve      Curve       `starlark:"curve"`
}

A keyframe defining specific point in time in the animation.

The keyframe _percentage_ can is expressed as a floating point value between `0.0` and `1.0`.

DOC(Percentage): Percentage of the time at which this keyframe occurs through the animation. DOC(Transforms): List of transforms at this keyframe to interpolate to or from. DOC(Curve): Easing curve to use, default is 'linear'

type LinearCurve

type LinearCurve struct{}

Linear curve moving from 0 to 1 (wait for it...) linearly

func (LinearCurve) Transform

func (lc LinearCurve) Transform(t float64) float64

type Origin added in v0.17.7

type Origin struct {
	X Percentage `starlark:"x,required"`
	Y Percentage `starlark:"y,required"`
}

An relative anchor point to use for scaling and rotation transforms.

DOC(X): Horizontal anchor point DOC(Y): Vertical anchor point

func (Origin) Transform added in v0.17.7

func (self Origin) Transform(bounds image.Rectangle) Vec2f

type Percentage added in v0.17.7

type Percentage struct {
	Value float64
}

type Rotate added in v0.17.7

type Rotate struct {
	Angle float64 `starlark:"angle,required"`
}

Transform by rotating by a given angle in degrees.

DOC(Angle): Angle to rotate by in degrees

func (Rotate) Apply added in v0.17.7

func (self Rotate) Apply(ctx *gg.Context, origin Vec2f, rounding Rounding)

func (Rotate) Interpolate added in v0.17.7

func (self Rotate) Interpolate(other Transform, progress float64) (result Transform, ok bool)

type Round added in v0.17.7

type Round struct{}

func (Round) Apply added in v0.17.7

func (self Round) Apply(v float64) float64

type RoundCeil added in v0.17.7

type RoundCeil struct{}

func (RoundCeil) Apply added in v0.17.7

func (self RoundCeil) Apply(v float64) float64

type RoundFloor added in v0.17.7

type RoundFloor struct{}

func (RoundFloor) Apply added in v0.17.7

func (self RoundFloor) Apply(v float64) float64

type RoundNone added in v0.17.7

type RoundNone struct{}

func (RoundNone) Apply added in v0.17.7

func (self RoundNone) Apply(v float64) float64

type Rounding added in v0.17.7

type Rounding interface {
	Apply(v float64) float64
}

type Scale added in v0.17.7

type Scale struct {
	Vec2f
}

Transform by scaling by a given factor.

DOC(X): Horizontal scale factor DOC(Y): Vertical scale factor

func (Scale) Apply added in v0.17.7

func (self Scale) Apply(ctx *gg.Context, origin Vec2f, rounding Rounding)

func (Scale) Interpolate added in v0.17.7

func (self Scale) Interpolate(other Transform, progress float64) (result Transform, ok bool)

type Transform added in v0.17.7

type Transform interface {
	Apply(ctx *gg.Context, origin Vec2f, rounding Rounding)
	Interpolate(other Transform, progress float64) (result Transform, ok bool)
}

func ExtendTransforms added in v0.17.7

func ExtendTransforms(lhs []Transform, rhs []Transform) []Transform

func InterpolateTransforms added in v0.17.7

func InterpolateTransforms(lhs, rhs []Transform, progress float64) (result []Transform, ok bool)

See: https://www.w3.org/TR/css-transforms-1/#interpolation-of-transforms

type Transformation added in v0.17.7

type Transformation struct {
	render.Widget

	Child        render.Widget `starlark:"child,required"`
	Keyframes    []Keyframe    `starlark:"keyframes,required"`
	Duration     int           `starlark:"duration,required"`
	Delay        int           `starlark:"delay"`
	Width        int           `starlark:"width"`
	Height       int           `starlark:"height"`
	Origin       Origin        `starlark:"origin"`
	Direction    Direction     `starlark:"direction"`
	FillMode     FillMode      `starlark:"fill_mode"`
	Rounding     Rounding      `starlark:"rounding"`
	WaitForChild bool          `starlark:"wait_for_child"`
}

Transformation makes it possible to animate a child widget by transitioning between transforms which are applied to the child wiget.

It supports animating translation, scale and rotation of its child.

If you have used CSS transforms and animations before, some of the following concepts will be familiar to you.

Keyframes define a list of transforms to apply at a specific point in time, which is given as a percentage of the total animation duration.

A keyframe is created via `animation.Keyframe(percentage, transforms, curve)`.

The `percentage` specifies its point in time and can be expressed as a floating point number in the range `0.0` to `1.0`.

In case a keyframe at percentage 0% or 100% is missing, a default keyframe without transforms and with a "linear" easing curve is inserted.

As the animation progresses, transforms defined by the previous and next keyframe will be interpolated to determine the transform to apply at the current frame.

The `duration` and `delay` of the animation are expressed as a number of frames.

By default a transform `origin` of `animation.Origin(0.5, 0.5)` is used, which defines the anchor point for scaling and rotation to be exactly the center of the child widget. A different `origin` can be specified by providing a custom `animation.Origin`.

The animation `direction` defaults to `normal`, playing the animation forwards. Other possible values are `reverse` to play it backwards, `alternate` to play it forwards, then backwards or `alternate-reverse` to play it backwards, then forwards.

The animation `fill_mode` defaults to `forwards`, and controls which transforms will be applied to the child widget after the animation finishes. A value of `forwards` will retain the transforms of the last keyframe, while a value of `backwards` will rever to the transforms of the first keyframe.

When translating the child widget on the X- or Y-axis, it often is desireable to round to even integers, which can be controlled via `rounding`, which defaults to `round`. Possible values are `round` to round to the nearest integer, `floor` to round down, `ceil` to round up or `none` to not perform any rounding. Rounding only is applied for translation transforms, but not to scaling or rotation transforms.

If `wait_for_child` is set to `True`, the animation will finish and then wait for all child frames to play before restarting. If it is set to `False`, it will not wait.

DOC(Child): Widget to animate DOC(Keyframes): List of animation keyframes DOC(Duration): Duration of animation (in frames) DOC(Delay): Duration to wait before animation (in frames) DOC(Width): Width of the animation canvas DOC(Height): Height of the animation canvas DOC(Origin): Origin for transforms, default is '50%, 50%' DOC(Direction): Direction of the animation, default is 'normal' DOC(FillMode): Fill mode of the animation, default is 'forwards' DOC(Rounding): Rounding to use for interpolated translation coordinates (not used for scale and rotate), default is 'round' DOC(WaitForChild): Wait for all child frames to play after finishing

EXAMPLE BEGIN animation.Transformation(

child = render.Box(render.Circle(diameter = 6, color = "#0f0")),
duration = 100,
delay = 0,
origin = animation.Origin(0.5, 0.5),
direction = "alternate",
fill_mode = "forwards",
keyframes = [
  animation.Keyframe(
    percentage = 0.0,
    transforms = [animation.Rotate(0), animation.Translate(-10, 0), animation.Rotate(0)],
    curve = "ease_in_out",
  ),
  animation.Keyframe(
    percentage = 1.0,
    transforms = [animation.Rotate(360), animation.Translate(-10, 0), animation.Rotate(-360)],
  ),
],

), EXAMPLE END

func (*Transformation) FrameCount added in v0.17.7

func (self *Transformation) FrameCount() int

func (*Transformation) Init added in v0.17.7

func (self *Transformation) Init() error

func (*Transformation) Paint added in v0.17.7

func (self *Transformation) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)

func (*Transformation) PaintBounds added in v0.17.16

func (self *Transformation) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle

type Translate added in v0.17.7

type Translate struct {
	Vec2f
}

Transform by translating by a given offset.

DOC(X): Horizontal offset DOC(Y): Vertical offset

func (Translate) Apply added in v0.17.7

func (self Translate) Apply(ctx *gg.Context, origin Vec2f, rounding Rounding)

func (Translate) Interpolate added in v0.17.7

func (self Translate) Interpolate(other Transform, progress float64) (result Transform, ok bool)

type Vec2f added in v0.17.7

type Vec2f struct {
	X float64 `starlark:"x,required"`
	Y float64 `starlark:"y,required"`
}

func (Vec2f) Lerp added in v0.17.7

func (lhs Vec2f) Lerp(rhs Vec2f, progress float64) Vec2f

Jump to

Keyboard shortcuts

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