Arguments & time
unreviewed draftThe kinds of values hydra functions accept — numbers, arrays, functions, textures — and how time, speed and bpm drive them.
What it does
Section titled “What it does”Every numeric parameter accepts four kinds of value:
| Form | Example | Evaluated |
|---|---|---|
| number | osc(20) | written into the shader as a constant (changing it recompiles) |
| array | osc([10, 20, 40]) | every frame, stepping through the values (modifiers) |
| function | osc(() => 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.
timeis seconds since start, advanced each frame by . Set the globalspeed = 0.5to slow everything that depends on time —osc’ssync,rotate’sspeed, arrays, and your own functions that readtime.bpm(default30) only affects arrays: index , so at the default each array value lasts 2 s.bpm = 120makes it 0.5 s.update = (dt) => { … }runs once per frame before rendering, withdtin milliseconds. Use it to accumulate your own state (e.g. an angle that changes pace smoothly).
Examples
Section titled “Examples”shape(4, () => 0.3 + 0.1 * Math.sin(time * 2)).out()osc(() => mouse.x / 20, 0.1, 1).out()var angle = 0update = (dt) => { angle += dt * 0.001 * (1 + Math.sin(time)) }shape(3).rotate(() => angle).out()bpm = 120shape([3, 4, 5, 6]).out()Gotchas
Section titled “Gotchas”- Changing a rate like
rotate(0, speed)live multiplies the whole elapsedtime, so the result jumps; accumulate inupdatefor smooth changes (third example). - Code runs through a global
eval: top-levellet/constare private to that one evaluation, whilevar(or a bare assignment) creates a real global that later evaluations can read. Don’t reuse hydra’s global names:ais the audio object,s0–s3/o0–o3are sources/outputs,time/speed/bpmare 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).NaNis a number and is passed through. ArrayNaN/undefinedvalues render as 0.
Related
Section titled “Related”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.