2024-12-17 12:29:01 +01:00
|
|
|
#include <Arduino.h>
|
|
|
|
#include <FastLED.h>
|
|
|
|
#include "constants.h"
|
2024-12-17 12:35:53 +01:00
|
|
|
#include "enums.h"
|
2024-12-17 12:29:01 +01:00
|
|
|
#include "supercomputer.h"
|
2024-12-17 15:12:09 +01:00
|
|
|
#include "overlay.h"
|
2024-12-17 12:29:01 +01:00
|
|
|
|
|
|
|
struct Cell {
|
|
|
|
float state;
|
|
|
|
float factor;
|
|
|
|
};
|
|
|
|
|
|
|
|
float cell_value(Cell c) {
|
|
|
|
return (1.0 + sin(c.state * c.factor)) * 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
Cell cells[PANEL_WIDTH * PANEL_HEIGHT];
|
|
|
|
bool cells_setup = false;
|
2024-12-17 14:56:57 +01:00
|
|
|
uint8_t rainbow_offset = 0;
|
2024-12-17 12:29:01 +01:00
|
|
|
|
|
|
|
void setup_cells() {
|
|
|
|
for(int i = 0; i < PANEL_WIDTH * PANEL_HEIGHT; i++) {
|
|
|
|
cells[i].state = random(100, 1000) / 100.0;
|
|
|
|
cells[i].factor = random(90, 110) / 100.0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-17 12:35:53 +01:00
|
|
|
void draw_supercomputer(MatrixPanel_I2S_DMA *matrix, Mode mode) {
|
2024-12-17 12:29:01 +01:00
|
|
|
if (!cells_setup) {
|
|
|
|
setup_cells();
|
|
|
|
cells_setup = true;
|
|
|
|
}
|
|
|
|
for(int i = 0; i < PANEL_WIDTH * PANEL_HEIGHT; i++) {
|
|
|
|
int x = i % PANEL_WIDTH;
|
2024-12-17 15:12:09 +01:00
|
|
|
int y = i / PANEL_WIDTH;
|
2024-12-17 12:35:53 +01:00
|
|
|
cells[i].state += 0.3;
|
|
|
|
if (mode == Stealth) {
|
|
|
|
// red only
|
2024-12-17 15:12:09 +01:00
|
|
|
matrix->drawPixel(x, y, matrix->color565((int)round(255.0 * cell_value(cells[i])), 0, 0));
|
2024-12-17 12:35:53 +01:00
|
|
|
} else {
|
|
|
|
// rainbow
|
|
|
|
float progress = (255.0 / PANEL_WIDTH) * x;
|
2024-12-17 14:56:57 +01:00
|
|
|
uint8_t hue = ((int)round(progress) + rainbow_offset);
|
2024-12-17 15:52:20 +01:00
|
|
|
if (overlay[i / 8] & (1 << (7 - (i % 8)))) {
|
2024-12-17 15:12:09 +01:00
|
|
|
hue -= 128;
|
2024-12-17 15:52:20 +01:00
|
|
|
} else if (mode == HighVis) {
|
|
|
|
continue;
|
2024-12-17 15:12:09 +01:00
|
|
|
}
|
2024-12-17 14:56:57 +01:00
|
|
|
CHSV hsv_color(hue, 255, 255 * cell_value(cells[i]));
|
2024-12-17 12:35:53 +01:00
|
|
|
CRGB rgb;
|
|
|
|
hsv2rgb_rainbow(hsv_color, rgb);
|
2024-12-17 15:12:09 +01:00
|
|
|
matrix->drawPixel(x, y, matrix->color565(rgb.r, rgb.g, rgb.b));
|
2024-12-17 12:35:53 +01:00
|
|
|
}
|
2024-12-17 12:29:01 +01:00
|
|
|
}
|
2024-12-17 15:52:20 +01:00
|
|
|
rainbow_offset++;
|
2024-12-28 16:26:14 +01:00
|
|
|
delay(25);
|
2024-12-17 12:29:01 +01:00
|
|
|
}
|