diff options
author | David Madison <dmadison@users.noreply.github.com> | 2022-01-03 00:25:43 +0300 |
---|---|---|
committer | David Madison <dmadison@users.noreply.github.com> | 2022-01-03 00:25:43 +0300 |
commit | dd30fd9143ca2eefaf68d29e5c72e8849e2a7c43 (patch) | |
tree | 7aa43b01ddecf1ac517b864ffd05ce1d60a795c8 | |
parent | f2da89411b1180398e204ca8c8522845706954f1 (diff) |
Add reversing option to fill_circular functions
-rw-r--r-- | src/colorutils.cpp | 10 | ||||
-rw-r--r-- | src/colorutils.h | 10 |
2 files changed, 12 insertions, 8 deletions
diff --git a/src/colorutils.cpp b/src/colorutils.cpp index 16cf855d..941f4686 100644 --- a/src/colorutils.cpp +++ b/src/colorutils.cpp @@ -62,7 +62,7 @@ void fill_rainbow( struct CHSV * targetArray, int numToFill, } -void fill_rainbow_circular(struct CRGB* targetArray, int numToFill, uint8_t initialhue) +void fill_rainbow_circular(struct CRGB* targetArray, int numToFill, uint8_t initialhue, bool reversed) { if (numToFill == 0) return; // avoiding div/0 @@ -76,12 +76,13 @@ void fill_rainbow_circular(struct CRGB* targetArray, int numToFill, uint8_t init for (int i = 0; i < numToFill; ++i) { targetArray[i] = hsv; - hueOffset += hueChange; // increase precise offset + if (reversed) hueOffset -= hueChange; + else hueOffset += hueChange; hsv.hue = initialhue + (uint8_t)(hueOffset >> 8); // assign new hue with precise offset (as 8-bit) } } -void fill_rainbow_circular(struct CHSV* targetArray, int numToFill, uint8_t initialhue) +void fill_rainbow_circular(struct CHSV* targetArray, int numToFill, uint8_t initialhue, bool reversed) { if (numToFill == 0) return; // avoiding div/0 @@ -95,7 +96,8 @@ void fill_rainbow_circular(struct CHSV* targetArray, int numToFill, uint8_t init for (int i = 0; i < numToFill; ++i) { targetArray[i] = hsv; - hueOffset += hueChange; // increase precise offset + if (reversed) hueOffset -= hueChange; + else hueOffset += hueChange; hsv.hue = initialhue + (uint8_t)(hueOffset >> 8); // assign new hue with precise offset (as 8-bit) } } diff --git a/src/colorutils.h b/src/colorutils.h index 8b9f98af..43c9c0ad 100644 --- a/src/colorutils.h +++ b/src/colorutils.h @@ -42,14 +42,14 @@ void fill_rainbow( struct CHSV * targetArray, int numToFill, /// so that the hues are continuous between the end /// of the strip and the beginning void fill_rainbow_circular(struct CRGB* targetArray, int numToFill, - uint8_t initialhue); + uint8_t initialhue, bool reversed=false); /// fill_rainbow_circular - fill a range of LEDs with a rainbow of colors, at /// full saturation and full value (brightness), /// so that the hues are continuous between the end /// of the strip and the beginning void fill_rainbow_circular(struct CHSV* targetArray, int numToFill, - uint8_t initialhue); + uint8_t initialhue, bool reversed=false); // fill_gradient - fill an array of colors with a smooth HSV gradient @@ -1582,7 +1582,8 @@ void fill_palette(CRGB* L, uint16_t N, uint8_t startIndex, uint8_t incIndex, // 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=255, TBlendType blendType=LINEARBLEND) + const PALETTE& pal, uint8_t brightness=255, TBlendType blendType=LINEARBLEND, + bool reversed=false) { if (N == 0) return; // avoiding div/0 @@ -1591,7 +1592,8 @@ void fill_palette_circular(CRGB* L, uint16_t N, uint8_t startIndex, for (uint16_t i = 0; i < N; ++i) { L[i] = ColorFromPalette(pal, (colorIndex >> 8), brightness, blendType); - colorIndex += colorChange; + if (reversed) colorIndex -= colorChange; + else colorIndex += colorChange; } } |