# HSV to individual R, individual G, individual B Functions

**URL:** <https://forum.electromage.com/t/hsv-to-individual-r-individual-g-individual-b-functions/193>\
**Category:** Patterns and Code\
**Created:** [January 18, 2020, 8:19am UTC](https://forum.electromage.com/t/hsv-to-individual-r-individual-g-individual-b-functions/193 "2020-01-18T08:19:35Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![jeff](https://forum.electromage.com/user_avatar/forum.electromage.com/jeff/32/3473_2.png) [@jeff](https://forum.electromage.com/u/jeff)\
**Post date:** [January 18, 2020, 4:44pm UTC](https://forum.electromage.com/t/hsv-to-individual-r-individual-g-individual-b-functions/193/2 "2020-01-18T16:44:55Z")

</div>

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]
)
```

---

_[View the full topic](https://forum.electromage.com/t/hsv-to-individual-r-individual-g-individual-b-functions/193)._
