2024-12-08 15:11:55 +01:00
|
|
|
#include "rain.h"
|
|
|
|
#include "constants.h"
|
|
|
|
#include "overlay.h"
|
2024-12-13 19:22:44 +01:00
|
|
|
#include <vector>
|
2024-12-08 15:11:55 +01:00
|
|
|
|
2024-12-11 10:21:43 +01:00
|
|
|
#define COLOR_HIGHLIGHT_R 128
|
|
|
|
#define COLOR_HIGHLIGHT_G 255
|
|
|
|
#define COLOR_HIGHLIGHT_B 128
|
|
|
|
|
|
|
|
#define COLOR_DEFAULT_R 0
|
2024-12-11 14:42:15 +01:00
|
|
|
#define COLOR_DEFAULT_G 255
|
2024-12-11 10:21:43 +01:00
|
|
|
#define COLOR_DEFAULT_B 0
|
|
|
|
|
2024-12-13 19:22:44 +01:00
|
|
|
//typedef struct {
|
|
|
|
struct Raindrop {
|
|
|
|
//bool reached_bottom = false;
|
|
|
|
bool reached_bottom;
|
|
|
|
int x;
|
2024-12-08 15:11:55 +01:00
|
|
|
int y;
|
|
|
|
int length;
|
|
|
|
int speed;
|
|
|
|
unsigned long last_moved;
|
2024-12-13 19:22:44 +01:00
|
|
|
} ;
|
2024-12-08 15:11:55 +01:00
|
|
|
|
|
|
|
bool rain_initialized = false;
|
2024-12-11 10:21:43 +01:00
|
|
|
uint16_t color_highlight;
|
|
|
|
uint16_t color_default;
|
2024-12-13 19:22:44 +01:00
|
|
|
std::vector<Raindrop> raindrops;
|
2024-12-08 15:11:55 +01:00
|
|
|
|
2024-12-13 18:26:57 +01:00
|
|
|
void setup_rain(MatrixPanel_I2S_DMA *matrix) {
|
2024-12-11 10:21:43 +01:00
|
|
|
color_highlight = matrix->color565(
|
|
|
|
COLOR_HIGHLIGHT_R,
|
|
|
|
COLOR_HIGHLIGHT_G,
|
|
|
|
COLOR_HIGHLIGHT_B
|
|
|
|
);
|
|
|
|
color_default = matrix->color565(
|
|
|
|
COLOR_DEFAULT_R,
|
|
|
|
COLOR_DEFAULT_B,
|
|
|
|
COLOR_DEFAULT_G
|
|
|
|
);
|
2024-12-13 19:22:44 +01:00
|
|
|
for (int x = 0; x<PANEL_WIDTH; x++) {
|
|
|
|
raindrops.push_back({
|
|
|
|
false,
|
|
|
|
x,
|
|
|
|
0 - random(24),
|
|
|
|
random(20, 28),
|
|
|
|
random(25, 100),
|
|
|
|
millis()
|
|
|
|
});
|
2024-12-08 15:11:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
|
|
|
|
//matrix ->drawBitmap(0, 0, overlay, 64, 32, matrix->color565(64, 0, 0));
|
|
|
|
if (!rain_initialized) {
|
2024-12-13 18:26:57 +01:00
|
|
|
setup_rain(matrix);
|
2024-12-08 15:11:55 +01:00
|
|
|
rain_initialized = true;
|
|
|
|
}
|
|
|
|
unsigned long timestamp = millis();
|
2024-12-15 15:58:13 +01:00
|
|
|
int r = 0;
|
|
|
|
while(r < raindrops.size()) {
|
|
|
|
if ((timestamp - raindrops[r].last_moved) > raindrops[r].speed) {
|
2024-12-08 15:11:55 +01:00
|
|
|
// step down a pixel
|
2024-12-15 15:58:13 +01:00
|
|
|
raindrops[r].y++;
|
|
|
|
raindrops[r].last_moved = timestamp;
|
2024-12-08 15:11:55 +01:00
|
|
|
}
|
2024-12-15 15:58:13 +01:00
|
|
|
if (raindrops[r].y > PANEL_HEIGHT + raindrops[r].length) {
|
2024-12-13 19:22:44 +01:00
|
|
|
raindrops.push_back({
|
|
|
|
false,
|
2024-12-15 15:58:13 +01:00
|
|
|
raindrops[r].x,
|
2024-12-27 13:35:44 +01:00
|
|
|
0 - random(4),
|
2024-12-13 19:22:44 +01:00
|
|
|
random(20, 28),
|
2024-12-28 16:26:14 +01:00
|
|
|
random(10, 55),
|
2024-12-13 19:22:44 +01:00
|
|
|
millis()
|
|
|
|
});
|
2024-12-15 15:58:13 +01:00
|
|
|
raindrops.erase(raindrops.begin() + r);
|
2024-12-13 19:22:44 +01:00
|
|
|
continue;
|
|
|
|
}
|
2024-12-15 15:58:13 +01:00
|
|
|
if (raindrops[r].y >= 0) {
|
2024-12-08 15:11:55 +01:00
|
|
|
//draw our pixel
|
2024-12-15 15:58:13 +01:00
|
|
|
matrix->drawPixel(raindrops[r].x, raindrops[r].y, matrix->color565(128, 255, 128));
|
2024-12-08 15:11:55 +01:00
|
|
|
// draw our trail
|
2024-12-15 15:58:13 +01:00
|
|
|
for (int trail_offset = 1; trail_offset < raindrops[r].length; trail_offset++) {
|
|
|
|
int trail_y = raindrops[r].y - trail_offset;
|
|
|
|
float brightness = ((raindrops[r].length - trail_offset) / (float)raindrops[r].length);
|
2024-12-11 10:21:43 +01:00
|
|
|
uint16_t fade_color = matrix->color565(
|
|
|
|
COLOR_DEFAULT_R * brightness,
|
|
|
|
COLOR_DEFAULT_G * brightness,
|
|
|
|
COLOR_DEFAULT_B * brightness
|
|
|
|
);
|
|
|
|
|
2024-12-11 14:16:46 +01:00
|
|
|
if (trail_y < 0) {
|
2024-12-13 19:22:44 +01:00
|
|
|
break;
|
2024-12-11 14:16:46 +01:00
|
|
|
}
|
2024-12-08 15:11:55 +01:00
|
|
|
|
2024-12-15 15:58:13 +01:00
|
|
|
int pixel_num = (trail_y * PANEL_WIDTH) + raindrops[r].x;
|
2024-12-11 14:16:46 +01:00
|
|
|
if (overlay[pixel_num / 8] & (1 << (7 - (pixel_num % 8))) and mode != Stealth) {
|
|
|
|
if (mode == HighVis) {
|
2024-12-15 15:58:13 +01:00
|
|
|
matrix->drawPixel(raindrops[r].x, trail_y, color_highlight);
|
2024-12-08 15:11:55 +01:00
|
|
|
} else {
|
2024-12-15 15:58:13 +01:00
|
|
|
matrix->drawPixel(raindrops[r].x, trail_y, matrix->color565(
|
2024-12-11 14:16:46 +01:00
|
|
|
COLOR_HIGHLIGHT_R * brightness,
|
|
|
|
COLOR_HIGHLIGHT_G * brightness,
|
|
|
|
COLOR_HIGHLIGHT_B * brightness
|
|
|
|
));
|
2024-12-08 15:11:55 +01:00
|
|
|
}
|
2024-12-11 14:16:46 +01:00
|
|
|
} else {
|
2024-12-15 15:58:13 +01:00
|
|
|
matrix->drawPixel(raindrops[r].x, trail_y, fade_color);
|
2024-12-08 15:11:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-12-15 15:58:13 +01:00
|
|
|
r++;
|
2024-12-08 15:11:55 +01:00
|
|
|
}
|
2024-12-28 16:26:14 +01:00
|
|
|
//delay(25);
|
2024-12-08 15:11:55 +01:00
|
|
|
}
|