I have some confusion about the use of color palettes.

I have some confusion about the use of color palettes. How does the code create the last 16 values of a 256 color palette? This comes up in the context of creating a palette with a constant hue (purple) and variable brightness - running from max brightness to black. I used a gradient palette definition, and it works as expected, until it reaches the last 16 values. If I run the brightness up from zero, the last sixteen leds decrease in brightness. If I run it with brightness decreasing, it goes to zero at position 240, and the last 16 leds show increasing brightness. I’m testing with a 16x16 matrix to show each value.

The decreasing gradient palette is defined as
( 0, 255 , 0 , 255,
63, 191 , 0 , 191 ,
127, 127 , 0 , 127 ,
191 , 63 , 0 , 63 ,
255 , 0 , 0 , 0 )

I would have thought this would create the black anchor point at position 256 (index 255 in code) but that doesn’t seem to be the case.

Use values 0-240 rather than the usual 0-255, as the last 15 colors will be ‘wrapping around’ from the end to the start. Sometimes this wrapping (circular blending) is useful, other times (in your case here) it’s not what you want.

If you do something like this:
CRGB c = ColorFromPalette( myPal, scale8( i , 240 ) );
then you can still program with 0-255 for i.

Thanks +Marc Miller. The library has so many amazing capabilities that the subtleties often escape me. Missed that one.