home/ atoms/ hydra-time-function-parameters

Any Hydra parameter can be a function of time, enabling continuous animation without retyping code

Instead of a static number, any Hydra parameter accepts a JavaScript function — typically an arrow function — that returns a value at each frame. The global variable time holds milliseconds elapsed since page load, enabling sine waves, ramps, or any time-varying expression. osc(() => 100 * Math.sin(time * 0.1)) makes the oscillator frequency oscillate smoothly. This pattern replaces animation loops with declarative live-coding: a single re-evaluated expression stays alive until overwritten. The function is called every render frame, so it reacts in real time.

Examples

osc(() => (100 * Math.sin(time * 0.1))).out()

Assessment

Write a Hydra line where both frequency and rotation angle vary as different functions of time. Explain why using a function is preferable to periodically re-running a static snippet.

“Each parameter can be defined as a function rather than a static variable. For example, ```javascript osc(function(){return 100 * Math.sin(time * 0.1)}).out() ``` modifies the oscillator frequency as a function of time.”
corpus · hydra-livecoding-networked-visuals-source-repo · chunk 3