Skip to content

Instantly share code, notes, and snippets.

@2bbb
Last active August 29, 2015 14:00
Show Gist options
  • Save 2bbb/11080282 to your computer and use it in GitHub Desktop.
Save 2bbb/11080282 to your computer and use it in GitHub Desktop.
hsv2rgb.js
inlets = 1;
outlets = 3;
function hsb(h, s, v) {
s = (s == undefined) ? 255.0 : s;
v = (v == undefined) ? 255.0 : v;
if(s == 0) {
outlet(0, v);
outlet(1, v);
outlet(2, v);
} else {
s /= 255.0;
var i = ((h / 60) ^ 0) % 6,
f = h / 60 - i;
var p = v * (1.0 - s),
q = v * (1.0 - s * f),
t = v * (1.0 - s * (1 - f));
var r, g, b;
switch(i) {
case 0: r = v, g = t, b = p; break;
case 1: r = q, g = v, b = p; break;
case 2: r = p, g = v, b = t; break;
case 3: r = p, g = q, b = v; break;
case 4: r = t, g = p, b = v; break;
case 5: r = v, g = p, b = q; break;
}
outlet(0, r);
outlet(1, g);
outlet(2, b);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment