# aego/curve

> Aego 0.12.5 · development; docs build `4a32b816933e02930662f6a443cb25abe6050d090c55e237cbff5c44ae9b25f8`. [Build manifest](/docs-build.json).

`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](/curves.md).

## Example

```aes run
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))
        }
    }
}
```

## Duration

```
func Duration(curve Curve) float
```

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

## Ease

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

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

## Easing

```
enum Easing
```

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

## Eval

```
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.

## EvalClamped

```
func EvalClamped(curve Curve, t float) float
```

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

## InBack

```
const InBack enum:aego/curve.Easing
```

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

## InBounce

```
const InBounce enum:aego/curve.Easing
```

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

## InCubic

```
const InCubic enum:aego/curve.Easing
```

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

## InElastic

```
const InElastic enum:aego/curve.Easing
```

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

## InExpo

```
const InExpo enum:aego/curve.Easing
```

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

## InOutBack

```
const InOutBack enum:aego/curve.Easing
```

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

## InOutBounce

```
const InOutBounce enum:aego/curve.Easing
```

InOutBounce bounces off the start and bounces on the end.

## InOutCubic

```
const InOutCubic enum:aego/curve.Easing
```

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

## InOutElastic

```
const InOutElastic enum:aego/curve.Easing
```

InOutElastic wobbles around both the start and the end.

## InOutExpo

```
const InOutExpo enum:aego/curve.Easing
```

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

## InOutQuad

```
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 InOutSine enum:aego/curve.Easing
```

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

## InQuad

```
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 InSine enum:aego/curve.Easing
```

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

## Linear

```
const Linear enum:aego/curve.Easing
```

Linear moves at a constant speed from start to end.

## OutBack

```
const OutBack enum:aego/curve.Easing
```

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

## OutBounce

```
const OutBounce enum:aego/curve.Easing
```

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

## OutCubic

```
const OutCubic enum:aego/curve.Easing
```

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

## OutElastic

```
const OutElastic enum:aego/curve.Easing
```

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

## OutExpo

```
const OutExpo enum:aego/curve.Easing
```

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

## OutQuad

```
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 OutSine enum:aego/curve.Easing
```

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