Browse Source

Add SC rainbow example

tags/v1.3.0
Brian Heim 5 years ago
parent
commit
a911e82a7f
1 changed files with 42 additions and 0 deletions
  1. +42
    -0
      examples/rainbow.scd

+ 42
- 0
examples/rainbow.scd View File

@@ -0,0 +1,42 @@
// Rainbow RGB LED example
// by Brian Heim
// adapted from example by Andrew Belt

// Call process() every 256 audio samples
~vcv_frameDivider = 256;
~vcv_bufferSize = 1;

// From https://en.wikipedia.org/wiki/HSL_and_HSV#HSV_to_RGB
~hsvToRgb = { |h, s, v|
var c, x, rgb, m;
h = h * 6;
c = v * s;
x = c * (1 - abs(h % 2 - 1));
rgb = case
{ h < 1 } { [c, x, 0] }
{ h < 2 } { [x, c, 0] }
{ h < 3 } { [0, c, x] }
{ h < 4 } { [0, x, c] }
{ h < 5 } { [x, 0, c] }
{ [c, 0, x] };

rgb + (v - c);
};

~phase = 0;
~vcv_process = { |block|
~phase = ~phase + block.sampleTime * ~vcv_frameDivider * 0.5;
~phase = ~phase % 1.0;

VcvPrototypeProcessBlock.numRows.do { |i|
var h = (1 - i / 6 + ~phase) % 1;
var rgb = ~hsvToRgb.value(h, 1, 1);
3.do { |c|
block.lights[i][c] = rgb[c];
block.switchLights[i][c] = rgb[c];
};
block.outputs[i][0] = sin(2pi * h) * 5 + 5;
};

block
}

Loading…
Cancel
Save