Hello, I have such a small problem with the acoustic spectrum analyzer.

Hello,

I have such a small problem with the acoustic spectrum analyzer. I use a color palette to give the diodes the right colors.
I do not want to assign the color of each diode sequentially through the loops.
When I use fill_palette, the stripes look like Figure A, I would like them to look like in Figure B. How to do it without using any loop and without using any “if”?

Currently i use:
fill_palette(linia1, oct0 / dzielnik, 0, 8 , currentPalette, oct0, NOBLEND);
fill_palette(linia2, oct1 / dzielnik, 0, 8 , currentPalette, oct1, NOBLEND);
fill_palette(linia3, oct2 / dzielnik, 0, 8 , currentPalette, oct2, NOBLEND);
fill_palette(linia4, oct3 / dzielnik, 0, 8 , currentPalette, oct3, NOBLEND);


Something that came to mind was to use a gradient color palette and move/scale the middle anchor point(s) around based on the height of each line.

First read this to make sure you understand how a gradient color palettes works.

Normally a gradient color palette is defined and the colors and the anchor points do not change. But it is possible to change things on the fly by doing something like this:

The Arduino “map” function might also be used as part of moving/scaling the anchor points around.
https://www.arduino.cc/reference/en/language/functions/math/map/

I’m not sure if this will work, but can’t you just reverse the palette and fill the strips from the top to the bottom?

Following on from @marmil 's ideas, I use this in some of my patterns, which maps a whole palette to a variable height column.

ColorFromPalette(palettes[currentPaletteIndex], map(i,0,columnHeight,0,255), 255)