HSV to individual R, individual G, individual B Functions

Hi Kevin -

I don’t have my pixelblaze with me, so I’ve typed this up without any validation – there might be errors when you paste it into the editor. I looked at a few hsv-to-rgb functions in JS and tried to adapt them to pixelblaze-compatible form. I used globals for r, g, b to keep it concise. Paste this above render(index):

var r, g, b
function hsv2rgb(hh, ss, vv) {
    var h = hh % 1
    var s = clamp(ss, 0, 1) 
    var v = clamp(vv, 0, 1) 
    var i = floor(h * 6)
    var f = h * 6 - i
    var p = v * (1 - s)
    var q = v * (1 - (s * f))
    var t = v * (1 - (s * (1 - f)))

    if (i == 0) {
      r = v; g = t; b = p
    } else if (i == 1) {
      r = q; g = v; b = p
    } else if (i == 2) {
      r = p; g = v; b = t
    } else if (i == 3) {
      r = p; g = q; b = v
    } else if (i == 4) {
      r = t; g = p; b = v
    } else if (i == 5) {
      r = v; g = p; b = q
    }  
}

You’d use it in blinkfade by replacing:

hsv(hues[index],1,v)

with

hsv2rgb(hues[index], 1, v)
rgb(
  r * analogInputs[0], 
  g * analogInputs[1],
  b * analogInputs[2]
)
1 Like