88 lines
3.2 KiB
C++
88 lines
3.2 KiB
C++
|
#include "rain.h"
|
||
|
#include "constants.h"
|
||
|
#include "overlay.h"
|
||
|
|
||
|
typedef struct {
|
||
|
bool reached_bottom = false;
|
||
|
int y;
|
||
|
int length;
|
||
|
int speed;
|
||
|
unsigned long last_moved;
|
||
|
} Raindrop;
|
||
|
|
||
|
Raindrop raindrops[PANEL_WIDTH];
|
||
|
bool rain_initialized = false;
|
||
|
|
||
|
void setup_rain() {
|
||
|
for (int i = 0; i<PANEL_WIDTH; i++) {
|
||
|
raindrops[i].y = 0 - random(24);
|
||
|
raindrops[i].length = random(20, 28);
|
||
|
raindrops[i].speed = random(25, 100);
|
||
|
raindrops[i].last_moved = millis();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
|
||
|
//matrix ->drawBitmap(0, 0, overlay, 64, 32, matrix->color565(64, 0, 0));
|
||
|
if (!rain_initialized) {
|
||
|
setup_rain();
|
||
|
rain_initialized = true;
|
||
|
}
|
||
|
unsigned long timestamp = millis();
|
||
|
for (int x = 0; x < PANEL_WIDTH; x++) {
|
||
|
if ((timestamp - raindrops[x].last_moved) > raindrops[x].speed) {
|
||
|
// step down a pixel
|
||
|
raindrops[x].y++;
|
||
|
raindrops[x].last_moved = timestamp;
|
||
|
}
|
||
|
if (raindrops[x].y > PANEL_HEIGHT) {
|
||
|
raindrops[x].y = 0;
|
||
|
raindrops[x].reached_bottom = true;
|
||
|
}
|
||
|
if (raindrops[x].y >= 0) {
|
||
|
//draw our pixel
|
||
|
matrix->drawPixel(x, raindrops[x].y, matrix->color565(128, 255, 128));
|
||
|
// draw our trail
|
||
|
for (int trail_offset = 1; trail_offset < raindrops[x].length; trail_offset++) {
|
||
|
int trail_y = raindrops[x].y - trail_offset;
|
||
|
if (trail_y >= 0) {
|
||
|
int pixel_num = (trail_y * PANEL_WIDTH) + x;
|
||
|
if (overlay[ pixel_num / 8 ] & (1 << (7 - (pixel_num % 8)) ) and mode != Stealth) {
|
||
|
if (mode == HighVis) {
|
||
|
matrix->drawPixel(x, trail_y, matrix->color565(128, 255, 128));
|
||
|
} else {
|
||
|
matrix->drawPixel(x, trail_y, matrix->color565(
|
||
|
(128 / raindrops[x].length) * (raindrops[x].length - trail_offset),
|
||
|
(255 / raindrops[x].length) * (raindrops[x].length - trail_offset),
|
||
|
(128 / raindrops[x].length) * (raindrops[x].length - trail_offset))
|
||
|
);
|
||
|
}
|
||
|
} else {
|
||
|
matrix->drawPixel(x, trail_y, matrix->color565(0, (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0));
|
||
|
}
|
||
|
} 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, matrix->color565(128, 255, 128));
|
||
|
} else {
|
||
|
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(
|
||
|
(128 / raindrops[x].length) * (raindrops[x].length - trail_offset),
|
||
|
(255 / raindrops[x].length) * (raindrops[x].length - trail_offset),
|
||
|
(128 / raindrops[x].length) * (raindrops[x].length - trail_offset))
|
||
|
);
|
||
|
}
|
||
|
} else {
|
||
|
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0,(255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0));
|
||
|
}
|
||
|
} else {
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|