#include <FastLED.h>
#define LED_PIN 3
#define COLOR_ORDER GRB
#define CHIPSET WS2812B
#define pWIDTH 24
#define pHEIGHT 24
#define NUM_LEDS ((pWIDTH) * (pHEIGHT))
#define pHalfWidth (pWIDTH / 2)
#define pHalfHeight (pHEIGHT / 2)
CRGB leds[NUM_LEDS];
struct {
float angle;
float radius;
}
rfMap[pWIDTH][pHEIGHT];
uint16_t getPixelNumber(uint8_t x, uint8_t y) {
if (x >= pWIDTH || y >= pHEIGHT)
return NUM_LEDS;
if (y & 1)
x = pWIDTH - 1 - x;
return x + (y * pWIDTH);
}
uint16_t XY(uint8_t x, uint8_t y) {
return getPixelNumber(x, y);
}
void setup() {
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(UncorrectedColor);
for (int8_t x = -pHalfWidth; x < pHalfWidth; x++) {
for (int8_t y = -pHalfHeight; y < pHalfHeight; y++) {
rfMap[x + pHalfWidth][y + pHalfHeight].angle = atan2(y, x) * (360. / 2. / PI) * pHalfWidth;
rfMap[x + pHalfWidth][y + pHalfHeight].radius = hypotf(y, x);
}
}
}
void loop() {
drawFrame();
FastLED.show();
}
void drawFrame() {
uint8_t effectBrightness = 255;
static byte scale = 100; // slider 1 ... 100
static byte speed = 48; // slider 8 ... 64
static uint32_t t;
t += speed;
fadeToBlackBy(leds, NUM_LEDS, 5);
for (uint8_t x = 0; x < pWIDTH; x++) {
for (uint8_t y = 0; y < pHEIGHT; y++) {
float angle = rfMap[x][y].angle;
float radius = rfMap[x][y].radius;
int16_t Bri = inoise8(angle, radius * scale - t) - radius * pHEIGHT/4;
if (Bri < 0) Bri = 0; if(Bri != 0) Bri = 256 - (Bri * .4);
int16_t Col = inoise8(angle, radius * scale - t) - radius * pHEIGHT/4;
if (Col < 0) Col = 0;
int16_t idx = XY(x, y);
if (idx >= 0 && idx < NUM_LEDS) nblend(leds[idx], ColorFromPalette(HeatColors_p, Col, map8(Bri,0,effectBrightness)), speed);
}
}
}