Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FastLED/FastLED.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Madison <dmadison@users.noreply.github.com>2022-01-02 23:38:35 +0300
committerDavid Madison <dmadison@users.noreply.github.com>2022-01-02 23:40:18 +0300
commit5cc52a289a405fcc580aac6621cc240a1ca8fce6 (patch)
treecf27f8c2f4784f4c579cde566d81c467e42a217e
parentfd06f2c97fc16034ba020eb2c2c2c8d643dbac6e (diff)
Create fill_palette_circular function
-rw-r--r--src/colorutils.h19
1 files changed, 18 insertions, 1 deletions
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 <typename PALETTE>
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 <typename PALETTE>
+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 <typename PALETTE>
void map_data_into_colors_through_palette(
uint8_t *dataArray, uint16_t dataCount,