refactor colors

This commit is contained in:
Felix Pankratz 2024-12-11 10:21:43 +01:00
parent f002d724ed
commit 638f74b6c3

View File

@ -2,6 +2,14 @@
#include "constants.h"
#include "overlay.h"
#define COLOR_HIGHLIGHT_R 128
#define COLOR_HIGHLIGHT_G 255
#define COLOR_HIGHLIGHT_B 128
#define COLOR_DEFAULT_R 0
#define COLOR_DEFAULT_G 0
#define COLOR_DEFAULT_B 0
typedef struct {
bool reached_bottom = false;
int y;
@ -12,13 +20,25 @@ typedef struct {
Raindrop raindrops[PANEL_WIDTH];
bool rain_initialized = false;
uint16_t color_highlight;
uint16_t color_default;
void setup_rain() {
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
);
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();
raindrops[i].y = 0 - random(24);
raindrops[i].length = random(20, 28);
raindrops[i].speed = random(25, 100);
raindrops[i].last_moved = millis();
}
}
@ -45,20 +65,27 @@ void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
// draw our trail
for (int trail_offset = 1; trail_offset < raindrops[x].length; trail_offset++) {
int trail_y = raindrops[x].y - trail_offset;
float brightness = (raindrops[x].length - trail_offset);
uint16_t fade_color = matrix->color565(
COLOR_DEFAULT_R * brightness,
COLOR_DEFAULT_G * brightness,
COLOR_DEFAULT_B * brightness
);
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 (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));
matrix->drawPixel(x, trail_y, color_highlight);
} 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))
);
COLOR_HIGHLIGHT_R * brightness,
COLOR_HIGHLIGHT_G * brightness,
COLOR_HIGHLIGHT_B * brightness
));
}
} else {
matrix->drawPixel(x, trail_y, matrix->color565(0, (255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0));
matrix->drawPixel(x, trail_y, fade_color);
}
} else if (raindrops[x].reached_bottom) {
int pixel_num = ((PANEL_HEIGHT + trail_y) * PANEL_WIDTH) + x;
@ -66,16 +93,16 @@ void draw_rain(MatrixPanel_I2S_DMA *matrix, Mode mode) {
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));
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, color_highlight);
} 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))
);
COLOR_HIGHLIGHT_R * brightness,
COLOR_HIGHLIGHT_G * brightness,
COLOR_HIGHLIGHT_B * brightness
));
}
} else {
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0,(255 / raindrops[x].length) * (raindrops[x].length - trail_offset), 0));
matrix->drawPixel(x, PANEL_HEIGHT + trail_y, matrix->color565(0, fade_color, 0));
}
} else {
break;