Skip to content

Commit f528aef

Browse files
committed
GoL - Allows default overlay mode.
Flicker fixed by always redrawing dead cells if overlay unchecked. Can swap between overlay types by checking/unchecking overlayBG.
1 parent 9f1ea87 commit f528aef

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

wled00/FX.cpp

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5234,24 +5234,23 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
52345234
return FRAMETIME;
52355235
}
52365236

5237-
// Redraw if paused (remove blur), palette changed, or overlaying background (avoid flicker)
5237+
bool blurDead = SEGENV.step > strip.now && blur && !bgBlendMode && !overlayBG;
52385238
bool palChanged = SEGMENT.palette != *prevPalette && !allColors;
5239-
bool blurDead = SEGENV.step > strip.now && !bgBlendMode && !overlayBG;
5240-
if (palChanged || blurDead || overlayBG) {
5241-
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) {
5242-
cIndex = y * cols + x;
5243-
bool alive = getBitValue(cells, cIndex);
5244-
if (palChanged && alive) SEGMENT.setPixelColorXY(x,y, SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0));
5245-
else if (overlayBG & alive) {
5246-
color = SEGMENT.getPixelColorXY(x,y);
5247-
SEGMENT.setPixelColorXY(x,y, allColors ? RGBW32(color.r, color.g, color.b, 0) : color);
5248-
}
5249-
if (palChanged && !alive && !overlayBG) SEGMENT.setPixelColorXY(x,y, bgColor); // remove blurred cells from previous palette
5250-
else if (blurDead && !alive) SEGMENT.setPixelColorXY(x,y, blend(SEGMENT.getPixelColorXY(x,y), bgColor, blur));
5251-
}
5252-
if (palChanged) *prevPalette = SEGMENT.palette;
5253-
}
5239+
if (palChanged) *prevPalette = SEGMENT.palette;
52545240

5241+
// Redraw if paused (remove blur), palette changed, overlaying background (avoid flicker),
5242+
// always redraw dead cells if not overlaying background. Allows overlayFG by default.
5243+
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) {
5244+
cIndex = y * cols + x;
5245+
bool alive = getBitValue(cells, cIndex);
5246+
CRGB color = SEGMENT.getPixelColorXY(x,y);
5247+
if (palChanged && alive) SEGMENT.setPixelColorXY(x,y, SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0)); // Recolor alive cells
5248+
else if (overlayBG & alive) SEGMENT.setPixelColorXY(x,y, allColors ? RGBW32(color.r, color.g, color.b, 0) : color); // Redraw alive cells for overlayBG
5249+
if (palChanged && !alive && !overlayBG) SEGMENT.setPixelColorXY(x,y, bgColor); // Remove blurred cells from previous palette
5250+
else if (blurDead && !alive) SEGMENT.setPixelColorXY(x,y, blend(color, bgColor, blur)); // Blur dead cells (paused)
5251+
else if (!overlayBG && !alive) SEGMENT.setPixelColorXY(x,y, color); // Redraw dead cells for default overlayFG
5252+
}
5253+
52555254
if (SEGENV.step > strip.now || strip.now - SEGENV.step < 1000 / (uint32_t)map(SEGMENT.speed,0,255,1,64)) return FRAMETIME; //skip if not enough time has passed (1-64 updates/sec)
52565255

52575256
//Update Game of Life
@@ -5266,14 +5265,14 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
52665265
CRGB nColors[3]; // track 3 colors, dying cells may overwrite but this wont be used
52675266

52685267
for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) { // iterate through 3*3 matrix
5269-
if (i==0 && j==0) continue; // ignore itself
5268+
if (i == 0 && j == 0) continue; // ignore itself
52705269
if (!wrap || generation % 1500 == 0) { //no wrap, disable wrap every 1500 generations to prevent undetected repeats
5271-
cX = x+i;
5272-
cY = y+j;
5270+
cX = x + i;
5271+
cY = y + j;
52735272
if (cX < 0 || cY < 0 || cX >= cols || cY >= rows) continue; //skip if out of bounds
52745273
} else { //wrap around
5275-
cX = (x+i+cols) % cols;
5276-
cY = (y+j+rows) % rows;
5274+
cX = (x + i + cols) % cols;
5275+
cY = (y + j + rows) % rows;
52775276
}
52785277
cIndex = cY * cols + cX; //neighbor cell index
52795278
// count neighbors and store upto 3 neighbor colors
@@ -5341,7 +5340,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
53415340
SEGENV.step = strip.now;
53425341
return FRAMETIME;
53435342
} // mode_2Dgameoflife()
5344-
static const char _data_FX_MODE_2DGAMEOFLIFE[] PROGMEM = "Game Of Life@!,Color Mutation ☾,Blur ☾,,,All Colors ☾,Overlay BG ☾,Wrap ☾,;!,!;!;2;sx=82,ix=4,c1=48,o1=0,o2=0,o3=1";
5343+
static const char _data_FX_MODE_2DGAMEOFLIFE[] PROGMEM = "Game Of Life@!,Color Mutation ☾,Blur ☾,,,All Colors ☾,Overlay BG ☾,Wrap ☾,;!,!;!;2;sx=56,ix=2,c1=128,o1=0,o2=0,o3=1";
53455344

53465345
/////////////////////////
53475346
// 2D Hiphotic //

0 commit comments

Comments
 (0)