General coding concept, layered effects

I have a vague idea for a pattern I’d like to attempt, using bits and pieces cobbled together from existing examples… However as a a general concept, how does one approach having effects /patterns shown “on top” of each other…

For example if I take the code for the “kitt” red sweep, and wish to add some white, random sparkles on top, is it simply the case of the order in which they are coded?

I appreciate its entirely possible I won’t understand the answer to this question, given my total lack of skills, but thought I’d ask in any case…

My overall idea, given I have a sensor board arriving, is to utilise the great looking music sequencer pattern, and use the variables it outputs to control, for example, a kitt style sweep to move on the beat, then some flashes, sparkles etc triggered by the hihat/clap variables. Could look cool. It seems that with a bit of learning this may be within the realms of possibility.

Right now there isn’t a blending/layering API, but I do hope to add one. In the meantime, this means you have to combine the inputs to a single rgb() or hsv() call.

Something like adding white could be done by reducing the saturation passed to hsv(), or adding some values to each element for rgb().

In some cases, you can optionally overwrite a color, e.g. for sparkles this works very well. I do something like that in a few patterns, and it looks like this as seen in “firework nova”:

  spark = triangle(r - t1 + .2) - .75 > random(2) // randomly true with a probability
  if (spark) {
    rgb(1,1,1) //sparks are white
  } else {
    v = v*4 //bring the triangle's peak back to 0-1 range
    v = v*v*v //gives more definition to the wave, preserve negatives

1 Like