From 5cc52a289a405fcc580aac6621cc240a1ca8fce6 Mon Sep 17 00:00:00 2001 From: David Madison Date: Sun, 2 Jan 2022 15:38:35 -0500 Subject: Create fill_palette_circular function --- src/colorutils.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/colorutils.h b/src/colorutils.h index d33ce55e..16534ef6 100644 --- a/src/colorutils.h +++ b/src/colorutils.h @@ -1566,7 +1566,7 @@ CHSV ColorFromPalette( const CHSVPalette32& pal, TBlendType blendType=LINEARBLEND); -// Fill a range of LEDs with a sequece of entryies from a palette +// Fill a range of LEDs with a sequence of entries from a palette template void fill_palette(CRGB* L, uint16_t N, uint8_t startIndex, uint8_t incIndex, const PALETTE& pal, uint8_t brightness, TBlendType blendType) @@ -1578,6 +1578,23 @@ void fill_palette(CRGB* L, uint16_t N, uint8_t startIndex, uint8_t incIndex, } } +// Fill a range of LEDs with a sequence of entries from a palette, so that +// the entire palette smoothly covers the range of LEDs +template +void fill_palette_circular(CRGB* L, uint16_t N, uint8_t startIndex, + const PALETTE& pal, uint8_t brightness, TBlendType blendType) +{ + if (N == 0) return; // avoiding div/0 + + const uint16_t colorChange = 65536 / N; // color change for each LED, * 256 for precision + uint16_t colorIndex = ((uint16_t) startIndex) << 8; // offset for color index, with precision (*256) + + for (uint16_t i = 0; i < N; ++i) { + L[i] = ColorFromPalette(pal, (colorIndex >> 8), brightness, blendType); + colorIndex += colorChange; + } +} + template void map_data_into_colors_through_palette( uint8_t *dataArray, uint16_t dataCount, -- cgit v1.2.3