41 lines
1.1 KiB
C++
41 lines
1.1 KiB
C++
|
#include <Arduino.h>
|
||
|
#include <FastLED.h>
|
||
|
#include "constants.h"
|
||
|
#include "supercomputer.h"
|
||
|
|
||
|
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;
|
||
|
|
||
|
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;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void draw_supercomputer(MatrixPanel_I2S_DMA *matrix) {
|
||
|
if (!cells_setup) {
|
||
|
setup_cells();
|
||
|
cells_setup = true;
|
||
|
}
|
||
|
for(int i = 0; i < PANEL_WIDTH * PANEL_HEIGHT; i++) {
|
||
|
cells[i].state += 0.3;
|
||
|
//matrix->drawPixel(i % PANEL_WIDTH, i / PANEL_WIDTH, matrix->color565((int)round(255.0 * cell_value(cells[i])), 0, 0));
|
||
|
int x = i % PANEL_WIDTH;
|
||
|
float progress = (255.0 / PANEL_WIDTH) * x;
|
||
|
CHSV hsv_color((int)round(progress), 255, 255 * cell_value(cells[i]));
|
||
|
CRGB rgb;
|
||
|
hsv2rgb_rainbow(hsv_color, rgb);
|
||
|
matrix->drawPixel(i % PANEL_WIDTH, i / PANEL_WIDTH, matrix->color565(rgb.r, rgb.g, rgb.b));
|
||
|
}
|
||
|
}
|