- Ohne Angabe Tempo und Farbe (66 Effekte); Musik: Empfindlichkeit und Farbe; Feuer: Hitze und Farbe; Gewitter, Regen, Schnee, Weihnachtsbaum, Geschenk, Fraktalwolken: zweiter Regler Tempo - Eigene Regler 2: Blitzlicht/Blaulicht Nachleuchten (kein Tempo, damit sie nicht schneller blitzen), Lampe Weiß (weißer oder satter) - Tempo, Farbe und Empfindlichkeit wirken, egal auf welchem Regler - API: param2 in /api/state und /api/effects; gespeichert als id=w1:w2 (alte Form id=w1 wird weiter gelesen) - App: zweiter Regler, Spezialeffekt-Knöpfe etwas flacher, damit alles ohne Scrollen passt Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
273 lines
9.0 KiB
C++
273 lines
9.0 KiB
C++
// Kategorie Flash: schnelle, kräftige Effekte
|
||
// (dazu Würfel im Würfel, Matrix und Flummis aus effects.cpp)
|
||
|
||
#include "fx.h"
|
||
|
||
// --- Blitzlicht: Würfel, Etage oder Ebene blitzt in wechselnden Farben ----------
|
||
// Höchstens 2,5 Blitze pro Sekunde.
|
||
|
||
void renderStrobe(uint32_t now) {
|
||
static uint32_t next = 0;
|
||
static uint8_t hue = 0;
|
||
if (fresh) {
|
||
fresh = false;
|
||
next = now;
|
||
}
|
||
fadeToBlackBy(leds, NUM_LEDS, max(3, 80 - fxParam2 * 5 / 16)); // Regler 2: Nachleuchten
|
||
if (int32_t(now - next) < 0) return;
|
||
next = now + 400;
|
||
hue += 47 + random8(40);
|
||
uint8_t kind = random8(3), pos = random8(CUBE_SIZE);
|
||
CRGB c = CHSV(hue, 255, kind == 0 ? min(255, brightness * 3) : highlight);
|
||
FOR_XYZ {
|
||
if (kind == 0 || (kind == 1 && z == pos) || (kind == 2 && x == pos)) at(x, y, z) = c;
|
||
}
|
||
}
|
||
|
||
// --- Scanner: eine Ebene fegt hin und her, jedes Mal entlang einer anderen Achse --
|
||
|
||
void renderScanner(uint32_t now) {
|
||
const uint16_t SWEEP = 900; // ms für einmal durch
|
||
uint32_t t = now - fxStart, n = t / SWEEP;
|
||
float f = (t % SWEEP) / float(SWEEP);
|
||
float pos = (n & 1 ? 1 - f : f) * TOP;
|
||
uint8_t axis = (n / 2) % 3;
|
||
CRGB c = CHSV(n * 40, 255, highlight);
|
||
fadeToBlackBy(leds, NUM_LEDS, 70);
|
||
FOR_XYZ {
|
||
float d = fabsf((axis == 0 ? x : axis == 1 ? y : z) - pos);
|
||
if (d < 1) at(x, y, z) += CRGB(c).nscale8(uint8_t((1 - d) * 255));
|
||
}
|
||
}
|
||
|
||
// --- Kometen: fliegen von einer Seite quer durch, mit Schweif --------------------
|
||
|
||
struct Comet {
|
||
bool active;
|
||
float p[3], v[3];
|
||
uint8_t hue;
|
||
};
|
||
static Comet comets[4];
|
||
|
||
void renderComets(uint32_t now) {
|
||
if (fresh) {
|
||
fresh = false;
|
||
for (Comet &c : comets) c.active = false;
|
||
}
|
||
fadeToBlackBy(leds, NUM_LEDS, 45);
|
||
for (Comet &c : comets) {
|
||
if (!c.active) {
|
||
if (random8() < 8) { // Start auf einer zufälligen Seitenfläche
|
||
uint8_t axis = random8(3);
|
||
bool back = random8(2);
|
||
for (uint8_t i = 0; i < 3; i++) {
|
||
c.p[i] = rnd(0, TOP);
|
||
c.v[i] = rnd(-0.03f, 0.03f);
|
||
}
|
||
c.p[axis] = back ? TOP + 0.4f : -0.4f;
|
||
c.v[axis] = (back ? -1 : 1) * rnd(0.12f, 0.2f);
|
||
c.hue = random8();
|
||
c.active = true;
|
||
}
|
||
continue;
|
||
}
|
||
for (uint8_t i = 0; i < 3; i++) {
|
||
c.p[i] += c.v[i];
|
||
if (c.p[i] < -0.6f || c.p[i] > TOP + 0.6f) c.active = false;
|
||
}
|
||
if (c.active) plot(c.p[0], c.p[1], c.p[2], CHSV(c.hue, 180, highlight));
|
||
}
|
||
}
|
||
|
||
// --- Schlange: kriecht durch den Würfel und weicht sich selbst aus ---------------
|
||
|
||
const uint8_t SNAKE_LEN = 8;
|
||
static int8_t snake[SNAKE_LEN][3];
|
||
static uint8_t snakeLen;
|
||
static int8_t snakeDir[3];
|
||
|
||
static bool inSnake(int x, int y, int z) {
|
||
for (uint8_t i = 0; i + 1 < snakeLen; i++) // das Schwanzende rückt gleich weiter
|
||
if (snake[i][0] == x && snake[i][1] == y && snake[i][2] == z) return true;
|
||
return false;
|
||
}
|
||
|
||
void renderSnake(uint32_t now) {
|
||
static uint32_t last = 0;
|
||
static uint8_t hue = 0;
|
||
static const int8_t DIRS[6][3] = {{1, 0, 0}, {-1, 0, 0}, {0, 1, 0}, {0, -1, 0}, {0, 0, 1}, {0, 0, -1}};
|
||
if (fresh) {
|
||
fresh = false;
|
||
snake[0][0] = snake[0][1] = snake[0][2] = 2;
|
||
snakeLen = 1;
|
||
memcpy(snakeDir, DIRS[0], 3);
|
||
last = now;
|
||
}
|
||
if (now - last >= 110) {
|
||
last = now;
|
||
hue += 3;
|
||
bool moved = false;
|
||
for (uint8_t attempt = 0; attempt < 16 && !moved; attempt++) {
|
||
// meist geradeaus, sonst eine zufällige Richtung
|
||
const int8_t *d = attempt == 0 && random8() < 170 ? snakeDir : DIRS[random8(6)];
|
||
int nx = snake[0][0] + d[0], ny = snake[0][1] + d[1], nz = snake[0][2] + d[2];
|
||
if (!inCube(nx, ny, nz) || inSnake(nx, ny, nz)) continue;
|
||
int8_t dir[3] = {d[0], d[1], d[2]};
|
||
memcpy(snakeDir, dir, 3);
|
||
memmove(snake[1], snake[0], sizeof(snake[0]) * (SNAKE_LEN - 1));
|
||
snake[0][0] = nx;
|
||
snake[0][1] = ny;
|
||
snake[0][2] = nz;
|
||
if (snakeLen < SNAKE_LEN) snakeLen++;
|
||
moved = true;
|
||
}
|
||
if (!moved) snakeLen = 1; // festgefahren: Schwanz abwerfen
|
||
}
|
||
FastLED.clear();
|
||
for (uint8_t i = 0; i < snakeLen; i++)
|
||
at(snake[i][0], snake[i][1], snake[i][2]) = CHSV(hue + i * 12, 255, scale8(highlight, 255 - i * 28));
|
||
}
|
||
|
||
// --- Rotor: eine senkrechte Ebene dreht sich schnell um die Mitte ---------------
|
||
|
||
void renderRotor(uint32_t now) {
|
||
float a = (now - fxStart) * 0.0042f; // eine halbe Umdrehung in 0,75 s
|
||
float s = sinf(a), c = cosf(a);
|
||
FastLED.clear();
|
||
FOR_XYZ {
|
||
float dx = x - MID, dy = y - MID;
|
||
float f = 1 - fabsf(c * dy - s * dx); // Abstand von der Ebene
|
||
if (f > 0) at(x, y, z) = CHSV(uint8_t(now / 20) + z * 20 + wrap8((c * dx + s * dy) * 25), 255, uint8_t(f * highlight));
|
||
}
|
||
}
|
||
|
||
// --- Stapeln: Würfel fallen, volle Etagen blitzen auf und verschwinden ----------
|
||
|
||
static uint8_t stack[CUBE_SIZE][CUBE_SIZE][NUM_LAYERS]; // 0 = leer, sonst Farbton + 1
|
||
|
||
struct Piece {
|
||
bool active;
|
||
uint8_t x, y, z, hue;
|
||
};
|
||
|
||
void renderStack(uint32_t now) {
|
||
static Piece piece;
|
||
static uint32_t lastStep = 0, flashUntil = 0;
|
||
static int8_t flashZ = -1; // Etage, die gerade aufblitzt
|
||
static uint8_t hue = 0;
|
||
if (fresh) {
|
||
fresh = false;
|
||
memset(stack, 0, sizeof(stack));
|
||
piece.active = false;
|
||
flashZ = -1;
|
||
}
|
||
|
||
if (flashZ >= 0 && int32_t(now - flashUntil) >= 0) { // volle Etage entfernen
|
||
for (uint8_t y = 0; y < CUBE_SIZE; y++)
|
||
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
|
||
for (uint8_t z = flashZ; z < TOP; z++) stack[x][y][z] = stack[x][y][z + 1];
|
||
stack[x][y][TOP] = 0;
|
||
}
|
||
flashZ = -1;
|
||
}
|
||
|
||
if (flashZ < 0 && !piece.active) {
|
||
// meist in eine der niedrigsten Säulen, damit sich Etagen füllen
|
||
uint8_t best = NUM_LAYERS, n = 0, cx = 0, cy = 0;
|
||
bool lowest = random8() < 180;
|
||
for (uint8_t y = 0; y < CUBE_SIZE; y++)
|
||
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
|
||
uint8_t h = 0;
|
||
while (h < NUM_LAYERS && stack[x][y][h]) h++;
|
||
if (h == NUM_LAYERS) continue;
|
||
uint8_t key = lowest ? h : 0;
|
||
if (key < best) { best = key; n = 0; }
|
||
if (key == best && random8(++n) == 0) { cx = x; cy = y; }
|
||
}
|
||
if (best == NUM_LAYERS) memset(stack, 0, sizeof(stack)); // alles voll: neu anfangen
|
||
else piece = {true, cx, cy, TOP, hue += 23};
|
||
lastStep = now;
|
||
}
|
||
|
||
if (piece.active && now - lastStep >= 50) {
|
||
lastStep = now;
|
||
if (piece.z > 0 && !stack[piece.x][piece.y][piece.z - 1]) piece.z--;
|
||
else { // gelandet
|
||
stack[piece.x][piece.y][piece.z] = piece.hue + 1;
|
||
piece.active = false;
|
||
bool full = true;
|
||
for (uint8_t y = 0; y < CUBE_SIZE; y++)
|
||
for (uint8_t x = 0; x < CUBE_SIZE; x++) full &= stack[x][y][piece.z] != 0;
|
||
if (full) {
|
||
flashZ = piece.z;
|
||
flashUntil = now + 300;
|
||
}
|
||
}
|
||
}
|
||
|
||
FastLED.clear();
|
||
FOR_XYZ {
|
||
if (z == flashZ) at(x, y, z) = CRGB(highlight, highlight, highlight);
|
||
else if (stack[x][y][z]) at(x, y, z) = CHSV(stack[x][y][z] - 1, 255, min(255, brightness * 2));
|
||
}
|
||
if (piece.active) at(piece.x, piece.y, piece.z) = CHSV(piece.hue, 200, highlight);
|
||
}
|
||
|
||
// --- Blaulicht: links blau, rechts rot, jeweils Doppelblitz ----------------------
|
||
|
||
void renderPolice(uint32_t now) {
|
||
uint16_t t = (now - fxStart) % 1200;
|
||
bool blue = t < 80 || (t >= 160 && t < 240);
|
||
bool red = (t >= 600 && t < 680) || (t >= 760 && t < 840);
|
||
fadeToBlackBy(leds, NUM_LEDS, max(4, 160 - fxParam2 * 5 / 8)); // Regler 2: Nachleuchten
|
||
FOR_XYZ {
|
||
if (x < 2 && blue) at(x, y, z) = CRGB(0, 0, highlight);
|
||
if (x > 2 && red) at(x, y, z) = CRGB(highlight, 0, 0);
|
||
if (x == 2 && (blue || red)) at(x, y, z) = CRGB(highlight / 3, highlight / 3, highlight / 3);
|
||
}
|
||
}
|
||
|
||
// --- Pixelsturm: bunte 2×2×2-Blöcke blitzen überall auf -------------------------
|
||
|
||
void renderPixelStorm(uint32_t now) {
|
||
static uint32_t next = 0;
|
||
fadeToBlackBy(leds, NUM_LEDS, 30);
|
||
if (int32_t(now - next) < 0) return;
|
||
next = now + 70;
|
||
uint8_t bx = random8(CUBE_SIZE - 1), by = random8(CUBE_SIZE - 1), bz = random8(NUM_LAYERS - 1);
|
||
CRGB c = CHSV(random8(), 230, highlight);
|
||
for (uint8_t i = 0; i < 8; i++) at(bx + (i & 1), by + (i >> 1 & 1), bz + (i >> 2)) = c;
|
||
}
|
||
|
||
// --- Laser: Strahlen schießen quer durch den Würfel ------------------------------
|
||
|
||
struct Beam {
|
||
uint8_t axis, a, b, hue;
|
||
bool reverse;
|
||
uint32_t start;
|
||
};
|
||
static Beam beams[3];
|
||
|
||
void renderLaser(uint32_t now) {
|
||
static const uint8_t HUES[] = {0, 96, 160, 200, 40};
|
||
FastLED.clear();
|
||
for (uint8_t k = 0; k < 3; k++) {
|
||
Beam &bm = beams[k];
|
||
if (fresh || int32_t(now - bm.start) > 600) {
|
||
bm = {random8(3), random8(CUBE_SIZE), random8(CUBE_SIZE), HUES[random8(5)], bool(random8(2)),
|
||
now + (fresh ? k * 200 : random8(150))};
|
||
}
|
||
if (int32_t(now - bm.start) < 0) continue;
|
||
uint32_t t = now - bm.start;
|
||
float head = t * 0.025f; // 5 LEDs in 200 ms
|
||
uint8_t v = t < 400 ? highlight : highlight * (600 - t) / 200;
|
||
for (uint8_t i = 0; i < CUBE_SIZE && i <= head; i++) {
|
||
uint8_t p = bm.reverse ? TOP - i : i;
|
||
uint8_t x = bm.axis == 0 ? p : bm.a, y = bm.axis == 1 ? p : bm.axis == 0 ? bm.a : bm.b,
|
||
z = bm.axis == 2 ? p : bm.b;
|
||
at(x, y, z) += CHSV(bm.hue, 255, i + 1 > head ? v / 2 : v);
|
||
}
|
||
}
|
||
fresh = false;
|
||
}
|