Documentation
¶
Index ¶
- Variables
- func Lerp(from, to, t float64) float64
- func Rescale(fromMin, fromMax, toMin, toMax, v float64) float64
- type AnimatedPositioned
- type CubicBezierCurve
- type Curve
- type CustomCurve
- type Direction
- type DirectionImpl
- type FillMode
- type FillModeBackwards
- type FillModeForwards
- type Keyframe
- type LinearCurve
- type Origin
- type Percentage
- type Rotate
- type Round
- type RoundCeil
- type RoundFloor
- type RoundNone
- type Rounding
- type Scale
- type Shear
- type Transform
- type Transformation
- func (t *Transformation) FrameCount(bounds image.Rectangle) int
- func (t *Transformation) Init(thread *starlark.Thread) error
- func (t *Transformation) Paint(dc *gg.Context, bounds image.Rectangle, frameIdx int)
- func (t *Transformation) PaintBounds(bounds image.Rectangle, frameIdx int) image.Rectangle
- type Translate
- type Vec2f
Constants ¶
This section is empty.
Variables ¶
var DefaultCurve = LinearCurve{}
var DefaultDirection = DirectionNormal
var DefaultFillMode = FillModeForwards{}
var DefaultOrigin = Origin{ X: Percentage{0.5}, Y: Percentage{0.5}, }
var DefaultRounding = Round{}
var DirectionAlternate = DirectionImpl{Alternate: true, Reverse: false}
var DirectionAlternateReverse = DirectionImpl{Alternate: true, Reverse: true}
var DirectionNormal = DirectionImpl{Alternate: false, Reverse: false}
var DirectionReverse = DirectionImpl{Alternate: false, Reverse: true}
var EaseIn = CubicBezierCurve{0.3, 0, 1, 1}
var EaseInOut = CubicBezierCurve{0.65, 0, 0.35, 1}
EaseInOut is a cubic-bezier curve.
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}.
var EaseOut = CubicBezierCurve{0, 0, 0, 1}
var RotateDefault = Rotate{0.0}
var ScaleDefault = Scale{Vec2f{1.0, 1.0}}
var ShearDefault = Shear{}
var TranslateDefault = Translate{Vec2f{0.0, 0.0}}
Functions ¶
Types ¶
type AnimatedPositioned ¶
type AnimatedPositioned struct {
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"`
}
AnimatedPositioned animates 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(bounds image.Rectangle) int
func (AnimatedPositioned) PaintBounds ¶
type CubicBezierCurve ¶
type CubicBezierCurve struct {
// contains filtered or unexported fields
}
CubicBezierCurve is a Bezier curve defined by a, b, c and d.
func (CubicBezierCurve) Transform ¶
func (cb CubicBezierCurve) Transform(t float64) float64
type Curve ¶
func ParseCurve ¶
type CustomCurve ¶
CustomCurve is a custom curve implemented as a starlark function.
func (CustomCurve) Transform ¶
func (cc CustomCurve) Transform(t float64) float64
type DirectionImpl ¶
func (DirectionImpl) FrameCount ¶
func (d DirectionImpl) FrameCount(delay, duration int) int
type FillModeBackwards ¶
type FillModeBackwards struct{}
func (FillModeBackwards) Value ¶
func (f FillModeBackwards) Value() float64
type FillModeForwards ¶
type FillModeForwards struct{}
func (FillModeForwards) Value ¶
func (f FillModeForwards) Value() float64
type Keyframe ¶
type Keyframe struct {
Percentage Percentage `starlark:"percentage,required"`
Transforms []Transform `starlark:"transforms,required"`
Curve Curve `starlark:"curve"`
}
Keyframe defines a 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{}
LinearCurve is a linear curve moving from 0 to 1 (wait for it...) linearly.
func (LinearCurve) Transform ¶
func (lc LinearCurve) Transform(t float64) float64
type Origin ¶
type Origin struct {
X Percentage `starlark:"x,required"`
Y Percentage `starlark:"y,required"`
}
Origin is a relative anchor point to use for scaling and rotation transforms.
DOC(X): Horizontal anchor point DOC(Y): Vertical anchor point.
type Percentage ¶
type Percentage struct {
Value float64
}
type Rotate ¶
type Rotate struct {
Angle float64 `starlark:"angle,required"`
}
Rotate transforms by rotating by a given angle in degrees.
DOC(Angle): Angle to rotate by in degrees.
type RoundFloor ¶
type RoundFloor struct{}
func (RoundFloor) Apply ¶
func (rf RoundFloor) Apply(v float64) float64
type Scale ¶
type Scale struct {
Vec2f
}
Scale transforms by scaling by a given factor.
DOC(X): Horizontal scale factor DOC(Y): Vertical scale factor.
type Shear ¶ added in v0.49.9
Shear transforms by shearing by a given X and Y angle in degrees.
DOC(XAngle): The angle to shear horizontally in degrees. DOC(YAngle): The angle to shear vertically in degrees.
type Transform ¶
type Transform interface {
Apply(ctx *gg.Context, origin Vec2f, rounding Rounding)
Interpolate(other Transform, progress float64) (result Transform, ok bool)
}
func ExtendTransforms ¶
func InterpolateTransforms ¶
InterpolateTransforms interpolates between two lists of transforms.
See: https://www.w3.org/TR/css-transforms-1/#interpolation-of-transforms
type Transformation ¶
type Transformation struct {
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 desirable 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 ¶
func (t *Transformation) FrameCount(bounds image.Rectangle) int