Skip to content

Commit e8e784d

Browse files
committed
GoL CRGB changed to uint32 & color_blend()
Other small changes.
1 parent 3d12f0f commit e8e784d

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

wled00/FX.cpp

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5190,8 +5190,8 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
51905190
byte blur = map(SEGMENT.custom1, 0, 255, 255, 0);
51915191
bool bgBlendMode = SEGMENT.custom1 > 220 && !overlayBG; // if blur is high and not overlaying, use bg blend mode
51925192
byte bgBlur = map(SEGMENT.custom1 - 220, 0, 35, 255, 128);
5193-
CRGB bgColor = SEGCOLOR(1);
5194-
CRGB color = allColors ? random16() * random16() : SEGMENT.color_from_palette(0, false, PALETTE_SOLID_WRAP, 0);
5193+
uint32_t bgColor = SEGCOLOR(1);
5194+
uint32_t color = allColors ? random16() * random16() : SEGMENT.color_from_palette(0, false, PALETTE_SOLID_WRAP, 0);
51955195
uint16_t cIndex;
51965196

51975197
if (SEGENV.call == 0) {
@@ -5213,7 +5213,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
52135213
color = SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0);
52145214
SEGMENT.setPixelColorXY(x,y, allColors ? random16() * random16() : color);
52155215
}
5216-
else if (!overlayBG) SEGMENT.setPixelColorXY(x,y, allColors ? RGBW32(bgColor.r, bgColor.g, bgColor.b, 0) : bgColor); // set background color if not overlaying
5216+
else if (!overlayBG) SEGMENT.setPixelColorXY(x,y, bgColor); // set background color if not overlaying
52175217
}
52185218
memcpy(futureCells, cells, dataSize);
52195219

@@ -5234,7 +5234,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
52345234
return FRAMETIME;
52355235
}
52365236

5237-
int aliveCount = 0; // Solo glider detection
5237+
int aliveCount = 0; // Solo glider detection
52385238
bool blurDead = SEGENV.step > strip.now && blur && !bgBlendMode && !overlayBG;
52395239
bool palChanged = SEGMENT.palette != *prevPalette && !allColors;
52405240
if (palChanged) *prevPalette = SEGMENT.palette;
@@ -5245,12 +5245,12 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
52455245
cIndex = y * cols + x;
52465246
bool alive = getBitValue(cells, cIndex);
52475247
if (alive) aliveCount++;
5248-
CRGB color = SEGMENT.getPixelColorXY(x,y);
5249-
if (palChanged && alive) SEGMENT.setPixelColorXY(x,y, SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0)); // Recolor alive cells
5250-
else if (overlayBG & alive) SEGMENT.setPixelColorXY(x,y, allColors ? RGBW32(color.r, color.g, color.b, 0) : color); // Redraw alive cells for overlayBG
5251-
if (palChanged && !alive && !overlayBG) SEGMENT.setPixelColorXY(x,y, bgColor); // Remove blurred cells from previous palette
5252-
else if (blurDead && !alive) SEGMENT.setPixelColorXY(x,y, blend(color, bgColor, blur)); // Blur dead cells (paused)
5253-
else if (!overlayBG && !alive) SEGMENT.setPixelColorXY(x,y, color); // Redraw dead cells for default overlayFG
5248+
uint32_t cellColor = SEGMENT.getPixelColorXY(x,y);
5249+
if ( alive && palChanged) SEGMENT.setPixelColorXY(x,y, SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0)); // Recolor alive cells
5250+
else if ( alive && overlayBG) SEGMENT.setPixelColorXY(x,y, cellColor); // Redraw alive cells for overlayBG
5251+
if (!alive && palChanged && !overlayBG) SEGMENT.setPixelColorXY(x,y, bgColor); // Remove blurred cells from previous palette
5252+
else if (!alive && blurDead) SEGMENT.setPixelColorXY(x,y, color_blend(cellColor, bgColor, blur)); // Blur dead cells (paused)
5253+
else if (!alive && !overlayBG) SEGMENT.setPixelColorXY(x,y, cellColor); // Redraw dead cells for default overlayFG
52545254
}
52555255

52565256
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)
@@ -5264,7 +5264,7 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
52645264
for (int x = 0; x < cols; x++) for (int y = 0; y < rows; y++) {
52655265
byte neighbors = 0;
52665266
byte colorCount = 0; //track number of valid colors
5267-
CRGB nColors[3]; // track 3 colors, dying cells may overwrite but this wont be used
5267+
uint32_t nColors[3]; // track 3 colors, dying cells may overwrite but this wont be used
52685268

52695269
for (int i = -1; i <= 1; i++) for (int j = -1; j <= 1; j++) { // iterate through 3*3 matrix
52705270
if (i == 0 && j == 0) continue; // ignore itself
@@ -5295,29 +5295,28 @@ uint16_t mode_2Dgameoflife(void) { // Written by Ewoud Wijma, inspired by https:
52955295
cellChanged = true;
52965296
setBitValue(futureCells, cIndex, false);
52975297
// Blur/turn off dying cells
5298-
if (!overlayBG) SEGMENT.setPixelColorXY(x,y, blend(SEGMENT.getPixelColorXY(x,y), bgColor, bgBlendMode ? bgBlur : blur));
5298+
if (!overlayBG) SEGMENT.setPixelColorXY(x,y, color_blend(SEGMENT.getPixelColorXY(x,y), bgColor, bgBlendMode ? bgBlur : blur));
52995299
}
53005300
else if (!(cellValue) && (neighbors == 3)) {
53015301
// Reproduction
53025302
setBitValue(futureCells, cIndex, true);
53035303
cellChanged = true;
53045304
// find dominant color and assign it to a new born cell no longer storing colors, if parent dies the color is lost
5305-
CRGB dominantColor;
5305+
uint32_t dominantColor;
53065306
if (colorCount == 3) { //All parents survived
53075307
if ((nColors[0] == nColors[1]) || (nColors[0] == nColors[2])) dominantColor = nColors[0];
53085308
else if (nColors[1] == nColors[2]) dominantColor = nColors[1];
53095309
else dominantColor = nColors[random8(3)];
53105310
}
53115311
else if (colorCount == 2) dominantColor = nColors[random8(2)]; // 1 leading parent died
53125312
else if (colorCount == 1) dominantColor = nColors[0]; // 2 leading parents died
5313-
else dominantColor = color; // all parents died last used color
5313+
else dominantColor = color; // all parents died use last seen color
53145314
// mutate color chance
5315-
if (allColors) dominantColor = RGBW32(dominantColor.r, dominantColor.g, dominantColor.b, 0); //WLEDMM support all colors
53165315
if (random8() < SEGMENT.intensity || dominantColor == bgColor) dominantColor = allColors ? random16() * random16() : SEGMENT.color_from_palette(random8(), false, PALETTE_SOLID_WRAP, 0);
53175316
SEGMENT.setPixelColorXY(x,y, dominantColor);
53185317
}
53195318
else { // blur dead cells
5320-
if (!cellValue && !overlayBG && !bgBlendMode) SEGMENT.setPixelColorXY(x,y, blend(SEGMENT.getPixelColorXY(x,y), bgColor, bgBlendMode ? bgBlur : blur));
5319+
if (!cellValue && !overlayBG && !bgBlendMode) SEGMENT.setPixelColorXY(x,y, color_blend(SEGMENT.getPixelColorXY(x,y), bgColor, bgBlendMode ? bgBlur : blur));
53215320
}
53225321
}
53235322
//update cell values

0 commit comments

Comments
 (0)