Aego Русский

aego/curve

Ease takes a preset such as curve.OutCubic and a time from 0 to 1. Eval, EvalClamped and Duration take a Curve, which comes from a curve field of a component (fader.Alpha); the documentation sandbox has no component with a curve field, so the example uses Ease. See Curves.

On this page

Example

package demo

import (
    "aego/curve"
    "aego/log"
    "aego/math"
)

script Slide {
    @export var From Vec2 = Vec2{0, 0}
    @export var To Vec2 = Vec2{4, 0}
    @export var Duration float = 1.5

    var age float

    func Ready() {
        log.Info("at t=0.5: linear " + string(curve.Ease(curve.Linear, 0.5)) + ", in quad " + string(curve.Ease(curve.InQuad, 0.5)) + ", out cubic " + string(curve.Ease(curve.OutCubic, 0.5)))
        log.Info("out back overshoots: " + string(curve.Ease(curve.OutBack, 0.8)))
    }

    func Update(dt float) {
        if age >= Duration {
            return
        }
        age += dt
        k := curve.Ease(curve.InOutSine, age / Duration)
        node.SetPosition(math.LerpVec2(From, To, k))
        if age >= Duration {
            log.Info("arrived at x=" + string(node.Position().X))
        } else if int(age * 60) % 15 == 0 {
            log.Info("x=" + string(node.Position().X))
        }
    }
}

Functions

Duration(curve Curve) floatReturns the time between the first and the last key, 1 for a preset.
Ease(easing aego/curve.Easing, t float) floatReturns a preset easing at t, clamped to 0..1.
Eval(curve Curve, t float) floatReturns the value of a curve at time t; outside its keys the curve repeats as its Before and After settings say.
EvalClamped(curve Curve, t float) floatReturns the value at t clamped to the first and last key.

23 constants and enum values are listed below.

Duration function

func Duration(curve Curve) float

Returns the time between the first and the last key, 1 for a preset.

Example

t := age / curve.Duration(fade)

Ease function

func Ease(easing aego/curve.Easing, t float) float

Returns a preset easing at t, clamped to 0..1.

Example

x := math.Lerp(a, b, curve.Ease(curve.OutCubic, k))

Easing enum

enum Easing

Easing names a preset curve from 0 to 1. None and Linear move at a constant speed.

Eval function

func Eval(curve Curve, t float) float

Returns the value of a curve at time t; outside its keys the curve repeats as its Before and After settings say.

Example

speed := Speed * curve.Eval(node.Get<Mover>().Accel, elapsed)

EvalClamped function

func EvalClamped(curve Curve, t float) float

Returns the value at t clamped to the first and last key.

Example

k := curve.EvalClamped(fade, age)

InBack const

const InBack enum:aego/curve.Easing

InBack pulls back past the start before it moves, like a wind-up.

InBounce const

const InBounce enum:aego/curve.Easing

InBounce bounces off the start with growing hops before it goes.

InCubic const

const InCubic enum:aego/curve.Easing

InCubic starts slowly and speeds up, more strongly than InQuad.

InElastic const

const InElastic enum:aego/curve.Easing

InElastic wobbles around the start with growing swings, then springs to the end.

InExpo const

const InExpo enum:aego/curve.Easing

InExpo barely moves at first, then covers nearly all the way at the end.

InOutBack const

const InOutBack enum:aego/curve.Easing

InOutBack pulls back past the start and goes past the end before it settles.

InOutBounce const

const InOutBounce enum:aego/curve.Easing

InOutBounce bounces off the start and bounces on the end.

InOutCubic const

const InOutCubic enum:aego/curve.Easing

InOutCubic is slow at both ends and fast in the middle, more strongly than InOutQuad.

InOutElastic const

const InOutElastic enum:aego/curve.Easing

InOutElastic wobbles around both the start and the end.

InOutExpo const

const InOutExpo enum:aego/curve.Easing

InOutExpo waits at the start, rushes through the middle and creeps to the end.

InOutQuad const

const InOutQuad enum:aego/curve.Easing

InOutQuad is slow at both ends and fastest in the middle, gently: for moves between two rest positions.

InOutSine const

const InOutSine enum:aego/curve.Easing

InOutSine is slow at both ends, the softest of the curves: for breathing, bobbing and fades.

InQuad const

const InQuad enum:aego/curve.Easing

InQuad starts slowly and speeds up, gently: for things that set off, such as a door starting to open.

InSine const

const InSine enum:aego/curve.Easing

InSine starts slowly and speeds up, the softest of the curves.

Linear const

const Linear enum:aego/curve.Easing

Linear moves at a constant speed from start to end.

OutBack const

const OutBack enum:aego/curve.Easing

OutBack goes past the end and settles back: for a pop or a bounce-in.

OutBounce const

const OutBounce enum:aego/curve.Easing

OutBounce reaches the end and bounces on it like a dropped ball.

OutCubic const

const OutCubic enum:aego/curve.Easing

OutCubic starts fast and slows down to the end, more strongly than OutQuad.

OutElastic const

const OutElastic enum:aego/curve.Easing

OutElastic springs past the end and wobbles around it as it settles, like a spring.

OutExpo const

const OutExpo enum:aego/curve.Easing

OutExpo covers nearly all the way at once, then creeps to the end: for snappy UI.

OutQuad const

const OutQuad enum:aego/curve.Easing

OutQuad starts fast and slows down gently to the end: the usual choice for UI that slides in.

OutSine const

const OutSine enum:aego/curve.Easing

OutSine starts fast and slows down to the end, the softest of the curves.