FastLED 3.9.15
Loading...
Searching...
No Matches

◆ nblendPaletteTowardPalette()

void fl::nblendPaletteTowardPalette ( CRGBPalette16 & current,
CRGBPalette16 & target,
fl::u8 maxChanges )
Examples
TwinkleFox.ino.

Definition at line 1018 of file colorutils.cpp.

1019 {
1020 fl::u8 *p1;
1021 fl::u8 *p2;
1022 fl::u8 changes = 0;
1023
1024 p1 = (fl::u8 *)current.entries;
1025 p2 = (fl::u8 *)target.entries;
1026
1027 const fl::u8 totalChannels = sizeof(CRGBPalette16);
1028 for (fl::u8 i = 0; i < totalChannels; ++i) {
1029 // if the values are equal, no changes are needed
1030 if (p1[i] == p2[i]) {
1031 continue;
1032 }
1033
1034 // if the current value is less than the target, increase it by one
1035 if (p1[i] < p2[i]) {
1036 ++p1[i];
1037 ++changes;
1038 }
1039
1040 // if the current value is greater than the target,
1041 // increase it by one (or two if it's still greater).
1042 if (p1[i] > p2[i]) {
1043 --p1[i];
1044 ++changes;
1045 if (p1[i] > p2[i]) {
1046 --p1[i];
1047 }
1048 }
1049
1050 // if we've hit the maximum number of changes, exit
1051 if (changes >= maxChanges) {
1052 break;
1053 }
1054 }
1055}
unsigned char u8
Definition int.h:17