Last active
March 8, 2016 04:05
-
-
Save tullo-x86/915c8dabf53bac12c3ae to your computer and use it in GitHub Desktop.
fill_gradient with palette support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Fill an array of colors with a sixteen-stop gradient from a palette. | |
// Only suitable for really long fades where banding must be minimised. | |
template <typename T> | |
void fill_gradient( T* targetArray, uint16_t numLeds, | |
const CHSVPalette16& palette, | |
TGradientDirectionCode directionCode = SHORTEST_HUES ) | |
{ | |
uint16_t spanLength = (numLeds / 15); | |
for (uint8_t spanIdx = 0; spanIdx < 14; spanIdx++) | |
{ | |
uint16_t spanStart = spanIdx * spanLength; | |
uint16_t spanEnd = (spanIdx+1) * spanLength; | |
fill_gradient(targetArray, spanStart, palette.entries[spanIdx], spanEnd, palette.entries[spanIdx+1], directionCode); | |
} | |
// The 15th span includes any leftover pixels from division | |
uint16_t spanStart = 14 * spanLength; | |
uint16_t spanEnd = numLeds - 1; | |
fill_gradient(targetArray, spanStart, palette.entries[14], spanEnd, palette.entries[15], directionCode); | |
} | |
// convenience synonym | |
#define fill_gradient_HSV fill_gradient | |
// etc... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment