Skip to content

Commit aab29cb

Browse files
committed
consolidated colorwaves and pride into one base function
the two FX are almost identical in code with just a few lines difference.
1 parent 566c505 commit aab29cb

File tree

1 file changed

+41
-64
lines changed

1 file changed

+41
-64
lines changed

wled00/FX.cpp

Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,48 +1893,72 @@ uint16_t mode_lightning(void) {
18931893
}
18941894
static const char _data_FX_MODE_LIGHTNING[] PROGMEM = "Lightning@!,!,,,,,Overlay;!,!;!";
18951895

1896-
1897-
// Pride2015
1898-
// Animated, ever-changing rainbows.
1899-
// by Mark Kriegsman: https://gist.github.com/kriegsman/964de772d64c502760e5
1900-
uint16_t mode_pride_2015(void) {
1896+
// combined function from original pride and colorwaves
1897+
uint16_t mode_colorwaves_pride_base(bool isPride2015) {
19011898
unsigned duration = 10 + SEGMENT.speed;
19021899
unsigned sPseudotime = SEGENV.step;
19031900
unsigned sHue16 = SEGENV.aux0;
19041901

1905-
uint8_t sat8 = beatsin88_t( 87, 220, 250);
1906-
uint8_t brightdepth = beatsin88_t( 341, 96, 224);
1907-
unsigned brightnessthetainc16 = beatsin88_t( 203, (25 * 256), (40 * 256));
1902+
uint8_t sat8 = isPride2015 ? beatsin88_t(87, 220, 250) : 255;
1903+
unsigned brightdepth = beatsin88_t(341, 96, 224);
1904+
unsigned brightnessthetainc16 = beatsin88_t(203, (25 * 256), (40 * 256));
19081905
unsigned msmultiplier = beatsin88_t(147, 23, 60);
19091906

1910-
unsigned hue16 = sHue16;//gHue * 256;
1911-
unsigned hueinc16 = beatsin88_t(113, 1, 3000);
1907+
unsigned hue16 = sHue16;
1908+
unsigned hueinc16 = isPride2015 ? beatsin88_t(113, 1, 3000) :
1909+
beatsin88_t(113, 60, 300) * SEGMENT.intensity * 10 / 255;
19121910

19131911
sPseudotime += duration * msmultiplier;
1914-
sHue16 += duration * beatsin88_t( 400, 5,9);
1912+
sHue16 += duration * beatsin88_t(400, 5, 9);
19151913
unsigned brightnesstheta16 = sPseudotime;
19161914

1917-
for (unsigned i = 0 ; i < SEGLEN; i++) {
1915+
for (unsigned i = 0; i < SEGLEN; i++) {
19181916
hue16 += hueinc16;
1919-
uint8_t hue8 = hue16 >> 8;
1917+
uint8_t hue8;
19201918

1921-
brightnesstheta16 += brightnessthetainc16;
1922-
unsigned b16 = sin16_t( brightnesstheta16 ) + 32768;
1919+
if (isPride2015) {
1920+
hue8 = hue16 >> 8;
1921+
} else {
1922+
unsigned h16_128 = hue16 >> 7;
1923+
hue8 = (h16_128 & 0x100) ? (255 - (h16_128 >> 1)) : (h16_128 >> 1);
1924+
}
19231925

1926+
brightnesstheta16 += brightnessthetainc16;
1927+
unsigned b16 = sin16_t(brightnesstheta16) + 32768;
19241928
unsigned bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
19251929
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
19261930
bri8 += (255 - brightdepth);
19271931

1928-
CRGB newcolor = CHSV(hue8, sat8, bri8);
1929-
SEGMENT.blendPixelColor(i, newcolor, 64);
1932+
if (isPride2015) {
1933+
CRGB newcolor = CHSV(hue8, sat8, bri8);
1934+
SEGMENT.blendPixelColor(i, newcolor, 64);
1935+
} else {
1936+
SEGMENT.blendPixelColor(i, SEGMENT.color_from_palette(hue8, false, PALETTE_SOLID_WRAP, 0, bri8), 128);
1937+
}
19301938
}
1939+
19311940
SEGENV.step = sPseudotime;
19321941
SEGENV.aux0 = sHue16;
19331942

19341943
return FRAMETIME;
19351944
}
1945+
1946+
// Pride2015
1947+
// Animated, ever-changing rainbows.
1948+
// by Mark Kriegsman: https://gist.github.com/kriegsman/964de772d64c502760e5
1949+
uint16_t mode_pride_2015(void) {
1950+
return mode_colorwaves_pride_base(true);
1951+
}
19361952
static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;";
19371953

1954+
// ColorWavesWithPalettes by Mark Kriegsman: https://gist.github.com/kriegsman/8281905786e8b2632aeb
1955+
// This function draws color waves with an ever-changing,
1956+
// widely-varying set of parameters, using a color palette.
1957+
uint16_t mode_colorwaves() {
1958+
return mode_colorwaves_pride_base(false);
1959+
}
1960+
static const char _data_FX_MODE_COLORWAVES[] PROGMEM = "Colorwaves@!,Hue;!;!;;pal=26";
1961+
19381962

19391963
//eight colored dots, weaving in and out of sync with each other
19401964
uint16_t mode_juggle(void) {
@@ -2141,53 +2165,6 @@ uint16_t mode_fire_2012() {
21412165
}
21422166
static const char _data_FX_MODE_FIRE_2012[] PROGMEM = "Fire 2012@Cooling,Spark rate,,2D Blur,Boost;;!;1;pal=35,sx=64,ix=160,m12=1,c2=128"; // bars
21432167

2144-
2145-
// ColorWavesWithPalettes by Mark Kriegsman: https://gist.github.com/kriegsman/8281905786e8b2632aeb
2146-
// This function draws color waves with an ever-changing,
2147-
// widely-varying set of parameters, using a color palette.
2148-
uint16_t mode_colorwaves() {
2149-
unsigned duration = 10 + SEGMENT.speed;
2150-
unsigned sPseudotime = SEGENV.step;
2151-
unsigned sHue16 = SEGENV.aux0;
2152-
2153-
unsigned brightdepth = beatsin88_t(341, 96, 224);
2154-
unsigned brightnessthetainc16 = beatsin88_t( 203, (25 * 256), (40 * 256));
2155-
unsigned msmultiplier = beatsin88_t(147, 23, 60);
2156-
2157-
unsigned hue16 = sHue16;//gHue * 256;
2158-
unsigned hueinc16 = beatsin88_t(113, 60, 300)*SEGMENT.intensity*10/255; // Use the Intensity Slider for the hues
2159-
2160-
sPseudotime += duration * msmultiplier;
2161-
sHue16 += duration * beatsin88_t(400, 5, 9);
2162-
unsigned brightnesstheta16 = sPseudotime;
2163-
2164-
for (unsigned i = 0 ; i < SEGLEN; i++) {
2165-
hue16 += hueinc16;
2166-
uint8_t hue8 = hue16 >> 8;
2167-
unsigned h16_128 = hue16 >> 7;
2168-
if ( h16_128 & 0x100) {
2169-
hue8 = 255 - (h16_128 >> 1);
2170-
} else {
2171-
hue8 = h16_128 >> 1;
2172-
}
2173-
2174-
brightnesstheta16 += brightnessthetainc16;
2175-
unsigned b16 = sin16_t(brightnesstheta16) + 32768;
2176-
2177-
unsigned bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
2178-
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
2179-
bri8 += (255 - brightdepth);
2180-
2181-
SEGMENT.blendPixelColor(i, SEGMENT.color_from_palette(hue8, false, PALETTE_SOLID_WRAP, 0, bri8), 128); // 50/50 mix
2182-
}
2183-
SEGENV.step = sPseudotime;
2184-
SEGENV.aux0 = sHue16;
2185-
2186-
return FRAMETIME;
2187-
}
2188-
static const char _data_FX_MODE_COLORWAVES[] PROGMEM = "Colorwaves@!,Hue;!;!;;pal=26";
2189-
2190-
21912168
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
21922169
uint16_t mode_bpm() {
21932170
uint32_t stp = (strip.now / 20) & 0xFF;

0 commit comments

Comments
 (0)