Hydra functions and values

Hi all, I’ve just started playing with Hydra.

The first thing I saw was naoto’s p5 demo, where a draw function was used to draw to a canvas object, instead of the whole screen.

Am wondering if similar is possible about different ways to do similar using Hydra & it’s functions, by chaining, maybe with buffers… am guessing the modulateFunctions will be required to achieve.

Also trying to understand alternate approaches, eg .color(1,0,0) using r() , if they can be equivalent, as well as what r() does exactly…

osc(60, 0.1, 1.5)
// 		.r(1)  // toggle commenting to "a|b test"

shape().mult(solid(1,0,0)).out() appears equivalent to shape().color(1,0,0).out()
but there may differences, depending on the what the transform is acting on.

I started with the solid() method, looking for valid values for alpha, to understand how that affects the output, but am still looking for more info on valid values.

solid( r, g, b, a = 1 )

alpha function not documented

Also I tried playing with bpm , to see if it’s equivalent to speed, and whether fast() factored in both speed and performance… eg if bpm default is 60 and speed 1, then bpm 30 and speed 0.5 == 25% playback… seems bpm doesn’t affect osc() speed, so still looking for how bpm works.

bpm example isn’t clear how bpm is being used, appears examples just illustrate different osc-speeds from the osc sync value

// change array speed
bpm = 60  //changing this appears to do nothing!?!

:brain:dump :end:

Conditional logic

My first attempt at conditional logic, with GPT. I noticed if then example in the extensions collection, but first tried the response from prompt.

Whilst the code seems to work briefly, the browser crunches to a halt then needs to be closed and reopened. I wonder if this is avoidable, and any tips on managing resources or debugging…

:warning: This may crash your browser.

I’d like to try a simple sketch, where conditionally different methods are executed
so we can start with a source
then conditionally modulate by voronoi or noise,
eg depending on whether mod time is even

// Define the base oscillator
let base = osc(4, 0.2);

// Define a function to conditionally apply modulation
function applyConditionalModulation() {
  let currentTime = new Date();
  let seconds = currentTime.getSeconds();

  // Check if seconds are even or odd
  if (seconds % 2 === 0) {
    // Apply voronoi modulation if even
    return base.modulate(voronoi(5), 0.1);
  } else {
    // Apply noise modulation if odd
    return base.modulate(noise(3), 0.1);

// Function to repeatedly update the output
function updateOutput() {

// Start the update loop

Even when running in another browser instance and killing the sketch, other tabs remain unresponsive, even edge taskmgr* remains empty! (shift+esc)

Is this breaking code normal and expected? Anyone tried any conditional logic like this?

I’m thinking of conditional “chains” eg src.mod1.mod2 or src.mod2.mod1


Hi Jonny, sorry for the late reply. There’s a guide I’ve written about this particular topic, it starts with iteration and gets into conditionals later on:

1 Like