HSV to individual R, individual G, individual B Functions

In a bind for tomorrow and need a good way to break HSV into its individual RGB component values. So that I can multiply it by the analog inputs from the sensor board to control the amount of r,g & b

All the sound programs use HSV to set the pixel.
I need to set them with something like this if anyone has an good idea on how to do it.
I’ll gladly PayPal a thank you if I can get this work tomorrow during the day.
Need to convert blink fade to account for the amount of analog 0,1 & 2 values read

rgb(
hsv(hues[index],1,v).getR()*analogInputs[0],
hsv(hues[index],1,v).getB()*analogInputs[1],
hsv(hues[index],1,v).getG()*analogInputs[2]
)

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

Thank you sooooo much. Please pm me your paypal/venmo/cash app

2 Likes

Nice! So glad you got it working. No need for payment – just gift someone else a Pixelblaze to pay it forward, or help someone else on the forums sometime.

2 Likes

Will do and will keep doing.
I’ve been handing them out all over the place
My favorite controller

Got another 3 I can reclaim from the clouds that were used and give away

1 Like

They made a lot of people happy :slight_smile:

2 Likes