is it possible to define a gradient Palette at runtime?
the DEFINE_GRADIENT_PALETTE uses the program memory.
In my situation I want to create a new Palette each frame dynamically, it is for a christmas candle effect where the gradient points are “candles” that change their brigntness based on an algorithm from here http://bienonline.magix.net/public/avr-advent.html (its german, but google translate is ok) and I want brigntness gradients between those virtual candles along a strip of 200 LEDs which I use as an indirect lighting in my living room. It shall give an effect to the room that it is lighted by a lot of flickering candles.
To my understanding those SetupXXXPalette functions create CRGBPalette16 objects, where 16 colors have an equal “distance” in the palette, while the gradient palettes define also the control points of the gradients. Sure, I can achieve something with the 16 element palettes but I have plenty of RAM so it would be nice to have the gradient function.
Yep, you can do this. Internally, all palettes are CRGBPalette16 (or 256), even the ones defined as a gradient – the gradient is just a convenient and compact way to define them.
There’s no example code for this, but it is possible and it works. Set up a byte array with the gradient palette definition, create a CRGBPalette16, and then call myPal16.loadDynamicGradientPalette. Then use myPal16 as usual.
When you get it working, share your code here – other people might want to see it!
This is gold. I was trying to find a way to change the palette at runtime as well, as I have a web app that sends a request to my esp2866 server with the palette… so the palette can be created in the web app with a color picker.