Skip to content

Commit 9ef8ff6

Browse files
committed
GoL - Redraw loop changes
Merged generation == 1 checks into standard checks.
1 parent 086b0e3 commit 9ef8ff6

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

wled00/FX.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5210,7 +5210,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
52105210
cIndex = y * cols + x;
52115211
if (random8(100) < 32) { // ~32% chance of being alive
52125212
setBitValue(cells, cIndex, true);
5213-
SEGMENT.setPixelColorXY(x,y, bgColor); // Initial color set in redraw loop
5213+
if (!overlayBG) SEGMENT.setPixelColorXY(x,y, bgColor); // Initial color set in redraw loop
52145214
}
52155215
}
52165216
memcpy(futureCells, cells, dataSize);
@@ -5236,27 +5236,27 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
52365236
bool palChanged = SEGMENT.palette != *prevPalette && !allColors;
52375237
if (palChanged) *prevPalette = SEGMENT.palette;
52385238

5239-
// Redraw if paused (remove blur), palette changed, overlaying background (avoid flicker),
5240-
// always redraw dead cells if not overlaying background. Allows overlayFG by default.
5239+
// Redraw Loop
5240+
// Redraw if paused (remove blur), palette changed, overlaying background (avoid flicker)
5241+
// Always redraw dead cells if not overlaying background. Allows overlayFG by default.
5242+
// Generation 1 draws alive cells randomly and fades dead cells
52415243
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) {
52425244
cIndex = y * cols + x;
52435245
bool alive = getBitValue(cells, cIndex);
52445246
if (alive) aliveCount++;
52455247
uint32_t cellColor = SEGMENT.getPixelColorXY(x,y);
5246-
if (generation == 1) {// Spawn initial colors randomly
5247-
bool aliveBgColor = (alive && cellColor == bgColor);
5248-
if (aliveBgColor && !random(12)) SEGMENT.setPixelColorXY(x,y, allColors ? random16() * random16() : SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0)); // Color alive cell
5249-
else if (alive && !aliveBgColor) SEGMENT.setPixelColorXY(x,y, cellColor); // Redraw alive cells
5250-
else if (!alive && !overlayBG && !bgBlendMode) SEGMENT.setPixelColorXY(x,y, bgColor); // Redraw dead cells for default overlayFG
5251-
else if (!alive && !overlayBG) SEGMENT.setPixelColorXY(x,y, color_blend(cellColor, bgColor, 16)); // Fade dead cells (bgBlendMode)
5252-
continue;
5253-
}
5254-
5255-
if ( alive && palChanged) SEGMENT.setPixelColorXY(x,y, SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0)); // Recolor alive cells
5256-
else if ( alive && overlayBG) SEGMENT.setPixelColorXY(x,y, cellColor); // Redraw alive cells for overlayBG
5257-
if (!alive && palChanged && !overlayBG) SEGMENT.setPixelColorXY(x,y, bgColor); // Remove blurred cells from previous palette
5258-
else if (!alive && blurDead) SEGMENT.setPixelColorXY(x,y, color_blend(cellColor, bgColor, blur)); // Blur dead cells (paused)
5259-
else if (!alive && !overlayBG) SEGMENT.setPixelColorXY(x,y, cellColor); // Redraw dead cells for default overlayFG
5248+
bool aliveBgColor = (alive && !overlayBG && generation == 1 && cellColor == bgColor);
5249+
5250+
if ( alive && (palChanged || (aliveBgColor && !random(12)))) { // Palette change or spawn initial colors randomly
5251+
uint32_t randomColor = allColors ? random16() * random16() : SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0);
5252+
SEGMENT.setPixelColorXY(x,y, randomColor); // Recolor alive cells
5253+
aliveBgColor = false;
5254+
}
5255+
else if ( alive && overlayBG) SEGMENT.setPixelColorXY(x,y, cellColor); // Redraw alive cells for overlayBG
5256+
if (!alive && palChanged && !overlayBG) SEGMENT.setPixelColorXY(x,y, bgColor); // Remove blurred cells from previous palette
5257+
else if (!alive && blurDead) SEGMENT.setPixelColorXY(x,y, color_blend(cellColor, bgColor, blur));// Blur dead cells (paused)
5258+
else if ((!alive || aliveBgColor) && !overlayBG && !bgBlendMode) SEGMENT.setPixelColorXY(x,y, cellColor); // Redraw dead cells/alive off cells for default overlayFG
5259+
else if (!alive && !overlayBG && generation == 1) SEGMENT.setPixelColorXY(x,y, color_blend(cellColor, bgColor, 16)); // Fade dead cells (bgBlendMode) on generation 1
52605260
}
52615261

52625262
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)

0 commit comments

Comments
 (0)