🤓 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;
} Raindrop;
// TODO: Use a dynamic vector instead
Raindrop raindrops[PANEL_WIDTH];
bool rain_initialized = false;
uint16_t color_highlight;
@ -72,7 +73,14 @@ void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
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;
if (overlay[pixel_num / 8] & (1 << (7 - (pixel_num % 8))) and mode != Stealth) {
if (mode == HighVis) {
@ -87,27 +95,27 @@ void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
} else {
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) {
if (mode == HighVis) {
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, color_highlight);
} else {
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(
COLOR_HIGHLIGHT_R * brightness,
COLOR_HIGHLIGHT_G * brightness,
COLOR_HIGHLIGHT_B * brightness
));
}
} else {
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0, fade_color, 0));
}
} else {
break;
}
}
//} 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) {
// if (mode == HighVis) {
// matrix->drawPixel(x, PANEL_HEIGHT + trail_y, color_highlight);
// } else {
// matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(
// COLOR_HIGHLIGHT_R * brightness,
// COLOR_HIGHLIGHT_G * brightness,
// COLOR_HIGHLIGHT_B * brightness
// ));
// }
// } else {
// matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0, fade_color, 0));
// }
// } else {
// break;
// }
//}
}
}
}