Skip to content

Arguments & time

unreviewed draft

The kinds of values hydra functions accept — numbers, arrays, functions, textures — and how time, speed and bpm drive them.

Every numeric parameter accepts four kinds of value:

FormExampleEvaluated
numberosc(20)written into the shader as a constant (changing it recompiles)
arrayosc([10, 20, 40])every frame, stepping through the values (modifiers)
functionosc(() => 20 + mouse.x / 10)every frame
texture/chain.modulate(noise(3)), .blend(o1)per pixel (texture inputs)

Functions are called each frame as fn({ time, bpm, mouse, resolution }) and must return a number; otherwise hydra logs function does not return a number and uses the parameter’s default. You can also just read the globals time, mouse, width, height inside the function.

  • time is seconds since start, advanced each frame by dt⋅speeddt \cdot \text{speed}. Set the global speed = 0.5 to slow everything that depends on time — osc’s sync, rotate’s speed, arrays, and your own functions that read time.
  • bpm (default 30) only affects arrays: index =time⋅fast⋅bpm/60= \text{time}\cdot\text{fast}\cdot\text{bpm}/60, so at the default each array value lasts 2 s. bpm = 120 makes it 0.5 s.
  • update = (dt) => { … } runs once per frame before rendering, with dt in milliseconds. Use it to accumulate your own state (e.g. an angle that changes pace smoothly).
Function argument reading the clock
shape(4, () => 0.3 + 0.1 * Math.sin(time * 2)).out()
Open in hydra ↗
Mouse-driven frequency
osc(() => mouse.x / 20, 0.1, 1).out()
Open in hydra ↗
Smooth pace changes with update
var angle = 0
update = (dt) => { angle += dt * 0.001 * (1 + Math.sin(time)) }
shape(3).rotate(() => angle).out()
Open in hydra ↗
Arrays follow bpm
bpm = 120
shape([3, 4, 5, 6]).out()
Open in hydra ↗
  • Changing a rate like rotate(0, speed) live multiplies the whole elapsed time, so the result jumps; accumulate in update for smooth changes (third example).
  • Code runs through a global eval: top-level let/const are private to that one evaluation, while var (or a bare assignment) creates a real global that later evaluations can read. Don’t reuse hydra’s global names: a is the audio object, s0–s3/o0–o3 are sources/outputs, time/speed/bpm are the clock.
  • A function that returns a non-number (undefined, a string) silently falls back to the parameter’s default (a warning appears in the console). NaN is a number and is passed through. Array NaN/undefined values render as 0.

Documents hydra-synth 1.4.0 (AGPL-3.0; this site runs it unmodified). Annotations drafted by Claude (Anthropic) from the hydra-synth source and checked against rendered output — see about. Site code AGPL-3.0, prose CC BY 4.0,source.