Gradient color palettes The latest FastLED v3.1 on github has a new way of

Gradient color palettes
The latest FastLED v3.1 on github has a new way of letting you define color palettes: as a series of gradients. The first pass of documentation is here
There are some new predefined color palettes coming, and they are going to be in this format. It’s approximately as easy to use, it just looks different. E.g., here’s how you might define a palette with three gradients: from black (at index 0) to red (at index 128), from red (at 128) to bright yellow (at 224), and from bright yellow (at 224) to full white (at index 255):

  0,     0,  0,  0,   //black
128,   255,  0,  0,   //red
224,   255,255,  0,   //bright yellow
255,   255,255,255 }; //full white

Then to use it, it’s the same as always:
CRGBPalette16 myPal = heatmap_gp;
and then use ColorFromPalette( pal, index) to retrieve colors from the palette.

At this point, this update is mostly for folks who are already playing with FastLED color palettes; it assumes that you already know what they are, why you’d use one, and roughly how to code with one.

If you want to learn more about FastLED palettes, check out the example called ColorPalette (and/or the “colorpalette.h” source file).

This format is a little odd (e.g., why raw R G and B values, and why no CRGB?), but I have my odd little reasons. Laying the groundwork for what comes next.

It’s also worth noting that these are quite compact in terms of program size. For example, the heatmap example above takes just 16 bytes of program space to store, and zero bytes of SRAM.

Now of course, there’s some additional code required to use these palettes, and one CRGBPalette16 does take 48 bytes of SRAM. But once you’ve got that, you could probably store dozens of different color palettes in a single sketch. Hypothetically speaking, of course.

It seems to me the advantage with this is that you can now specify exactly where individual colours are defined in the index and let the blending take care of the rest. I assume that blending is similar to the current LINEARBLEND.

I do, however, like the CRGB method because I prefer to define a palette entry with a CHSV value, which is easy to rotate the hue while maintaining full colour saturation.

Will be looking forward to what comes next.

How many colors can you have? Does it have to be an even number of colors?

You can have as many as you like in the gradient definitions. The underlying palette has either 16 (CRGBPalette16) or 256 (CRGBPalette256) slots, so that’s going to be the limiting factor.

Play around!

Yay!! Thanks for this!

How easy will this make it to fade smoothly from one palette to another?

Palette crossfade is already available! Check out this post, code, and video from December
That what you had in mind?

That’s exactly what I was after. I can’t even keep up with all the good stuff you’re putting out there.

I would love to use these for my new LED table. For normal use, I don’t want patterns - just a simple gradient. Ideally, I would create a whole bunch of gradient palettes, be able to randomly select one, show it for a while, and then crossfade to another randomly selected one.

In my other projects, I’ve created an array of patterns and then used a random number to index into the array. Given how these are created and stored though, I’m guessing I can’t put them in an array. Is that correct? If so, can you think of a way I might be able to accomplish this?

I think I posted a gist showing how to do just this.

Check out

This is great Mark - thanks! I found your stash of demos a few days ago, but I’m still making my way through them (lots of great stuff!). I’ll play with this one tonight.

Great! It’s a start!

Yup - now I need to find a good stash of matrix-friendly examples. I have my own, but it’s always nice to see what other people are doing. Once FastLED supports the Photon I’ll be doing a lot more matrix work on my 8x8x8 and 16x16x16 L3D cubes!