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 Transform
- type Transformation
- 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}
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 TranslateDefault = Translate{Vec2f{0.0, 0.0}}
Functions ¶
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) PaintBounds ¶ added in v0.17.16
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 ¶
func ParseCurve ¶ added in v0.17.1
type CustomCurve ¶ added in v0.17.1
Custom curve implemented as a starlark function
func (CustomCurve) Transform ¶ added in v0.17.1
func (cc CustomCurve) Transform(t float64) float64
type DirectionImpl ¶ added in v0.17.7
func (DirectionImpl) FrameCount ¶ added in v0.17.7
func (self DirectionImpl) FrameCount(delay, duration int) int
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
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
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 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
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 InterpolateTransforms ¶ added in v0.17.7
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