# Single Color Snake Pattern?

**URL:** <https://forum.electromage.com/t/single-color-snake-pattern/3157>\
**Category:** Patterns and Code\
**Created:** [September 8, 2023, 5:54pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157 "2023-09-08T17:54:49Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![arewhatyouit](https://forum.electromage.com/letter_avatar_proxy/v4/letter/a/439d5e/32.png) [@arewhatyouit](https://forum.electromage.com/u/arewhatyouit)\
**Post date:** [September 8, 2023, 5:54pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/1 "2023-09-08T17:54:49Z")

</div>

Hello! I’m trying to create a single color snake pattern and I’m having some issues. I’m very new with all of this so I would appreciate any help or pointers.

I started with this rainbow snake pattern that works perfectly:

```auto
distance = 50

export function beforeRender(delta) {
  t1 = time(.17)
}

export function render(index) {
  h = index/pixelCount
  s = 1
  v = 1
  
  head = t1 * 112
  offset = (head - index + 112) % 112
  
  hsv(h, s, clamp(1 - offset / distance, 0, 1))
}

```

Then I modified it to run a white snake pattern:

```auto
distance = 50

export function beforeRender(delta) {
  t1 = time(.17)
}

export function render(index) {
  h = 0
  s = 0
  v = 1
  
  head = t1 * 112
  offset = (head - index + 112) % 112
  
  hsv(h, s, clamp(1 - offset / distance, 0, 1))
}

```

I would now like to run the exact same pattern as the white snake, but with solid colors. However I can’t seem to get it to work. If I change the “s” value to anything other than 0 the color turns to green and I can’t get it to produce any other colors. Is there a straight forward way of doing this which would allow me to choose a few different solid colors to run with this pattern?

---

<div class="post-metadata">

**Author:** ![ZacharyRD](https://forum.electromage.com/user_avatar/forum.electromage.com/zacharyrd/32/124_2.png) [@ZacharyRD](https://forum.electromage.com/u/ZacharyRD)\
**Post date:** [September 8, 2023, 6:12pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/2 "2023-09-08T18:12:37Z")

</div>

H S V stands for Hue (color, basically), Saturation (how gray / desaturated the color is) and Value (basically brightness).

You want to control the COLOR with H, not S.

If you scroll down on [Getting Started with PixelBlaze — Ben Hencke](https://www.bhencke.com/pixelblazegettingstarted) to “Writing Your First Pattern” it’s decently well explained.

---

<div class="post-metadata">

**Author:** ![arewhatyouit](https://forum.electromage.com/letter_avatar_proxy/v4/letter/a/439d5e/32.png) [@arewhatyouit](https://forum.electromage.com/u/arewhatyouit)\
**Post date:** [September 8, 2023, 6:19pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/3 "2023-09-08T18:19:37Z")

</div>

Thanks for the reply! I’ve tried that as well, but no mater what value I give it it remains white.

---

<div class="post-metadata">

**Author:** ![sorceror](https://forum.electromage.com/user_avatar/forum.electromage.com/sorceror/32/735_2.png) [@sorceror](https://forum.electromage.com/u/sorceror)\
**Post date:** [September 9, 2023, 7:44am UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/4 "2023-09-09T07:44:27Z")

</div>

> [@arewhatyouit](#):
>
> but no mater what value I give it it remains white.

That’s because you have `s = 0` which means 0 saturation. ☺

---

<div class="post-metadata">

**Author:** ![arewhatyouit](https://forum.electromage.com/letter_avatar_proxy/v4/letter/a/439d5e/32.png) [@arewhatyouit](https://forum.electromage.com/u/arewhatyouit)\
**Post date:** [September 11, 2023, 4:23pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/5 "2023-09-11T16:23:27Z")

</div>

That makes sense, however I’m still confused why if I make S anything above 0 why it will only run a single green color. The strip I’m using is these 12v RGBW pixels: [https://www.enttec.com/product/led-pixel-strip/black-led-pixel-strip/](https://www.enttec.com/product/led-pixel-strip/black-led-pixel-strip/). Does it have something to do with it being RGBW instead of RGB? The rest of the effect works exactly how I want, but I just need to be able to choose the color and as of right now it will only do all white or one specific shade of green.

---

<div class="post-metadata">

**Author:** ![ZacharyRD](https://forum.electromage.com/user_avatar/forum.electromage.com/zacharyrd/32/124_2.png) [@ZacharyRD](https://forum.electromage.com/u/ZacharyRD)\
**Post date:** [September 11, 2023, 9:45pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/6 "2023-09-11T21:45:23Z")

</div>

You first need to make sure that you’ve selected the right type of LED strip and color order in settings. (If you’re not sure, play around with different options while running a simple test pattern). RGBW strips work fine, but the color order may or may not be that order on your actual strips.

Then, control the color (hue) with H, and just set the saturation to 1.

---

<div class="post-metadata">

**Author:** ![arewhatyouit](https://forum.electromage.com/letter_avatar_proxy/v4/letter/a/439d5e/32.png) [@arewhatyouit](https://forum.electromage.com/u/arewhatyouit)\
**Post date:** [September 11, 2023, 10:13pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/7 "2023-09-11T22:13:37Z")

</div>

I set the color order according to the LEDs spec sheet and all the test patterns are running correctly. Still though, whenever I set the saturation to anything above 0 with any hue setting it will only show green.

---

<div class="post-metadata">

**Author:** ![ZacharyRD](https://forum.electromage.com/user_avatar/forum.electromage.com/zacharyrd/32/124_2.png) [@ZacharyRD](https://forum.electromage.com/u/ZacharyRD)\
**Post date:** [September 11, 2023, 11:03pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/8 "2023-09-11T23:03:29Z")

</div>

Can you share the code snippet you’re working on now that you have implemented the notes above from me and @sorceror , as well as a screenshot of your settings screen where you picked the LED type? (I also might be missing something obvious; also don’t assume the LED spec sheets are correct necessarily).

Hue = 0 Saturation = 1 Value = 1 should be red, not green… I had this bookmarked from walking though a similar problem in the past. [Working with Hues in Pixelblaze - color ranges, blending](https://forum.electromage.com/t/working-with-hues-in-pixelblaze-color-ranges-blending/687)

---

<div class="post-metadata">

**Author:** ![arewhatyouit](https://forum.electromage.com/letter_avatar_proxy/v4/letter/a/439d5e/32.png) [@arewhatyouit](https://forum.electromage.com/u/arewhatyouit)\
**Post date:** [September 11, 2023, 11:59pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/9 "2023-09-11T23:59:23Z")

</div>

Of course, thank you so much for the help! Here is the code I’m using… I just updated it to Hue = 0 Saturation = 1 Value = 1 and its still running all the lights as green. I thought they might be broken, but that doesn’t seem to be the case since they have zero problem running the rainbow pattern which shows all the colors.

Here is my code:

```auto
distance = 50

export function beforeRender(delta) {
  t1 = time(.17)
}

export function render(index) {
  h = 0
  s = 1
  v = 1
  
  head = t1 * 112
  offset = (head - index + 112) % 112
  
  hsv(h, s, clamp(1 - offset / distance, 0, 1))
}

```

Here is a screenshot of my settings:

 ![Screenshot 2023-09-11 at 4.56.48 PM](https://forum.electromage.com/uploads/default/original/2X/7/7488acc219659837b70d3be808a5adf8d12498f9.png)

---

<div class="post-metadata">

**Author:** ![ZacharyRD](https://forum.electromage.com/user_avatar/forum.electromage.com/zacharyrd/32/124_2.png) [@ZacharyRD](https://forum.electromage.com/u/ZacharyRD)\
**Post date:** [September 12, 2023, 12:17am UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/10 "2023-09-12T00:17:57Z")

</div>

If you run the pre-loaded pattern called KITT, does the pattern show as green or red? If green, then the problem is the Color Order in Settings is wrong. If Red, I’m really confused. Alternatively, if you set H to 0.5 or 0.25, what color do you get? Still green or a different color?

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [September 12, 2023, 12:35am UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/11 "2023-09-12T00:35:27Z")

</div>

For quick reference when testing, if the color order is correct and everything else is working properly then:

- hsv(0,1,1) is red
- hsv(0.33333,1,1) is green
- hsv(0.6666,1,1) is blue

Another thing you might want to do is set the brightness limit for your LEDs to 50% or less until you’ve got it working correctly, to be sure that the power supply can keep up as you test.

---

<div class="post-metadata">

**Author:** ![sorceror](https://forum.electromage.com/user_avatar/forum.electromage.com/sorceror/32/735_2.png) [@sorceror](https://forum.electromage.com/u/sorceror)\
**Post date:** [September 12, 2023, 8:44am UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/12 "2023-09-12T08:44:18Z")

</div>

You said they are RGBW strips but your screenshot shows Color Order GRBW which would explain why Hue 0 gives you Green. As @ZacharyRD says … the KITT pattern should be red. Is it?

---

<div class="post-metadata">

**Author:** ![arewhatyouit](https://forum.electromage.com/letter_avatar_proxy/v4/letter/a/439d5e/32.png) [@arewhatyouit](https://forum.electromage.com/u/arewhatyouit)\
**Post date:** [September 12, 2023, 5:18pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/13 "2023-09-12T17:18:15Z")

</div>

Ah! Ok Now I’m getting somewhere! I set it to RGBW and now its operating as you just described @zranger1 and @sorceror. I’m able to get red, green and blue independently by using:

- hsv(0,1,1) is red
- hsv(0.33333,1,1) is green
- hsv(0.6666,1,1) is blue

So then my next question is if there is a way to use the outputs from a HEX/RGB to HSV calculator to figure out my HSV values. I used a calculator to try to get the correct color but the Hue output is way outside of the range that works with the pixel blaze. Here is a screenshot to show what I mean:

 ![Screenshot 2023-09-12 at 10.12.45 AM](https://forum.electromage.com/uploads/default/original/2X/a/a99d4e1d7e264d757c296fe926ff0cc6b766eebe.png)

If I set the Hue to 171 it outputs as red, which makes sense since it is \>1. Is there a way to get a corresponding hue value that works with the Pixelblaze?

---

<div class="post-metadata">

**Author:** ![zranger1](https://forum.electromage.com/user_avatar/forum.electromage.com/zranger1/32/301_2.png) [@zranger1](https://forum.electromage.com/u/zranger1)\
**Post date:** [September 12, 2023, 6:00pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/14 "2023-09-12T18:00:34Z")

</div>

Quick answer: The Pixelblaze uses normalized values in the range [0.0,1.0] for just about everything. It makes a whole lot of math a whole lot easier in the long run. Plus it lets Pixelblaze patterns run on LEDs with \>8-bit color depth without changing any code.

To convert from a 360 degrees/100%/100% based HSV color, just divide hue by 360,and saturation and value by 100.

For the color above, that’ll give you (0.475, 0.9, 0.196)

(This applies to RGB colors as well – red is rgb(1,0,0), green rgb(0,1,0), and so forth. To convert from [0,255]-based colors, divide by 255.)

---

<div class="post-metadata">

**Author:** ![arewhatyouit](https://forum.electromage.com/letter_avatar_proxy/v4/letter/a/439d5e/32.png) [@arewhatyouit](https://forum.electromage.com/u/arewhatyouit)\
**Post date:** [September 12, 2023, 6:21pm UTC](https://forum.electromage.com/t/single-color-snake-pattern/3157/15 "2023-09-12T18:21:03Z")

</div>

Ok Great! Thanks so much this is perfect. I really appreciate all of your help. Everything’s now working as intended!
