FX update

- Dynamic & Dynamic Smooth
- Dissolve & Dissolve Rnd
- Juggles
- Game of Life
- Colorful
- Fireworks & Rain
This commit is contained in:
Blaz Kristan 2023-01-18 22:56:49 +01:00
parent 901ce23cd2
commit 17543535e3
3 changed files with 97 additions and 112 deletions

View File

@ -281,10 +281,12 @@ static const char _data_FX_MODE_RANDOM_COLOR[] PROGMEM = "Random Colors@!,Fade t
* Lights every LED in a random color. Changes all LED at the same time * Lights every LED in a random color. Changes all LED at the same time
* to new random colors. * to new random colors.
*/ */
uint16_t dynamic(boolean smooth=false) { uint16_t mode_dynamic(void) {
if (!SEGENV.allocateData(SEGLEN)) return mode_static(); //allocation failed if (!SEGENV.allocateData(SEGLEN)) return mode_static(); //allocation failed
if(SEGENV.call == 0) { if(SEGENV.call == 0) {
//SEGMENT.setUpLeds(); //lossless getPixelColor()
//SEGMENT.fill(BLACK);
for (int i = 0; i < SEGLEN; i++) SEGENV.data[i] = random8(); for (int i = 0; i < SEGLEN; i++) SEGENV.data[i] = random8();
} }
@ -293,14 +295,14 @@ uint16_t dynamic(boolean smooth=false) {
if (it != SEGENV.step && SEGMENT.speed != 0) //new color if (it != SEGENV.step && SEGMENT.speed != 0) //new color
{ {
for (int i = 0; i < SEGLEN; i++) { for (int i = 0; i < SEGLEN; i++) {
if (random8() <= SEGMENT.intensity) SEGENV.data[i] = random8(); if (random8() <= SEGMENT.intensity) SEGENV.data[i] = random8(); // random color index
} }
SEGENV.step = it; SEGENV.step = it;
} }
if (smooth) { if (SEGMENT.check1) {
for (int i = 0; i < SEGLEN; i++) { for (int i = 0; i < SEGLEN; i++) {
SEGMENT.blendPixelColor(i, SEGMENT.color_wheel(SEGENV.data[i]),16); // TODO SEGMENT.blendPixelColor(i, SEGMENT.color_wheel(SEGENV.data[i]), 16);
} }
} else { } else {
for (int i = 0; i < SEGLEN; i++) { for (int i = 0; i < SEGLEN; i++) {
@ -309,22 +311,18 @@ uint16_t dynamic(boolean smooth=false) {
} }
return FRAMETIME; return FRAMETIME;
} }
static const char _data_FX_MODE_DYNAMIC[] PROGMEM = "Dynamic@!,!,,,,Smooth;;!";
/* /*
* Original effect "Dynamic" * effect "Dynamic" with smooth color-fading
*/
uint16_t mode_dynamic(void) {
return dynamic(false);
}
static const char _data_FX_MODE_DYNAMIC[] PROGMEM = "Dynamic@!,!;;!";
/*
* effect "Dynamic" with smoth color-fading
*/ */
uint16_t mode_dynamic_smooth(void) { uint16_t mode_dynamic_smooth(void) {
return dynamic(true); bool old = SEGMENT.check1;
SEGMENT.check1 = true;
mode_dynamic();
SEGMENT.check1 = old;
return FRAMETIME;
} }
static const char _data_FX_MODE_DYNAMIC_SMOOTH[] PROGMEM = "Dynamic Smooth@!,!;;!"; static const char _data_FX_MODE_DYNAMIC_SMOOTH[] PROGMEM = "Dynamic Smooth@!,!;;!";
@ -603,33 +601,38 @@ static const char _data_FX_MODE_TWINKLE[] PROGMEM = "Twinkle@!,!;!,!;!;;m12=0";
* Dissolve function * Dissolve function
*/ */
uint16_t dissolve(uint32_t color) { uint16_t dissolve(uint32_t color) {
bool wa = (SEGCOLOR(1) != 0 && strip.getBrightness() < 255); //workaround, can't compare getPixel to color if not full brightness //bool wa = (SEGCOLOR(1) != 0 && strip.getBrightness() < 255); //workaround, can't compare getPixel to color if not full brightness
if (SEGENV.call == 0) {
SEGMENT.setUpLeds(); //lossless getPixelColor()
SEGMENT.fill(SEGCOLOR(1));
}
for (int j = 0; j <= SEGLEN / 15; j++) for (int j = 0; j <= SEGLEN / 15; j++) {
{
if (random8() <= SEGMENT.intensity) { if (random8() <= SEGMENT.intensity) {
for (size_t times = 0; times < 10; times++) //attempt to spawn a new pixel 5 times for (size_t times = 0; times < 10; times++) //attempt to spawn a new pixel 10 times
{ {
uint16_t i = random16(SEGLEN); uint16_t i = random16(SEGLEN);
if (SEGENV.aux0) { //dissolve to primary/palette if (SEGENV.aux0) { //dissolve to primary/palette
if (SEGMENT.getPixelColor(i) == SEGCOLOR(1) || wa) { // TODO if (SEGMENT.getPixelColor(i) == SEGCOLOR(1) /*|| wa*/) {
if (color == SEGCOLOR(0)) if (color == SEGCOLOR(0)) {
{
SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0)); SEGMENT.setPixelColor(i, SEGMENT.color_from_palette(i, true, PALETTE_SOLID_WRAP, 0));
} else { SEGMENT.setPixelColor(i, color); } } else {
SEGMENT.setPixelColor(i, color);
}
break; //only spawn 1 new pixel per frame per 50 LEDs break; //only spawn 1 new pixel per frame per 50 LEDs
} }
} else { //dissolve to secondary } else { //dissolve to secondary
if (SEGMENT.getPixelColor(i) != SEGCOLOR(1)) { SEGMENT.setPixelColor(i, SEGCOLOR(1)); break; } // TODO if (SEGMENT.getPixelColor(i) != SEGCOLOR(1)) { SEGMENT.setPixelColor(i, SEGCOLOR(1)); break; }
} }
} }
} }
} }
if (SEGENV.call > (255 - SEGMENT.speed) + 15U) if (SEGENV.step > (255 - SEGMENT.speed) + 15U) {
{
SEGENV.aux0 = !SEGENV.aux0; SEGENV.aux0 = !SEGENV.aux0;
SEGENV.call = 0; SEGENV.step = 0;
} else {
SEGENV.step++;
} }
return FRAMETIME; return FRAMETIME;
@ -640,9 +643,9 @@ uint16_t dissolve(uint32_t color) {
* Blink several LEDs on and then off * Blink several LEDs on and then off
*/ */
uint16_t mode_dissolve(void) { uint16_t mode_dissolve(void) {
return dissolve(SEGCOLOR(0)); return dissolve(SEGMENT.check1 ? SEGMENT.color_wheel(random8()) : SEGCOLOR(0));
} }
static const char _data_FX_MODE_DISSOLVE[] PROGMEM = "Dissolve@Repeat speed,Dissolve speed;!,!;!"; static const char _data_FX_MODE_DISSOLVE[] PROGMEM = "Dissolve@Repeat speed,Dissolve speed,,,,Random;!,!;!";
/* /*
@ -1193,17 +1196,19 @@ uint16_t mode_fireworks() {
const uint16_t width = strip.isMatrix ? SEGMENT.virtualWidth() : SEGMENT.virtualLength(); const uint16_t width = strip.isMatrix ? SEGMENT.virtualWidth() : SEGMENT.virtualLength();
const uint16_t height = SEGMENT.virtualHeight(); const uint16_t height = SEGMENT.virtualHeight();
SEGMENT.fade_out(0);
if (SEGENV.call == 0) { if (SEGENV.call == 0) {
SEGMENT.setUpLeds(); //lossless getPixelColor()
SEGMENT.fill(SEGCOLOR(1));
SEGENV.aux0 = UINT16_MAX; SEGENV.aux0 = UINT16_MAX;
SEGENV.aux1 = UINT16_MAX; SEGENV.aux1 = UINT16_MAX;
} }
SEGMENT.fade_out(128);
bool valid1 = (SEGENV.aux0 < width*height); bool valid1 = (SEGENV.aux0 < width*height);
bool valid2 = (SEGENV.aux1 < width*height); bool valid2 = (SEGENV.aux1 < width*height);
uint32_t sv1 = 0, sv2 = 0; uint32_t sv1 = 0, sv2 = 0;
if (valid1) sv1 = strip.isMatrix ? SEGMENT.getPixelColorXY(SEGENV.aux0%width, SEGENV.aux0/width) : SEGMENT.getPixelColor(SEGENV.aux0); // TODO get spark color if (valid1) sv1 = strip.isMatrix ? SEGMENT.getPixelColorXY(SEGENV.aux0%width, SEGENV.aux0/width) : SEGMENT.getPixelColor(SEGENV.aux0); // get spark color
if (valid2) sv2 = strip.isMatrix ? SEGMENT.getPixelColorXY(SEGENV.aux1%width, SEGENV.aux1/width) : SEGMENT.getPixelColor(SEGENV.aux1); // TODO if (valid2) sv2 = strip.isMatrix ? SEGMENT.getPixelColorXY(SEGENV.aux1%width, SEGENV.aux1/width) : SEGMENT.getPixelColor(SEGENV.aux1);
if (!SEGENV.step) SEGMENT.blur(16); if (!SEGENV.step) SEGMENT.blur(16);
if (valid1) { if (strip.isMatrix) SEGMENT.setPixelColorXY(SEGENV.aux0%width, SEGENV.aux0/width, sv1); else SEGMENT.setPixelColor(SEGENV.aux0, sv1); } // restore spark color after blur if (valid1) { if (strip.isMatrix) SEGMENT.setPixelColorXY(SEGENV.aux0%width, SEGENV.aux0/width, sv1); else SEGMENT.setPixelColor(SEGENV.aux0, sv1); } // restore spark color after blur
if (valid2) { if (strip.isMatrix) SEGMENT.setPixelColorXY(SEGENV.aux1%width, SEGENV.aux1/width, sv2); else SEGMENT.setPixelColor(SEGENV.aux1, sv2); } // restore old spark color after blur if (valid2) { if (strip.isMatrix) SEGMENT.setPixelColorXY(SEGENV.aux1%width, SEGENV.aux1/width, sv2); else SEGMENT.setPixelColor(SEGENV.aux1, sv2); } // restore old spark color after blur
@ -1230,7 +1235,7 @@ uint16_t mode_rain()
const uint16_t width = SEGMENT.virtualWidth(); const uint16_t width = SEGMENT.virtualWidth();
const uint16_t height = SEGMENT.virtualHeight(); const uint16_t height = SEGMENT.virtualHeight();
SEGENV.step += FRAMETIME; SEGENV.step += FRAMETIME;
if (SEGENV.step > SPEED_FORMULA_L) { if (SEGENV.call && SEGENV.step > SPEED_FORMULA_L) {
SEGENV.step = 1; SEGENV.step = 1;
if (strip.isMatrix) { if (strip.isMatrix) {
uint32_t ctemp[width]; uint32_t ctemp[width];
@ -1241,9 +1246,9 @@ uint16_t mode_rain()
SEGENV.aux1 = (SEGENV.aux1 % width) + (SEGENV.aux1 / width + 1) * width; SEGENV.aux1 = (SEGENV.aux1 % width) + (SEGENV.aux1 / width + 1) * width;
} else { } else {
//shift all leds left //shift all leds left
uint32_t ctemp = SEGMENT.getPixelColor(0); // TODO uint32_t ctemp = SEGMENT.getPixelColor(0);
for (int i = 0; i < SEGLEN - 1; i++) { for (int i = 0; i < SEGLEN - 1; i++) {
SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1)); // TODO SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1));
} }
SEGMENT.setPixelColor(SEGLEN -1, ctemp); // wrap around SEGMENT.setPixelColor(SEGLEN -1, ctemp); // wrap around
SEGENV.aux0++; // increase spark index SEGENV.aux0++; // increase spark index
@ -1585,8 +1590,7 @@ static const char _data_FX_MODE_ICU[] PROGMEM = "ICU@!,!,,,,,Overlay;!,!;!";
/* /*
* Custom mode by Aircoookie. Color Wipe, but with 3 colors * Custom mode by Aircoookie. Color Wipe, but with 3 colors
*/ */
uint16_t mode_tricolor_wipe(void) uint16_t mode_tricolor_wipe(void) {
{
uint32_t cycleTime = 1000 + (255 - SEGMENT.speed)*200; uint32_t cycleTime = 1000 + (255 - SEGMENT.speed)*200;
uint32_t perc = strip.now % cycleTime; uint32_t perc = strip.now % cycleTime;
uint16_t prog = (perc * 65535) / cycleTime; uint16_t prog = (perc * 65535) / cycleTime;
@ -1628,8 +1632,7 @@ static const char _data_FX_MODE_TRICOLOR_WIPE[] PROGMEM = "Tri Wipe@!;1,2,3;!";
* Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/TriFade.h * Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/TriFade.h
* Modified by Aircoookie * Modified by Aircoookie
*/ */
uint16_t mode_tricolor_fade(void) uint16_t mode_tricolor_fade(void) {
{
uint16_t counter = strip.now * ((SEGMENT.speed >> 3) +1); uint16_t counter = strip.now * ((SEGMENT.speed >> 3) +1);
uint32_t prog = (counter * 768) >> 16; uint32_t prog = (counter * 768) >> 16;
@ -1672,8 +1675,7 @@ static const char _data_FX_MODE_TRICOLOR_FADE[] PROGMEM = "Tri Fade@!;1,2,3;!";
* Creates random comets * Creates random comets
* Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/MultiComet.h * Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/MultiComet.h
*/ */
uint16_t mode_multi_comet(void) uint16_t mode_multi_comet(void) {
{
uint32_t cycleTime = 10 + (uint32_t)(255 - SEGMENT.speed); uint32_t cycleTime = 10 + (uint32_t)(255 - SEGMENT.speed);
uint32_t it = strip.now / cycleTime; uint32_t it = strip.now / cycleTime;
if (SEGENV.step == it) return FRAMETIME; if (SEGENV.step == it) return FRAMETIME;
@ -1711,8 +1713,7 @@ static const char _data_FX_MODE_MULTI_COMET[] PROGMEM = "Multi Comet";
* Running random pixels ("Stream 2") * Running random pixels ("Stream 2")
* Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/RandomChase.h * Custom mode by Keith Lord: https://github.com/kitesurfer1404/WS2812FX/blob/master/src/custom/RandomChase.h
*/ */
uint16_t mode_random_chase(void) uint16_t mode_random_chase(void) {
{
if (SEGENV.call == 0) { if (SEGENV.call == 0) {
SEGENV.step = RGBW32(random8(), random8(), random8(), 0); SEGENV.step = RGBW32(random8(), random8(), random8(), 0);
SEGENV.aux0 = random16(); SEGENV.aux0 = random16();
@ -1754,8 +1755,7 @@ typedef struct Oscillator {
/* /*
/ Oscillating bars of color, updated with standard framerate / Oscillating bars of color, updated with standard framerate
*/ */
uint16_t mode_oscillate(void) uint16_t mode_oscillate(void) {
{
uint8_t numOscillators = 3; uint8_t numOscillators = 3;
uint16_t dataSize = sizeof(oscillator) * numOscillators; uint16_t dataSize = sizeof(oscillator) * numOscillators;
@ -1807,8 +1807,7 @@ static const char _data_FX_MODE_OSCILLATE[] PROGMEM = "Oscillate";
//TODO //TODO
uint16_t mode_lightning(void) uint16_t mode_lightning(void) {
{
uint16_t ledstart = random16(SEGLEN); // Determine starting location of flash uint16_t ledstart = random16(SEGLEN); // Determine starting location of flash
uint16_t ledlen = 1 + random16(SEGLEN -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1) uint16_t ledlen = 1 + random16(SEGLEN -ledstart); // Determine length of flash (not to go beyond NUM_LEDS-1)
uint8_t bri = 255/random8(1, 3); uint8_t bri = 255/random8(1, 3);
@ -1853,8 +1852,7 @@ static const char _data_FX_MODE_LIGHTNING[] PROGMEM = "Lightning@!,!,,,,,Overlay
// Pride2015 // Pride2015
// Animated, ever-changing rainbows. // Animated, ever-changing rainbows.
// by Mark Kriegsman: https://gist.github.com/kriegsman/964de772d64c502760e5 // by Mark Kriegsman: https://gist.github.com/kriegsman/964de772d64c502760e5
uint16_t mode_pride_2015(void) uint16_t mode_pride_2015(void) {
{
uint16_t duration = 10 + SEGMENT.speed; uint16_t duration = 10 + SEGMENT.speed;
uint16_t sPseudotime = SEGENV.step; uint16_t sPseudotime = SEGENV.step;
uint16_t sHue16 = SEGENV.aux0; uint16_t sHue16 = SEGENV.aux0;
@ -1883,11 +1881,8 @@ uint16_t mode_pride_2015(void)
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536; uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth); bri8 += (255 - brightdepth);
CRGB newcolor = CHSV( hue8, sat8, bri8); CRGB newcolor = CHSV(hue8, sat8, bri8);
fastled_col = CRGB(SEGMENT.getPixelColor(i)); // TODO SEGMENT.blendPixelColor(i, newcolor, 64);
nblend(fastled_col, newcolor, 64);
SEGMENT.setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
} }
SEGENV.step = sPseudotime; SEGENV.step = sPseudotime;
SEGENV.aux0 = sHue16; SEGENV.aux0 = sHue16;
@ -1898,24 +1893,29 @@ static const char _data_FX_MODE_PRIDE_2015[] PROGMEM = "Pride 2015@!;;";
//eight colored dots, weaving in and out of sync with each other //eight colored dots, weaving in and out of sync with each other
uint16_t mode_juggle(void){ uint16_t mode_juggle(void) {
SEGMENT.fade_out(SEGMENT.intensity); if (SEGENV.call == 0) {
SEGMENT.setUpLeds(); //lossless getPixelColor()
SEGMENT.fill(BLACK);
}
SEGMENT.fadeToBlackBy(192 - (3*SEGMENT.intensity/4));
CRGB fastled_col; CRGB fastled_col;
byte dothue = 0; byte dothue = 0;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
uint16_t index = 0 + beatsin88((128 + SEGMENT.speed)*(i + 7), 0, SEGLEN -1); uint16_t index = 0 + beatsin88((16 + SEGMENT.speed)*(i + 7), 0, SEGLEN -1);
fastled_col = CRGB(SEGMENT.getPixelColor(index)); // TODO fastled_col = CRGB(SEGMENT.getPixelColor(index));
fastled_col |= (SEGMENT.palette==0)?CHSV(dothue, 220, 255):ColorFromPalette(SEGPALETTE, dothue, 255); fastled_col |= (SEGMENT.palette==0)?CHSV(dothue, 220, 255):ColorFromPalette(SEGPALETTE, dothue, 255);
SEGMENT.setPixelColor(index, fastled_col.red, fastled_col.green, fastled_col.blue); SEGMENT.setPixelColor(index, fastled_col);
dothue += 32; dothue += 32;
} }
return FRAMETIME; return FRAMETIME;
} }
static const char _data_FX_MODE_JUGGLE[] PROGMEM = "Juggle@!,Trail;;!;;sx=16,ix=240"; static const char _data_FX_MODE_JUGGLE[] PROGMEM = "Juggle@!,Trail;;!;;sx=64,ix=128";
uint16_t mode_palette() uint16_t mode_palette() {
{
uint16_t counter = 0; uint16_t counter = 0;
if (SEGMENT.speed != 0) if (SEGMENT.speed != 0)
{ {
@ -1963,8 +1963,7 @@ static const char _data_FX_MODE_PALETTE[] PROGMEM = "Palette@Cycle speed;;!;;c3=
// There are two main parameters you can play with to control the look and // There are two main parameters you can play with to control the look and
// feel of your fire: COOLING (used in step 1 above) (Speed = COOLING), and SPARKING (used // feel of your fire: COOLING (used in step 1 above) (Speed = COOLING), and SPARKING (used
// in step 3 above) (Effect Intensity = Sparking). // in step 3 above) (Effect Intensity = Sparking).
uint16_t mode_fire_2012() uint16_t mode_fire_2012() {
{
uint16_t strips = SEGMENT.nrOfVStrips(); uint16_t strips = SEGMENT.nrOfVStrips();
if (!SEGENV.allocateData(strips * SEGLEN)) return mode_static(); //allocation failed if (!SEGENV.allocateData(strips * SEGLEN)) return mode_static(); //allocation failed
byte* heat = SEGENV.data; byte* heat = SEGENV.data;
@ -2023,8 +2022,7 @@ static const char _data_FX_MODE_FIRE_2012[] PROGMEM = "Fire 2012@Cooling,Spark r
// ColorWavesWithPalettes by Mark Kriegsman: https://gist.github.com/kriegsman/8281905786e8b2632aeb // ColorWavesWithPalettes by Mark Kriegsman: https://gist.github.com/kriegsman/8281905786e8b2632aeb
// This function draws color waves with an ever-changing, // This function draws color waves with an ever-changing,
// widely-varying set of parameters, using a color palette. // widely-varying set of parameters, using a color palette.
uint16_t mode_colorwaves() uint16_t mode_colorwaves() {
{
uint16_t duration = 10 + SEGMENT.speed; uint16_t duration = 10 + SEGMENT.speed;
uint16_t sPseudotime = SEGENV.step; uint16_t sPseudotime = SEGENV.step;
uint16_t sHue16 = SEGENV.aux0; uint16_t sHue16 = SEGENV.aux0;
@ -2034,15 +2032,11 @@ uint16_t mode_colorwaves()
uint8_t msmultiplier = beatsin88(147, 23, 60); uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t hue16 = sHue16;//gHue * 256; uint16_t hue16 = sHue16;//gHue * 256;
// uint16_t hueinc16 = beatsin88(113, 300, 1500);
uint16_t hueinc16 = beatsin88(113, 60, 300)*SEGMENT.intensity*10/255; // Use the Intensity Slider for the hues uint16_t hueinc16 = beatsin88(113, 60, 300)*SEGMENT.intensity*10/255; // Use the Intensity Slider for the hues
sPseudotime += duration * msmultiplier; sPseudotime += duration * msmultiplier;
sHue16 += duration * beatsin88(400, 5, 9); sHue16 += duration * beatsin88(400, 5, 9);
uint16_t brightnesstheta16 = sPseudotime; uint16_t brightnesstheta16 = sPseudotime;
//CRGB fastled_col;
if (SEGENV.call == 0) SEGMENT.fill(BLACK);
for (int i = 0 ; i < SEGLEN; i++) { for (int i = 0 ; i < SEGLEN; i++) {
hue16 += hueinc16; hue16 += hueinc16;
@ -2055,17 +2049,12 @@ uint16_t mode_colorwaves()
} }
brightnesstheta16 += brightnessthetainc16; brightnesstheta16 += brightnessthetainc16;
uint16_t b16 = sin16( brightnesstheta16 ) + 32768; uint16_t b16 = sin16(brightnesstheta16) + 32768;
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536; uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536; uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth); bri8 += (255 - brightdepth);
//CRGB newcolor = ColorFromPalette(SEGPALETTE, hue8, bri8);
//fastled_col = SEGMENT.getPixelColor(i); // TODO
//nblend(fastled_col, newcolor, 128);
//SEGMENT.setPixelColor(i, fastled_col.red, fastled_col.green, fastled_col.blue);
SEGMENT.blendPixelColor(i, SEGMENT.color_from_palette(hue8, false, PALETTE_SOLID_WRAP, 0, bri8), 128); // 50/50 mix SEGMENT.blendPixelColor(i, SEGMENT.color_from_palette(hue8, false, PALETTE_SOLID_WRAP, 0, bri8), 128); // 50/50 mix
} }
SEGENV.step = sPseudotime; SEGENV.step = sPseudotime;
@ -2077,8 +2066,7 @@ static const char _data_FX_MODE_COLORWAVES[] PROGMEM = "Colorwaves@!,Hue;!;!";
// colored stripes pulsing at a defined Beats-Per-Minute (BPM) // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint16_t mode_bpm() uint16_t mode_bpm() {
{
//CRGB fastled_col; //CRGB fastled_col;
uint32_t stp = (strip.now / 20) & 0xFF; uint32_t stp = (strip.now / 20) & 0xFF;
uint8_t beat = beatsin8(SEGMENT.speed, 64, 255); uint8_t beat = beatsin8(SEGMENT.speed, 64, 255);
@ -2093,8 +2081,7 @@ uint16_t mode_bpm()
static const char _data_FX_MODE_BPM[] PROGMEM = "Bpm@!;!;!;;sx=64"; static const char _data_FX_MODE_BPM[] PROGMEM = "Bpm@!;!;!;;sx=64";
uint16_t mode_fillnoise8() uint16_t mode_fillnoise8() {
{
if (SEGENV.call == 0) SEGENV.step = random16(12345); if (SEGENV.call == 0) SEGENV.step = random16(12345);
//CRGB fastled_col; //CRGB fastled_col;
for (int i = 0; i < SEGLEN; i++) { for (int i = 0; i < SEGLEN; i++) {
@ -2110,8 +2097,7 @@ uint16_t mode_fillnoise8()
static const char _data_FX_MODE_FILLNOISE8[] PROGMEM = "Fill Noise@!;!;!"; static const char _data_FX_MODE_FILLNOISE8[] PROGMEM = "Fill Noise@!;!;!";
uint16_t mode_noise16_1() uint16_t mode_noise16_1() {
{
uint16_t scale = 320; // the "zoom factor" for the noise uint16_t scale = 320; // the "zoom factor" for the noise
//CRGB fastled_col; //CRGB fastled_col;
SEGENV.step += (1 + SEGMENT.speed/16); SEGENV.step += (1 + SEGMENT.speed/16);
@ -2135,8 +2121,7 @@ uint16_t mode_noise16_1()
static const char _data_FX_MODE_NOISE16_1[] PROGMEM = "Noise 1@!;!;!"; static const char _data_FX_MODE_NOISE16_1[] PROGMEM = "Noise 1@!;!;!";
uint16_t mode_noise16_2() uint16_t mode_noise16_2() {
{
uint16_t scale = 1000; // the "zoom factor" for the noise uint16_t scale = 1000; // the "zoom factor" for the noise
//CRGB fastled_col; //CRGB fastled_col;
SEGENV.step += (1 + (SEGMENT.speed >> 1)); SEGENV.step += (1 + (SEGMENT.speed >> 1));
@ -2157,8 +2142,7 @@ uint16_t mode_noise16_2()
static const char _data_FX_MODE_NOISE16_2[] PROGMEM = "Noise 2@!;!;!"; static const char _data_FX_MODE_NOISE16_2[] PROGMEM = "Noise 2@!;!;!";
uint16_t mode_noise16_3() uint16_t mode_noise16_3() {
{
uint16_t scale = 800; // the "zoom factor" for the noise uint16_t scale = 800; // the "zoom factor" for the noise
//CRGB fastled_col; //CRGB fastled_col;
SEGENV.step += (1 + SEGMENT.speed); SEGENV.step += (1 + SEGMENT.speed);
@ -2183,8 +2167,7 @@ static const char _data_FX_MODE_NOISE16_3[] PROGMEM = "Noise 3@!;!;!";
//https://github.com/aykevl/ledstrip-spark/blob/master/ledstrip.ino //https://github.com/aykevl/ledstrip-spark/blob/master/ledstrip.ino
uint16_t mode_noise16_4() uint16_t mode_noise16_4() {
{
//CRGB fastled_col; //CRGB fastled_col;
uint32_t stp = (strip.now * SEGMENT.speed) >> 7; uint32_t stp = (strip.now * SEGMENT.speed) >> 7;
for (int i = 0; i < SEGLEN; i++) { for (int i = 0; i < SEGLEN; i++) {
@ -2199,8 +2182,7 @@ static const char _data_FX_MODE_NOISE16_4[] PROGMEM = "Noise 4@!;!;!";
//based on https://gist.github.com/kriegsman/5408ecd397744ba0393e //based on https://gist.github.com/kriegsman/5408ecd397744ba0393e
uint16_t mode_colortwinkle() uint16_t mode_colortwinkle() {
{
uint16_t dataSize = (SEGLEN+7) >> 3; //1 bit per LED uint16_t dataSize = (SEGLEN+7) >> 3; //1 bit per LED
if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed if (!SEGENV.allocateData(dataSize)) return mode_static(); //allocation failed
@ -2353,8 +2335,7 @@ static const char _data_FX_MODE_METEOR_SMOOTH[] PROGMEM = "Meteor Smooth@!,Trail
//Railway Crossing / Christmas Fairy lights //Railway Crossing / Christmas Fairy lights
uint16_t mode_railway() uint16_t mode_railway() {
{
uint16_t dur = (256 - SEGMENT.speed) * 40; uint16_t dur = (256 - SEGMENT.speed) * 40;
uint16_t rampdur = (dur * SEGMENT.intensity) >> 8; uint16_t rampdur = (dur * SEGMENT.intensity) >> 8;
if (SEGENV.step > dur) if (SEGENV.step > dur)
@ -4844,7 +4825,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
const uint16_t cols = SEGMENT.virtualWidth(); const uint16_t cols = SEGMENT.virtualWidth();
const uint16_t rows = SEGMENT.virtualHeight(); const uint16_t rows = SEGMENT.virtualHeight();
const uint16_t dataSize = sizeof(CRGB) * SEGMENT.length(); // using width*height prevents reallocation if mirroring is enabled const uint16_t dataSize = sizeof(CRGB) * SEGMENT.length(); // using width*height prevents reallocation if mirroring is enabled
const uint16_t crcBufferLen = (SEGMENT.width() + SEGMENT.height())*71/100; // roughly sqrt(2)/2 for better repetition detection (Ewowi) const uint16_t crcBufferLen = 2; //(SEGMENT.width() + SEGMENT.height())*71/100; // roughly sqrt(2)/2 for better repetition detection (Ewowi)
if (!SEGENV.allocateData(dataSize + sizeof(uint16_t)*crcBufferLen)) return mode_static(); //allocation failed if (!SEGENV.allocateData(dataSize + sizeof(uint16_t)*crcBufferLen)) return mode_static(); //allocation failed
CRGB *prevLeds = reinterpret_cast<CRGB*>(SEGENV.data); CRGB *prevLeds = reinterpret_cast<CRGB*>(SEGENV.data);
@ -4852,7 +4833,9 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
CRGB backgroundColor = SEGCOLOR(1); CRGB backgroundColor = SEGCOLOR(1);
if (SEGENV.call == 0 || strip.now - SEGMENT.step > 5000) { if (SEGENV.call == 0) SEGMENT.setUpLeds();
if (SEGENV.call == 0 || strip.now - SEGMENT.step > 3000) {
SEGENV.step = strip.now; SEGENV.step = strip.now;
SEGENV.aux0 = 0; SEGENV.aux0 = 0;
random16_set_seed(millis()>>2); //seed the random generator random16_set_seed(millis()>>2); //seed the random generator
@ -4879,20 +4862,22 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
//calculate new leds //calculate new leds
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) { for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) {
colorCount colorsCount[9];//count the different colors in the 9*9 matrix
for (int i=0; i<9; i++) colorsCount[i] = {backgroundColor, 0}; //init colorsCount
//iterate through neighbors and count them and their different colors colorCount colorsCount[9]; // count the different colors in the 3*3 matrix
for (int i=0; i<9; i++) colorsCount[i] = {backgroundColor, 0}; // init colorsCount
// iterate through neighbors and count them and their different colors
int neighbors = 0; int neighbors = 0;
for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) { //iterate through 9*9 matrix for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) { // iterate through 3*3 matrix
if (i==0 && j==0) continue; // ignore itself
// wrap around segment // wrap around segment
int16_t xx = x+i, yy = y+j; int16_t xx = x+i, yy = y+j;
if (x+i < 0) xx = cols-1; else if (x+i >= cols) xx = 0; if (x+i < 0) xx = cols-1; else if (x+i >= cols) xx = 0;
if (y+j < 0) yy = rows-1; else if (y+j >= rows) yy = 0; if (y+j < 0) yy = rows-1; else if (y+j >= rows) yy = 0;
uint16_t xy = XY(xx, yy); // previous cell xy to check
// count different neighbours and colors, except the centre cell uint16_t xy = XY(xx, yy); // previous cell xy to check
if (xy != XY(x,y) && prevLeds[xy] != backgroundColor) { // count different neighbours and colors
if (prevLeds[xy] != backgroundColor) {
neighbors++; neighbors++;
bool colorFound = false; bool colorFound = false;
int k; int k;
@ -4901,22 +4886,22 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
colorsCount[k].count++; colorsCount[k].count++;
colorFound = true; colorFound = true;
} }
if (!colorFound) colorsCount[k] = {prevLeds[xy], 1}; //add new color found in the array if (!colorFound) colorsCount[k] = {prevLeds[xy], 1}; //add new color found in the array
} }
} // i,j } // i,j
// Rules of Life // Rules of Life
uint32_t col = SEGMENT.getPixelColorXY(x,y); uint32_t col = prevLeds[XY(x,y)];
uint32_t bgc = RGBW32(backgroundColor.r, backgroundColor.g, backgroundColor.b, 0); uint32_t bgc = RGBW32(backgroundColor.r, backgroundColor.g, backgroundColor.b, 0);
if ((col != bgc) && (neighbors < 2)) SEGMENT.setPixelColorXY(x,y, bgc); // Loneliness if ((col != bgc) && (neighbors < 2)) SEGMENT.setPixelColorXY(x,y, bgc); // Loneliness
else if ((col != bgc) && (neighbors > 3)) SEGMENT.setPixelColorXY(x,y, bgc); // Overpopulation else if ((col != bgc) && (neighbors > 3)) SEGMENT.setPixelColorXY(x,y, bgc); // Overpopulation
else if ((col == bgc) && (neighbors == 3)) { // Reproduction else if ((col == bgc) && (neighbors == 3)) { // Reproduction
//find dominant color and assign to cell // find dominant color and assign it to a cell
colorCount dominantColorCount = {backgroundColor, 0}; colorCount dominantColorCount = {backgroundColor, 0};
for (int i=0; i<9 && colorsCount[i].count != 0; i++) for (int i=0; i<9 && colorsCount[i].count != 0; i++)
if (colorsCount[i].count > dominantColorCount.count) dominantColorCount = colorsCount[i]; if (colorsCount[i].count > dominantColorCount.count) dominantColorCount = colorsCount[i];
if (dominantColorCount.count > 0) SEGMENT.setPixelColorXY(x,y, dominantColorCount.color); //assign the dominant color // assign the dominant color w/ a bit of randomness to avoid "gliders"
if (dominantColorCount.count > 0 && random8(128)) SEGMENT.setPixelColorXY(x,y, dominantColorCount.color);
} }
// else do nothing! // else do nothing!
} //x,y } //x,y
@ -6721,7 +6706,7 @@ uint16_t mode_DJLight(void) { // Written by ??? Adapted by Wil
CRGB color = SEGMENT.getPixelColor(mid); CRGB color = SEGMENT.getPixelColor(mid);
SEGMENT.setPixelColor(mid, color.fadeToBlackBy(map(fftResult[1*4], 0, 255, 255, 10))); // TODO - Update SEGMENT.setPixelColor(mid, color.fadeToBlackBy(map(fftResult[1*4], 0, 255, 255, 10))); // TODO - Update
for (int i = SEGLEN - 1; i > mid; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); //move to the left for (int i = SEGLEN - 1; i > mid; i--) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i-1)); // move to the left
for (int i = 0; i < mid; i++) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1)); // move to the right for (int i = 0; i < mid; i++) SEGMENT.setPixelColor(i, SEGMENT.getPixelColor(i+1)); // move to the right
} }

View File

@ -143,7 +143,7 @@
#define FX_MODE_SAW 16 #define FX_MODE_SAW 16
#define FX_MODE_TWINKLE 17 #define FX_MODE_TWINKLE 17
#define FX_MODE_DISSOLVE 18 #define FX_MODE_DISSOLVE 18
#define FX_MODE_DISSOLVE_RANDOM 19 #define FX_MODE_DISSOLVE_RANDOM 19 // candidate for removal (use Dissolve with with check 3)
#define FX_MODE_SPARKLE 20 #define FX_MODE_SPARKLE 20
#define FX_MODE_FLASH_SPARKLE 21 #define FX_MODE_FLASH_SPARKLE 21
#define FX_MODE_HYPER_SPARKLE 22 #define FX_MODE_HYPER_SPARKLE 22
@ -227,7 +227,7 @@
#define FX_MODE_HEARTBEAT 100 #define FX_MODE_HEARTBEAT 100
#define FX_MODE_PACIFICA 101 #define FX_MODE_PACIFICA 101
#define FX_MODE_CANDLE_MULTI 102 #define FX_MODE_CANDLE_MULTI 102
#define FX_MODE_SOLID_GLITTER 103 #define FX_MODE_SOLID_GLITTER 103 // candidate for removal (use glitter)
#define FX_MODE_SUNRISE 104 #define FX_MODE_SUNRISE 104
#define FX_MODE_PHASED 105 #define FX_MODE_PHASED 105
#define FX_MODE_TWINKLEUP 106 #define FX_MODE_TWINKLEUP 106
@ -241,7 +241,7 @@
// #define FX_MODE_CANDY_CANE 114 // removed in 0.14! // #define FX_MODE_CANDY_CANE 114 // removed in 0.14!
#define FX_MODE_BLENDS 115 #define FX_MODE_BLENDS 115
#define FX_MODE_TV_SIMULATOR 116 #define FX_MODE_TV_SIMULATOR 116
#define FX_MODE_DYNAMIC_SMOOTH 117 #define FX_MODE_DYNAMIC_SMOOTH 117 // candidate for removal (check3 in dynamic)
// new 0.14 2D effects // new 0.14 2D effects
#define FX_MODE_2DSPACESHIPS 118 //gap fill #define FX_MODE_2DSPACESHIPS 118 //gap fill

View File

@ -893,7 +893,7 @@ void Segment::blur(uint8_t blur_amount)
* The colours are a transition r -> g -> b -> back to r * The colours are a transition r -> g -> b -> back to r
* Inspired by the Adafruit examples. * Inspired by the Adafruit examples.
*/ */
uint32_t Segment::color_wheel(uint8_t pos) { // TODO uint32_t Segment::color_wheel(uint8_t pos) {
if (palette) return color_from_palette(pos, false, true, 0); if (palette) return color_from_palette(pos, false, true, 0);
pos = 255 - pos; pos = 255 - pos;
if(pos < 85) { if(pos < 85) {