🤓 remove duplicated trail drawing logic

This commit is contained in:
Felix Pankratz 2024-12-11 14:16:46 +01:00
parent 638f74b6c3
commit 971b1cd042

View File

@ -18,6 +18,7 @@ typedef struct {
unsigned long last_moved; unsigned long last_moved;
} Raindrop; } Raindrop;
// TODO: Use a dynamic vector instead
Raindrop raindrops[PANEL_WIDTH]; Raindrop raindrops[PANEL_WIDTH];
bool rain_initialized = false; bool rain_initialized = false;
uint16_t color_highlight; uint16_t color_highlight;
@ -72,7 +73,14 @@ void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
COLOR_DEFAULT_B * brightness COLOR_DEFAULT_B * brightness
); );
if (trail_y >= 0) { if (trail_y < 0) {
if (not raindrops[x].reached_bottom) {
continue;
}
// we need to count from the bottom up
trail_y = PANEL_WIDTH + trail_y;
}
int pixel_num = (trail_y * PANEL_WIDTH) + x; int pixel_num = (trail_y * PANEL_WIDTH) + x;
if (overlay[pixel_num / 8] & (1 << (7 - (pixel_num % 8))) and mode != Stealth) { if (overlay[pixel_num / 8] & (1 << (7 - (pixel_num % 8))) and mode != Stealth) {
if (mode == HighVis) { if (mode == HighVis) {
@ -87,27 +95,27 @@ void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
} else { } else {
matrix->drawPixel(x, trail_y, fade_color); matrix->drawPixel(x, trail_y, fade_color);
} }
} else if (raindrops[x].reached_bottom) {
int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x;
if (raindrops[x].y >= 0) {
if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) and mode != Stealth) { //} else if (raindrops[x].reached_bottom) {
if (mode == HighVis) { // int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x;
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, color_highlight); // if (raindrops[x].y >= 0) {
} else { // if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) and mode != Stealth) {
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565( // if (mode == HighVis) {
COLOR_HIGHLIGHT_R * brightness, // matrix->drawPixel(x, PANEL_HEIGHT + trail_y, color_highlight);
COLOR_HIGHLIGHT_G * brightness, // } else {
COLOR_HIGHLIGHT_B * brightness // matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(
)); // COLOR_HIGHLIGHT_R * brightness,
} // COLOR_HIGHLIGHT_G * brightness,
} else { // COLOR_HIGHLIGHT_B * brightness
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0, fade_color, 0)); // ));
} // }
} else { // } else {
break; // matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0, fade_color, 0));
} // }
} // } else {
// break;
// }
//}
} }
} }
} }