Reference: easings and numbers
What a scene imports from framescript and calls, in the order the module exports it. Each entry has its signature, what it does, and the examples that use it; the types its signatures name are at the end.
Explained in Values, Easings and springs.
hold
function hold(at: number, length: number): Easing
Makes the time curve of a hold: the piece runs, stops for a share of its length, and runs on, faster by as much as the stop took.
at: Where the stop begins, from 0 to 1 of the warp's length.length: How much of the warp's length the stop takes.- Returns: The time curve, for
warp.
Examples: time/warp
ramp
function ramp(options?: RampOptions): Easing
Makes the time curve of a speed ramp: motion eases down to a slow moment and back up, and runs a little faster elsewhere so that the piece takes as long as it did.
options: Where the slow moment is, how slow, and how wide.- Returns: The time curve, for
warp.
Examples: time/warp
defineEasing
function defineEasing(
name: string,
params: ReadonlyArray<number>,
fn: (progress: number) => number
): Easing
Tags a function of progress with the name and parameters it is stored under.
name: The easing's name.params: The parameters that produced it.fn: The function of progress.- Returns: The easing.
Examples: values/easings-with-numbers
toEasing
function toEasing(fn: Easing | ((progress: number) => number)): Easing
Turns anything accepted as an easing into one: a tagged easing is returned as it is, and a plain function is stored under the name custom.
fn: An easing or a plain function of progress.- Returns: The easing.
Examples: values/easings-with-numbers
linear
const linear: Easing
Constant speed from start to end.
Examples: transitions/match-cut, footage/video-file, instances/field
easeIn
const easeIn: Easing
Starts slowly. The cubic curve; the default "ease in".
Examples: values/easings
easeOut
const easeOut: Easing
Ends slowly. The cubic curve; the default easing of every tween.
Examples: sound/dynamics/ducking, values/easings
easeInOut
const easeInOut: Easing
Starts and ends slowly. The cubic curve.
Examples: camera/sight, steps/custom-writes, sound/time/tape-delay
smooth
const smooth: Easing
The gentlest way from rest to rest: no speed and no acceleration at either end, and the lowest top speed that allows (minimum jerk). Moves eased with it can overlap or follow one another without a visible seam.
Examples: time/warp, values/easings
quadIn
const quadIn: Easing
Quadratic ease in.
Examples: values/easings
quadOut
const quadOut: Easing
Quadratic ease out.
Examples: values/easings
quadInOut
const quadInOut: Easing
Quadratic ease in and out.
Examples: values/easings
cubicIn
const cubicIn: Easing
Cubic ease in.
Examples: motion/more-easings, values/easings
cubicOut
const cubicOut: Easing
Cubic ease out.
Examples: values/easings
cubicInOut
const cubicInOut: Easing
Cubic ease in and out.
Examples: composing/play, values/easings
quartIn
const quartIn: Easing
Quartic ease in.
Examples: values/easings
quartOut
const quartOut: Easing
Quartic ease out.
Examples: values/easings
quartInOut
const quartInOut: Easing
Quartic ease in and out.
Examples: values/easings
quintIn
const quintIn: Easing
Quintic ease in.
Examples: values/easings
quintOut
const quintOut: Easing
Quintic ease out.
Examples: values/easings
quintInOut
const quintInOut: Easing
Quintic ease in and out.
Examples: values/easings
expoIn
const expoIn: Easing
Exponential ease in.
Examples: values/easings
expoOut
const expoOut: Easing
Exponential ease out.
Examples: presets/flip, text-reveals/count, values/easings
expoInOut
const expoInOut: Easing
Exponential ease in and out.
Examples: values/easings
circIn
const circIn: Easing
Circular ease in.
Examples: values/easings
circOut
const circOut: Easing
Circular ease out.
Examples: values/easings
circInOut
const circInOut: Easing
Circular ease in and out.
Examples: values/easings
sineIn
const sineIn: Easing
Sinusoidal ease in.
Examples: values/easings
sineOut
const sineOut: Easing
Sinusoidal ease out.
Examples: values/easings
sineInOut
const sineInOut: Easing
Sinusoidal ease in and out.
Examples: instances/trail, sound/time/chorus, sound/time/flanger
backIn
const backIn: Easing
Pulls back before moving.
Examples: values/easings-with-numbers
backOut
const backOut: Easing
Overshoots the end and settles back.
Examples: values/easings-with-numbers
backInOut
const backInOut: Easing
Pulls back, then overshoots.
Examples: values/easings-with-numbers
elasticIn
const elasticIn: Easing
Winds up like a spring before moving.
Examples: values/easings-with-numbers
elasticOut
const elasticOut: Easing
Overshoots and oscillates into place.
Examples: values/easings-with-numbers
elasticInOut
const elasticInOut: Easing
Winds up, then oscillates into place.
Examples: values/easings-with-numbers
bounceIn
const bounceIn: Easing
Bounces away from the start.
Examples: values/easings-with-numbers
bounceOut
const bounceOut: Easing
Bounces to rest at the end.
Examples: values/easings-with-numbers
bounceInOut
const bounceInOut: Easing
Bounces at both ends.
Examples: values/easings-with-numbers
cubicBezier
function cubicBezier(
x1: number,
y1: number,
x2: number,
y2: number
): Easing
A cubic Bézier easing with the same control points CSS uses.
x1: The first control point's x, from 0 to 1.y1: The first control point's y.x2: The second control point's x, from 0 to 1.y2: The second control point's y.- Returns: The easing.
Examples: values/easings-with-numbers
steps
function steps(count: number): Easing
An easing that jumps between evenly spaced values instead of moving smoothly.
count: How many jumps to make.- Returns: The easing.
Examples: values/easings-with-numbers
back
function back(overshoot: number): {
in: Easing
out: Easing
inOut: Easing
}
The back easings with a chosen amount of overshoot.
overshoot: How far past the end to go; 1.70158 is the default.- Returns: The in, out and in-out variants.
Examples: values/easings-with-numbers
elastic
function elastic(
amplitude: number,
period: number
): {
in: Easing
out: Easing
inOut: Easing
}
The elastic easings with a chosen amplitude and period.
amplitude: The size of the oscillation; at least 1. The larger it is, the further the value swings past the end it comes to rest at.period: The length of one oscillation, as a share of the duration.- Returns: The in, out and in-out variants.
Examples: values/easings-with-numbers
anticipate
const anticipate: Easing
Pulls back a little before it goes, then arrives quickly and settles: the wind-up before a throw.
Examples: motion/more-easings
bouncy
function bouncy(bounces?: number, strength?: number): Easing
An easing that falls to where it is going and bounces there a set number of times, each bounce lower than the one before.
bounces: How many times it bounces after the first landing. Defaults to 3.strength: How high each bounce is against the one before, from 0 to 1. Defaults to 0.5.- Returns: The easing.
Examples: motion/more-easings
carried
function carried(speed: number): Easing
An easing that starts at a given speed and comes to rest at the end: what a tween with carry uses, so that it takes a moving property over without a kink.
speed: The speed at the start, in whole moves per duration; 1 is the speed of a linear move.- Returns: The easing.
Examples: values/easings-with-numbers
decay
function decay(rate?: number): Easing
The easing of something that coasts to rest: fast at first, losing its speed evenly. It is what inertia moves with.
rate: How many times over the speed falls to about a third of itself along the way. Defaults to 6.2, after which nothing is left to see.- Returns: The easing.
Examples: values/easings-with-numbers
expoScale
function expoScale(from: number, to: number): Easing
The easing for a scale or a zoom that should look even: a zoom from 1 to 8 at constant speed seems to slow down, because each doubling takes longer than the last. With this easing every doubling takes the same time.
from: The scale the move starts at.to: The scale it ends at.- Returns: The easing;
linearwhen the two are the same.
Examples: motion/more-easings
mirrored
function mirrored(ease: Easing | ((progress: number) => number)): Easing
An easing followed by its own mirror image: the first half of the move goes as the easing says, the second half the same way backwards. An ease in becomes an ease in and out.
ease: Any easing.- Returns: The mirrored easing.
Examples: motion/more-easings
pathEasing
function pathEasing(data: string | ReadonlyArray<number>): Easing
An easing drawn as an SVG path: progress runs along x, the value along y. The path is taken from its first point to its last, whatever size it was drawn at and whether y points up or down, so a curve copied out of a drawing program works as it is. Each x may be passed only once.
data: The path, as thedof an SVG path, or the numbers a schedule stored for one.- Returns: The easing.
Examples: motion/more-easings
reversed
function reversed(ease: Easing | ((progress: number) => number)): Easing
An easing run backwards: what was slow at the start is slow at the end. An ease in becomes an ease out.
ease: Any easing.- Returns: The reversed easing.
Examples: motion/more-easings
rough
function rough(options?: RoughOptions): Easing
A rough easing: the even line from 0 to 1 with random steps to either side, for a flicker or a shaky hand. It is random but always the same for the same seed.
options:{ strength, points, seed, taper }.- Returns: The easing.
Examples: motion/more-easings
through
function through(...points: ReadonlyArray<EasingPoint>): Easing
An easing that passes through given points on its way from 0 to 1. Each point says how far through the move it is and what the value is there; between them the curve is smooth and does not swing wider than the points themselves.
points: The points, each as[progress, value], in any order.- Returns: The easing.
Examples: motion/more-easings
wiggly
function wiggly(wiggles?: number, amount?: number): Easing
An easing that goes evenly from 0 to 1 while swinging to either side of the even line, a set number of times, the swings dying down towards the end.
wiggles: How many times it swings. Defaults to 4.amount: How far it swings at first, as a share of the whole move. Defaults to 0.2.- Returns: The easing.
Examples: motion/more-easings
spring
function spring(options?: SpringFeel | SpringPhysics): SpringEasing
A spring easing, asked for in one of two ways. By feel, { bounce }, it is shaped to arrive within the duration the tween is given. By physics, { stiffness, damping, mass }, it takes as long as the spring takes to settle, and the tween is written without a duration. Either may start with a speed, which a tween works out from what the property is doing.
options: The spring's feel or its physics.- Returns: The spring easing.
Examples: motion/keeps-its-speed
clamp
function clamp(value: number, min: number, max: number): number
Keeps a number inside a range.
value: The number.min: The lowest value allowed.max: The highest value allowed.- Returns: The number, or the nearer bound.
Examples: values/utilities
distance
function distance(from: PointLike, to: PointLike): number
The straight distance between two points.
from: One point, as[x, y],[x, y, z]or an object's position.to: The other.- Returns: How far apart they are.
Examples: values/utilities
lerp
function lerp(from: number, to: number, amount: number): number
Linear interpolation between two numbers.
from: The value at 0.to: The value at 1.amount: How far along, usually from 0 to 1.- Returns: The interpolated number.
Examples: values/numbers
mapRange
function mapRange(
value: number,
inMin: number,
inMax: number,
outMin: number,
outMax: number
): number
Maps a number from one range onto another.
value: The number in the input range.inMin: The start of the input range.inMax: The end of the input range.outMin: The start of the output range.outMax: The end of the output range.- Returns: The matching number in the output range.
Examples: values/numbers
mix
function mix<T extends Mixable>(from: T, to: T, amount: number): T
function mix(
from: ReadonlyArray<number>,
to: ReadonlyArray<number>,
amount: number
): Array<number>
Blends two values of the same shape: two numbers, two colours written as text, two lists (vectors, colours as components, lists of points) or two objects with the same keys, to any depth. What is not a number or a colour, or has no partner, is taken from the first.
from: The value at 0.to: The value at 1.amount: How far along, usually from 0 to 1.- Returns: The blended value, in the shape of the first.
Examples: values/utilities
mixColor
function mixColor(
from: ColorInput,
to: ColorInput,
amount: number
): string
Blends two colours.
from: The colour at 0.to: The colour at 1.amount: How far along, usually from 0 to 1.- Returns: The colour between, as
#rrggbb.
Examples: values/utilities
noise
function noise(seed?: number): Noise
Creates seeded noise in one, two or three dimensions, for motion that is random but smooth and the same on every run: a drift, a flicker, a hand that is not quite steady. Read it along one direction for a wandering number, and along a second or third to give each of many things a wander of its own.
seed: Any integer. Defaults to 1.- Returns: The noise: a function of x, of x and y, or of x, y and z.
Examples: values/utilities
normalize
function normalize(value: number, min: number, max: number): number
Says how far a number is through a range: the opposite of lerp.
value: The number.min: The start of the range, which gives 0.max: The end of the range, which gives 1.- Returns: The share; below 0 or above 1 for a number outside the range.
Examples: values/utilities
pipe
function pipe<T>(
...steps: ReadonlyArray<(value: T) => T>
): (value: T) => T
Joins functions into one that hands its value through each in turn.
steps: The functions, the first to be applied first.- Returns: A function that applies them all.
Examples: values/utilities
random
function random(seed: number): Random
Creates a seeded source of random numbers. Timeline code uses this instead of Math.random(), so every run of a scene is identical.
seed: Any integer.- Returns: The source.
Examples: values/numbers
shuffle
function shuffle<T>(items: ReadonlyArray<T>, seed?: number): Array<T>
A copy of a list in a random order that is the same for the same seed.
items: The list.seed: Any integer. Defaults to 1.- Returns: The shuffled copy.
Examples: values/utilities
snap
function snap(value: number, step: number): number
Rounds a number to the nearest multiple of a step.
value: The number.step: The size of one step.- Returns: The nearest multiple.
Examples: values/numbers
splitColor
function splitColor(color: ColorInput): [number, number, number]
Takes a colour apart into red, green and blue.
color: The colour, as#rgb,#rrggbb,rgb(r, g, b)or the number0xrrggbb.- Returns: The three parts, each from 0 to 255.
Examples: values/utilities
wrap
function wrap(value: number, min: number, max: number): number
Wraps a number into a range, so one past the end is the start again.
value: The number.min: The start of the range, included.max: The end of the range, excluded.- Returns: The wrapped number.
Examples: values/numbers
wrapYoyo
function wrapYoyo(value: number, min: number, max: number): number
Wraps a number into a range by turning round at each end, so that it runs to and fro: one past the end is one before it.
value: The number.min: One end of the range.max: The other end.- Returns: The number inside the range.
Examples: values/utilities
Types
ColorInput
type ColorInput = string | number
Easing
interface Easing {
(progress: number): number
readonly easing: EasingData
}
EasingData
interface EasingData {
readonly name: string
readonly params: ReadonlyArray<number>
/**
* For an easing on remapped time (`warp`): the easing it had before, and
* the time curve it was remapped by. `params` then holds the part of the
* time curve the easing covers, as two numbers from 0 to 1.
*/
readonly inner?: EasingData
readonly curve?: EasingData
}
EasingPoint
type EasingPoint = readonly [progress: number, value: number]
Mixable
type Mixable =
| number
| string
| ReadonlyArray<Mixable>
| {
readonly [key: string]: Mixable
}
Noise
type Noise = (x: number, y?: number, z?: number) => number
PointLike
type PointLike =
| ReadonlyArray<number>
| {
readonly x: number
readonly y: number
readonly z?: number
}
RampOptions
interface RampOptions {
/** Where the slowest moment is, from 0 to 1 of the warp's length. */
readonly at?: number
/** The speed at that moment, as a share of normal speed; 0.1 is a tenth. */
readonly speed?: number
/** How much of the warp's length the slowing and recovering takes. */
readonly width?: number
}
Random
interface Random {
/** The next number, from 0 up to but not including 1. */
(): number
/** A number between two bounds. */
range(min: number, max: number): number
/** One item of a list. */
pick<T>(items: ReadonlyArray<T>): T
/** A shuffled copy of a list. */
shuffle<T>(items: ReadonlyArray<T>): Array<T>
}
RoughOptions
interface RoughOptions {
/** How far it strays from the even line, from 0 to 1. Defaults to 0.3. */
readonly strength?: number
/** How many times it changes direction. Defaults to 20. */
readonly points?: number
/** The seed: the same seed gives the same curve. Defaults to 1. */
readonly seed?: number
/**
* Where it is calm: `"in"` at the start, `"out"` at the end, `"both"` at
* both ends. Defaults to `"none"`, rough throughout.
*/
readonly taper?: "none" | "in" | "out" | "both"
}
SpringEasing
interface SpringEasing extends Easing {
/** The settle time in seconds; only set for a spring given by its physics. */
readonly settle?: number
}