Starting to write my own libraries built upon FastLED...

gplus
(Myche Tician) #1

Starting to write my own libraries built upon FastLED… have a few questions…

I like the HSV 1-byte color model and I’ve been wanting to write routines with different patterrns where I can specify colors (I assume a global saturation and level number)… making the color a 0-255 int makes a lot of sense, but it appears that this doe not cover all the colors… i.e. in order to do black, you have to modify the brightness value… is there any color model that supports a simple single number value that also includes black, white and shades of gray?

(Daniel Garcia) #2

No, the closest you could get would be to define a palette.

(Myche Tician) #3

I guess the model could be augmented with some values outside the 0-255 range to represent other colors and expand it to a slightly larger int?

(Myche Tician) #4

I haven’t gotten into how to define and use palettes yet… are they like arrays of color values that can be referenced by index? Is there a limit to how many min/max colors can be in a palette? Is there a palette that is already defined that does something like this? Are there other people who might be brewing their own routines that use a palette index as a parameter to specify colors?

(Daniel Garcia) #5

“slightly larger int” would be two bytes - in which case, you could just pick a constant saturation value and use a 1 byte hue and a 1 byte value/brightness.

(Jason Coon) #6

For full saturation and brightness colors, I often just use a uint8_t for hue. For all other cases, I just use CRGB and CHSV. Three bytes to represent any 24-bit color seems efficient enough for my uses. :slight_smile: Depending on your platform, an int is going to be two or four bytes, so I’m not sure what the point of using an int would be, but I’m probably missing something.

You can use hex codes to represent colors in a compact manner, if that’s what you’re looking for (blue = 0x0000FF, red = 0xFF0000, etc): https://github.com/FastLED/FastLED/blob/8ee392ace11da654a99d980abb94fc7a9d568157/pixeltypes.h#L463

Here’s an example of using FastLED palettes: https://github.com/FastLED/FastLED/blob/master/examples/ColorPalette/ColorPalette.ino

Here’s the code with the pre-defined palettes: https://github.com/FastLED/FastLED/blob/8ee392ace11da654a99d980abb94fc7a9d568157/colorpalettes.cpp

(Myche Tician) #7

Does saturation really matter that much? What is all white in HSV anway? 255,255,255? Is there a baseline of saturation or level that washes out any color towards white? Forgive me if I’m asking stupid questions.

(Myche Tician) #8

For those of you who write your own routines, what parameter types do you use to specify colors?

(Daniel Garcia) #9

Saturation absolutely matters - it’s what gives you a wider range of colors. Personally, I run everything at a lower (and variable saturation), and it’s not uncommon for people to, when looking at the things i’ve done, comment on the range of colors that they’re seeing, that they didn’t expect from leds (because everyone out there uses that goddamned fully saturated color wheel).

All white in CHSV is any hue and any non-zero brightness value with a saturation of 0.

As for writing my own routines - I regularly use all of Hue Saturation and Value. (One thing I’ve been playing with is using three noise generators, one for each of hue, saturation, and value).

(Jason Coon) #10

Saturation matters. Open up any paint program and mess with the color picker using HSV or HSL. All white in HSV is { anything, 0, 255 }.

(Myche Tician) #11

I know saturation matters in programs like photoshop, but I’m not sure in an LED it isn’t already some kind of odd interpolation, since basically what do you have from a LED? varying brightness of 3 primary colors, so exactly what does saturation do? Does it, to some degree wash out the true color by adding extraneous light from the other LEDs? So what you’re really doing is washing out the color by adding a little whiteness to it? And fully-saturated means removing that extra white light?

(Daniel Garcia) #12

It’s the same as your lcd display panel (and your television) - everything you see is made up of combining red, blue, and green at different brightness.

Full saturation, basically, gives you the colors in the rainbow. However, the rainbow is hardly the full set of colors. De-saturating increases the amount contributed to the full color by all three of red, blue, and green, washing them out a little bit, and giving you a much wider range of softer colors than you would just get with pegging saturation at 255. If all you want are the colors that you would see in the rainbow, then you just need hue. If you want to add blacks into that as well, then you need to add in brightness, and if you want whites and grays (as well as all the other various in between colors), then you play with saturation.

(Seriously, a lot of this is stuff that spending some time with google and looking up information on colorspaces like HSV and RGB would bring you a long way)

(Myche Tician) #13

So it perhaps seems that the best way to handle all colors is to probably accept all three parameters? I’m just wondering if there are a lot of important colors that can’t be done without saturation? For example, does this mean without the use of saturation you can’t do pastels? I’ve read up on the color models - I’m just looking for some practical examples of the diverse array of colors that look good in LEDs from a practical standpoint.

(Myche Tician) #14

btw, I see the hue list here: https://raw.githubusercontent.com/FastLED/FastLED/gh-pages/images/HSV-rainbow-with-desc.jpg and on the calling page there’s a list of the color constants, but I wish there was a corresponding list of HSV values for those things.

What do most of you use as a source when trying to eyeball a color you want to program?

(Daniel Garcia) #15

There really isn’t a comprehensive list of hsv colors like there are for rgb (we basically just took the w3c definitions).

I don’t really select colors as much as tune the ranges of colors that’ll be used in a piece. A lot of people experiment and nudge colors around to get something that they like (there are so many factors that will affect how a color appears, like surrounding lighting, the diffusion, if any, used, etc…).

(Luminous Elements) #16

HSV colour space is more perceptual than RGB. Its usefulness comes from being able to interpolate, or pick randomly, a single variable (H, S, or V), keep the others constant, and have nice effects play out “automagically”. Your best bet is to experiment.

(Myche Tician) #17

Thanks for all the great responses!