delay()

delay(expr, ms) gives you the value expr had ms milliseconds ago. Animate one thing, and everything that should follow it with a lag follows on its own.

Try it

Draw a tail of three bones. Animate only the first one, then give the others a formula on rotation:

// Tail2.rotation
delay(Tail1.rotation, 80)
// Tail3.rotation
delay(Tail2.rotation, 80)

Each bone repeats the swing of the one before it, 80 ms later. Hair behind a head, a scarf, a tentacle, a crowd doing a wave: one animated part, the rest delayed.

Signature

delay(expr, ms)
  • expr — any number a formula can read: a property (Head.y), arithmetic (Head.y + 20), another formula's result.
  • ms — how far back, in milliseconds. A number you type (120) can be up to 10 000. An expression (Slider.value * 10) is allowed too and is kept between 0 and 5 000. 0 or less returns expr as it is now.

Which clock it uses

delay counts animation time, not the clock on the wall.

  • Playing, exporting, recording: ms is play time. A take recorded in slow motion stretches the lag with it, so the playback looks the same as the take.
  • Editing, not playing: drag the source and the followers trail behind it live, then settle. Scrub the timeline and every delayed value shows what its source was ms earlier on the timeline.
  • Paused: behaves like editing.
  • Before frame 0: the first value is held, so a delay at the very start does not jump. After a loop or ping-pong, the delay carries the end of the previous cycle, so the loop has no seam.

In events and methods

delay also works in event and method code. There it can read only what a formula can read: node properties, time, mouse and the like, not the event's arguments or your local variables.

// Lamp: on click
Glow.opacity = delay(Lamp.opacity, 300)

Memory

Each delay call keeps one fixed buffer, sized once from the document's frame rate (60 fps when the rate is not fixed). Using delay everywhere is fine: nothing new is allocated while the animation runs.

Limits

  • Numbers only. If expr stops being a number, delay keeps returning the last number it had.
  • Not inside a function or an arrow, such as items.map(i => delay(i.x, 50)). The formula is rejected with a message.
  • Inside ?:, && and ||, a branch that is not taken does not record. When it is taken again, its history starts from where it stopped.
  • delay(delay(x, 50), 50) works and keeps two buffers. Up to 32 levels deep.
  • A bone posed by IK: in the editor, things delayed from it show no lag until you press Play. In play mode they lag as expected.

See also

Formo

The browser studio where drawings become animations, toys, and games. Your files, nothing to install.