Files
cube/effects.cpp
T
mikeandClaude Opus 5.5 55b94475a5 Firmware, iOS-App und Gehäuse für den 5x5x5-LED-Würfel
ESP32-S3-Firmware mit 18 Effekten, Mikrofon (Klatschen, Beat, Spektrum)
und REST-API, Testprogramme, SwiftUI-Fernbedienung und OpenSCAD-Sockel.
Die WLAN-Zugangsdaten (secrets.h) sind nicht enthalten.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-13 15:00:43 +01:00

592 lines
20 KiB
C++

#include "cube.h"
const float MID = (CUBE_SIZE - 1) / 2.0f; // Mitte des Würfels
float rnd(float a, float b) {
return a + (b - a) * random16() / 65535.0f;
}
// Setzt einen Punkt an die nächstgelegene LED (addiert, außerhalb wird ignoriert).
void plot(float x, float y, float z, const CRGB &c) {
int ix = lroundf(x), iy = lroundf(y), iz = lroundf(z);
if (ix < 0 || iy < 0 || iz < 0 || ix >= CUBE_SIZE || iy >= CUBE_SIZE || iz >= NUM_LAYERS) return;
at(ix, iy, iz) += c;
}
// --- Partikel (Feuerwerk, Matrix, Schnee) ------------------------------------
struct Particle {
float x, y, z, vx, vy, vz;
CRGB color;
uint8_t life; // 0 = frei, sonst Helligkeit
};
const uint8_t MAX_PARTICLES = 48;
Particle particles[MAX_PARTICLES];
void spawnParticle(float x, float y, float z, float vx, float vy, float vz, const CRGB &color) {
for (Particle &p : particles)
if (!p.life) {
p = {x, y, z, vx, vy, vz, color, 255};
return;
}
}
// Bewegt alle Partikel; wer verglüht oder den Würfel verlässt, wird frei.
void moveParticles(float gravity, float drag, uint8_t fade) {
for (Particle &p : particles) {
if (!p.life) continue;
p.vx *= drag;
p.vy *= drag;
p.vz = p.vz * drag - gravity;
p.x += p.vx;
p.y += p.vy;
p.z += p.vz;
p.life = qsub8(p.life, fade);
if (p.z < -0.5f || p.x < -0.5f || p.y < -0.5f || p.x > CUBE_SIZE - 0.5f || p.y > CUBE_SIZE - 0.5f)
p.life = 0;
}
}
void drawParticles() {
for (const Particle &p : particles)
if (p.life) plot(p.x, p.y, p.z, CRGB(p.color).nscale8(p.life));
}
// --- Gewitter (für Manuel); Blitze gibt es auch beim Klatschen in jedem Effekt --
const uint8_t MAX_DROPS = 16;
const uint8_t MAX_POINTS = 16; // Punkte pro Blitz
const uint8_t MAX_PULSES = 4; // Teilentladungen pro Blitz
struct Drop {
bool active;
uint8_t x, y;
int16_t z16; // Höhe in 1/16 Etagen
};
Drop drops[MAX_DROPS];
struct Bolt {
bool active;
uint32_t start;
uint8_t n, x[MAX_POINTS], y[MAX_POINTS], z[MAX_POINTS];
uint8_t pulses;
uint16_t on[MAX_PULSES], len[MAX_PULSES], end; // ms nach start
};
Bolt bolt;
uint32_t nextStrike = 0;
void addPoint(uint8_t x, uint8_t y, uint8_t z) {
if (bolt.n == MAX_POINTS) return;
bolt.x[bolt.n] = x;
bolt.y[bolt.n] = y;
bolt.z[bolt.n] = z;
bolt.n++;
}
// Ein Schritt zur Seite (±1 in x oder y), am Rand nach innen.
void zigzag(uint8_t &x, uint8_t &y) {
uint8_t &c = random8(2) ? x : y;
if (c == 0) c = 1;
else if (c == CUBE_SIZE - 1) c--;
else if (random8(2)) c++;
else c--;
}
void triggerLightning(uint32_t now) {
// Zickzack-Pfad von der Wolke nach unten, manchmal mit Verzweigung
bolt.n = 0;
uint8_t x = random8(CUBE_SIZE), y = random8(CUBE_SIZE);
int8_t branchAt = random8(2) ? random8(1, TOP) : -1;
for (int8_t z = TOP; z >= 0; z--) {
addPoint(x, y, z);
if (z == branchAt) {
uint8_t bx = x, by = y;
for (int8_t bz = z - 1; bz >= 0 && bz >= z - 2; bz--) {
zigzag(bx, by);
addPoint(bx, by, bz);
}
}
switch (random8(3)) {
case 0: break; // senkrecht weiter
case 1: zigzag(x, y); break; // schräg weiter
case 2: zigzag(x, y); addPoint(x, y, z); break; // Knick in der Etage
}
}
// Ein Blitz flackert mehrmals kurz hintereinander
bolt.pulses = random8(2, MAX_PULSES + 1);
uint16_t t = 0;
for (uint8_t i = 0; i < bolt.pulses; i++) {
bolt.on[i] = t;
bolt.len[i] = random8(30, 90);
t += bolt.len[i] + random8(40, 140);
}
bolt.end = bolt.on[bolt.pulses - 1] + bolt.len[bolt.pulses - 1];
bolt.start = now;
bolt.active = true;
}
void renderStorm(uint32_t now) {
FastLED.clear();
// Wolken: oberste Etage, dunkel grau-blau wabernd
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++)
at(x, y, TOP) = CHSV(160, 120, scale8(inoise8(x * 80, y * 80, now / 4), brightness));
// Regen: Tropfen fallen unter den Wolken nach unten
for (Drop &d : drops) {
if (!d.active) {
if (random8() < 10) d = {true, random8(CUBE_SIZE), random8(CUBE_SIZE), int16_t(TOP * 16 - 1)};
continue;
}
at(d.x, d.y, d.z16 / 16) += CRGB(0, brightness / 3, brightness);
d.z16 -= 4;
if (d.z16 < 0) d.active = false;
}
// Blitze in zufälligen Abständen (gezeichnet wird in drawLightning)
if (!bolt.active && int32_t(now - nextStrike) >= 0) {
triggerLightning(now);
nextStrike = now + bolt.end + 300 + random16(500, 3000);
}
}
// Zeichnet einen laufenden Blitz über den aktuellen Effekt.
void drawLightning(uint32_t now) {
if (!bolt.active) return;
uint32_t dt = now - bolt.start;
bool flash = false;
for (uint8_t i = 0; i < bolt.pulses; i++)
if (dt >= bolt.on[i] && dt < bolt.on[i] + bolt.len[i]) flash = true;
CRGB c;
if (flash) {
c = CRGB(220, 220, 255);
for (CRGB &l : leds) l += CRGB(brightness / 4, brightness / 4, brightness / 2); // Himmel leuchtet mit auf
} else if (dt < bolt.end) {
c = CRGB(30, 20, 60); // Kanal glimmt zwischen den Entladungen
} else if (dt < bolt.end + 300u) {
uint8_t v = 120 - 120 * (dt - bolt.end) / 300; // Nachglühen
c = CRGB(v / 2, v / 3, v);
} else {
bolt.active = false;
return;
}
for (uint8_t i = 0; i < bolt.n; i++) at(bolt.x[i], bolt.y[i], bolt.z[i]) = c;
}
// --- Feuer: Flammen in jeder Säule, unten heiß, oben glimmend ----------------
uint8_t heat[CUBE_SIZE][CUBE_SIZE][NUM_LAYERS];
void renderFire(uint32_t now) {
static uint32_t last = 0;
if (now - last >= 30) {
last = now;
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
uint8_t *h = heat[x][y];
for (uint8_t z = 0; z < NUM_LAYERS; z++) h[z] = qsub8(h[z], random8(0, 90)); // abkühlen
for (uint8_t z = TOP; z >= 2; z--) h[z] = (h[z - 1] + 2 * h[z - 2]) / 3; // Hitze steigt
if (random8() < 100) { // Funken unten
uint8_t s = random8(2);
h[s] = qadd8(h[s], random8(150, 255));
}
}
}
for (uint8_t z = 0; z < NUM_LAYERS; z++)
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++)
at(x, y, z) = HeatColor(heat[x][y][z]).nscale8(brightness);
}
// --- Regenbogen, der nach oben steigt -----------------------------------------
void renderRainbow(uint32_t now) {
for (uint8_t z = 0; z < NUM_LAYERS; z++)
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++)
at(x, y, z) = CHSV(uint8_t(now / 8 - z * 32 + (x + y) * 6), 255, brightness);
}
// --- Sinuswelle: eine wogende Fläche, wechselt zwischen drei Wellenformen ------
// Höhe der Fläche über Säule (x, y), 0 .. TOP
float waveHeight(uint8_t form, uint8_t x, uint8_t y, float phase) {
float s;
switch (form) {
case 0: s = x * 1.2f; break; // läuft quer durch
case 1: s = (x + y) * 0.8f; break; // diagonal
default: s = hypotf(x - MID, y - MID) * 1.6f; break; // Kreiswellen von der Mitte
}
return MID + MID * sinf(s - phase);
}
void renderWave(uint32_t now) {
const uint32_t FORM_MS = 7000, BLEND_MS = 1000;
float phase = (now % 1600) / 1600.0f * TWO_PI; // eine Schwingung in 1,6 s
// Am Ende jeder Wellenform weich in die nächste überblenden
uint32_t slot = now / FORM_MS, inSlot = now % FORM_MS;
uint8_t a = slot % 3, b = (slot + 1) % 3;
float w = inSlot > FORM_MS - BLEND_MS ? float(inSlot - (FORM_MS - BLEND_MS)) / BLEND_MS : 0;
w = w * w * (3 - 2 * w);
FastLED.clear();
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
float h = (1 - w) * waveHeight(a, x, y, phase) + w * waveHeight(b, x, y, phase);
uint8_t hue = now / 50 + uint8_t(h * 25); // Berge und Täler in verschiedenen Farben
for (uint8_t z = 0; z < NUM_LAYERS; z++) {
float d = fabsf(z - h); // zwischen zwei Etagen weich verteilen
if (d < 1) at(x, y, z) = CHSV(hue, 255, uint8_t((1 - d) * highlight));
}
}
}
// --- Glitzer: bunte Funken, die langsam verglühen -----------------------------
void renderGlitter(uint32_t now) {
fadeToBlackBy(leds, NUM_LEDS, 12);
if (random8() < 100) leds[random16(NUM_LEDS)] = CHSV(random8(), 160, highlight);
}
// --- Feuerwerk: Raketen steigen auf und zerplatzen in bunte Funken -------------
struct Rocket {
bool active;
uint8_t x, y, hue;
float z, target;
};
Rocket rocket;
uint32_t nextLaunch = 0;
void renderFireworks(uint32_t now) {
FastLED.clear();
if (!rocket.active && int32_t(now - nextLaunch) >= 0) {
rocket = {true, random8(1, CUBE_SIZE - 1), random8(1, CUBE_SIZE - 1), random8(), 0, rnd(2.5f, TOP)};
nextLaunch = now + random16(800, 2200);
}
if (rocket.active) {
rocket.z += 0.1f;
if (rocket.z < rocket.target) {
plot(rocket.x, rocket.y, rocket.z, CRGB(highlight, highlight / 2, highlight / 6)); // Kopf
plot(rocket.x, rocket.y, rocket.z - 1, CRGB(brightness, brightness / 4, 0)); // Schweif
} else {
rocket.active = false;
uint8_t n = random8(14, 24);
for (uint8_t i = 0; i < n; i++) {
float vx = rnd(-1, 1), vy = rnd(-1, 1), vz = rnd(-1, 1);
float k = rnd(0.05f, 0.12f) / (sqrtf(vx * vx + vy * vy + vz * vz) + 0.01f);
CRGB c = CHSV(rocket.hue + random8(40), random8(4) ? 255 : 0, highlight); // ab und zu weiß
spawnParticle(rocket.x, rocket.y, rocket.z, vx * k, vy * k, vz * k, c);
}
}
}
moveParticles(0.004f, 0.96f, 5);
drawParticles();
}
// --- Matrix: grüne Zeichenketten rieseln herab --------------------------------
void renderMatrix(uint32_t now) {
FastLED.clear();
if (random8() < 40)
spawnParticle(random8(CUBE_SIZE), random8(CUBE_SIZE), TOP, 0, 0, -rnd(0.06f, 0.15f), CRGB::Black);
moveParticles(0, 1, 0);
for (const Particle &p : particles) {
if (!p.life) continue;
plot(p.x, p.y, p.z + 2, CRGB(0, brightness / 4, 0));
plot(p.x, p.y, p.z + 1, CRGB(0, brightness, 0));
plot(p.x, p.y, p.z, CRGB(highlight / 2, highlight, highlight / 2));
}
}
// --- Schnee: Flocken taumeln herab und bleiben unten kurz liegen ---------------
uint8_t ground[CUBE_SIZE][CUBE_SIZE];
void renderSnow(uint32_t now) {
FastLED.clear();
if (random8() < 15) {
CRGB white(highlight / 2, highlight / 2, highlight / 2);
spawnParticle(rnd(0, CUBE_SIZE - 1), rnd(0, CUBE_SIZE - 1), TOP + 0.4f, 0, 0, -rnd(0.012f, 0.02f), white);
}
for (Particle &p : particles) {
if (!p.life) continue;
p.vx = constrain(p.vx + rnd(-0.002f, 0.002f), -0.015f, 0.015f); // taumeln
p.vy = constrain(p.vy + rnd(-0.002f, 0.002f), -0.015f, 0.015f);
if (p.z + p.vz < 0) { // gelandet
uint8_t &g = ground[constrain(lroundf(p.x), 0, CUBE_SIZE - 1)][constrain(lroundf(p.y), 0, CUBE_SIZE - 1)];
g = qadd8(g, 80);
p.life = 0;
}
}
moveParticles(0, 1, 0);
static uint8_t frame = 0;
bool melt = ++frame % 6 == 0;
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
if (melt) ground[x][y] = qsub8(ground[x][y], 1);
at(x, y, 0) = CRGB(brightness, brightness, brightness).nscale8(ground[x][y]);
}
drawParticles();
}
// --- Lavalampe: glühende Blasen steigen langsam auf ---------------------------
void renderLava(uint32_t now) {
for (uint8_t z = 0; z < NUM_LAYERS; z++)
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
uint8_t n = inoise8(x * 50, uint16_t(y * 50 + now / 20), uint16_t(z * 50 - now / 8));
n = qsub8(n, 60);
n = qadd8(n, n); // Kontrast erhöhen
at(x, y, z) = ColorFromPalette(LavaColors_p, n, brightness);
}
}
// --- Doppelhelix: zwei Stränge winden sich um die Mitte -----------------------
void renderHelix(uint32_t now) {
fadeToBlackBy(leds, NUM_LEDS, 60);
float turn = (now % 2000) / 2000.0f * TWO_PI; // eine Umdrehung in 2 s
for (uint8_t z = 0; z < NUM_LAYERS; z++) {
float a = turn + z * TWO_PI / NUM_LAYERS;
float dx = 1.9f * cosf(a), dy = 1.9f * sinf(a);
uint8_t hue = now / 30 + z * 12;
plot(MID + dx, MID + dy, z, CHSV(hue, 255, highlight));
plot(MID - dx, MID - dy, z, CHSV(hue + 128, 255, highlight));
}
}
// --- Flummis: zwei Bälle springen durch den Würfel ----------------------------
struct Ball {
float x, y, z, vx, vy, vz;
uint8_t hue;
};
Ball balls[] = {{1, 1, TOP, 0.04f, 0.03f, 0, 0}, {3, 2, 2, -0.03f, 0.05f, 0, 128}};
void renderBounce(uint32_t now) {
fadeToBlackBy(leds, NUM_LEDS, 50);
const float g = 0.006f, hi = CUBE_SIZE - 1;
for (Ball &b : balls) {
b.vz -= g;
b.x += b.vx;
b.y += b.vy;
b.z += b.vz;
if (b.x < 0 || b.x > hi) { b.vx = -b.vx; b.x = constrain(b.x, 0, hi); b.hue += 30; }
if (b.y < 0 || b.y > hi) { b.vy = -b.vy; b.y = constrain(b.y, 0, hi); b.hue += 30; }
if (b.z < 0) { // Aufprall: springt immer wieder fast bis oben
b.z = 0;
b.vz = sqrtf(2 * g * rnd(2.5f, TOP));
b.hue += 30;
}
plot(b.x, b.y, b.z, CHSV(b.hue, 255, highlight));
}
}
// --- Würfel im Würfel: Wellen laufen von der Mitte zur Außenhaut ---------------
void renderShells(uint32_t now) {
for (uint8_t z = 0; z < NUM_LAYERS; z++)
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
int d = max(max(abs(x - 2), abs(y - 2)), abs(z - 2)); // 0 = Mitte, 2 = außen
uint8_t wave = sin8(uint8_t(now / 4 - d * 70));
wave = scale8(wave, wave); // schärfere Pulse
at(x, y, z) = CHSV(uint8_t(now / 40 + d * 40), 255, scale8(wave, brightness));
}
}
// --- Spektrum: Frequenzbänder als Säulen (Bass links), Verlauf wandert nach hinten
float history[CUBE_SIZE][CUBE_SIZE]; // [Alter][Band], Höhe 0..1
void renderSpectrum(uint32_t now) {
static uint32_t lastShift = 0;
if (now - lastShift >= 120) {
lastShift = now;
memmove(history[1], history[0], sizeof(history[0]) * (CUBE_SIZE - 1));
}
audioSpectrum(history[0]);
FastLED.clear();
for (uint8_t y = 0; y < CUBE_SIZE; y++) {
uint8_t v = scale8(highlight, 255 - y * 40); // nach hinten sanft dunkler: 100 %, 84 %, 69 %, 53 %, 37 %
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
float h = history[y][x] * NUM_LAYERS;
for (uint8_t z = 0; z < NUM_LAYERS; z++) {
float f = constrain(h - z, 0.0f, 1.0f);
if (f > 0) at(x, y, z) = CHSV(x * 45, 255, uint8_t(f * v));
}
}
}
}
// --- Puls: eine Kugel in der Mitte wächst mit der Lautstärke ------------------
void renderPulse(uint32_t now) {
float l = audioLevel();
float r = 0.6f + l * 2.6f;
uint8_t hue = now / 60 + uint8_t(l * 60);
for (uint8_t z = 0; z < NUM_LAYERS; z++)
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
float d = sqrtf(sq(x - MID) + sq(y - MID) + sq(z - MID));
float f = constrain(r - d, 0.0f, 1.0f);
at(x, y, z) = CHSV(hue + uint8_t(d * 20), 255, uint8_t(f * min(255, brightness * 2)));
}
}
// --- Schockwelle: jeder Bass-Schlag schickt eine Kugelwelle von der Mitte los --
struct Shock {
uint32_t start; // 0 = frei
uint8_t hue;
};
Shock shocks[4];
void renderShockwave(uint32_t now) {
static uint8_t next = 0, hue = 0;
if (audioBeat()) {
shocks[next] = {now, hue};
next = (next + 1) % 4;
hue += 40;
}
FastLED.clear();
float glow = audioLevel();
for (uint8_t z = 0; z < NUM_LAYERS; z++)
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
float d = sqrtf(sq(x - MID) + sq(y - MID) + sq(z - MID));
CRGB &led = at(x, y, z);
// Glühen in der Mitte mit der Lautstärke
float core = constrain(glow * 1.5f - d, 0.0f, 1.0f);
led += CHSV(hue, 200, uint8_t(core * brightness));
// Wellen: Radius wächst 8 Einheiten pro Sekunde, wird dabei schwächer
for (Shock &w : shocks) {
if (!w.start) continue;
float r = (now - w.start) * 0.008f;
float f = constrain(1 - fabsf(d - r), 0.0f, 1.0f) * constrain(1 - r / 4, 0.0f, 1.0f);
if (f > 0) led += CHSV(w.hue, 255, uint8_t(f * highlight));
}
}
for (Shock &w : shocks)
if (w.start && now - w.start > 500) w.start = 0;
}
// --- Klangschichten: unten Bass, oben Höhen; Lautstärke = Fläche in der Etage --
void renderSoundLayers(uint32_t now) {
float bands[CUBE_SIZE];
audioSpectrum(bands);
FastLED.clear();
for (uint8_t z = 0; z < NUM_LAYERS; z++) {
float r = bands[z % CUBE_SIZE] * 3.2f; // 0 = nur Mitte, 3,2 = ganze Etage
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
float d = sqrtf(sq(x - MID) + sq(y - MID));
float f = constrain(r - d + 0.5f, 0.0f, 1.0f);
if (f > 0) at(x, y, z) = CHSV(uint8_t(z * 45 + d * 8), 255, uint8_t(f * min(255, brightness * 3)));
}
}
}
// --- Klangwelle: Kreiswellen, deren Höhe der Lautstärke folgt -----------------
void renderSoundWave(uint32_t now) {
static float amp = 0;
float l = audioLevel();
amp = l > amp ? l : amp * 0.97f; // schnell hoch, sanft zurück
float phase = (now % 1200) / 1200.0f * TWO_PI;
FastLED.clear();
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
float h = MID + MID * (0.15f + 0.85f * amp) * sinf(hypotf(x - MID, y - MID) * 1.6f - phase);
uint8_t hue = now / 40 + uint8_t(h * 30);
for (uint8_t z = 0; z < NUM_LAYERS; z++) {
float d = fabsf(z - h);
if (d < 1) at(x, y, z) = CHSV(hue, 255, uint8_t((1 - d) * highlight));
}
}
}
// --- Disko: bunte Funken mit der Lautstärke, bei jedem Beat ein ganzer Schwall --
void renderDisco(uint32_t now) {
fadeToBlackBy(leds, NUM_LEDS, 25);
uint8_t sparks = audioLevel() * 3;
if (audioBeat()) sparks += 20;
for (uint8_t i = 0; i < sparks; i++)
leds[random16(NUM_LEDS)] = CHSV(random8(), 220, highlight);
}
// --- Spezialeffekte, die wie der Blitz kurz über jedem Effekt laufen --------------
uint32_t explosionStart = 0, rainbowStart = 0; // 0 = aus
void triggerExplosion(uint32_t now) { explosionStart = now; }
void triggerRainbowWave(uint32_t now) { rainbowStart = now; }
// Feuerball aus der Mitte: weißer Kern, Schale wird von Weiß über Gelb zu Rot
void drawExplosion(uint32_t now) {
if (!explosionStart) return;
uint32_t t = now - explosionStart;
if (t > 550) {
explosionStart = 0;
return;
}
float r = t * 0.008f; // Radius: 4,4 Einheiten in 0,55 s
float fade = 1 - t / 550.0f;
for (uint8_t z = 0; z < NUM_LAYERS; z++)
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++) {
float d = sqrtf(sq(x - MID) + sq(y - MID) + sq(z - MID));
float shell = constrain(1 - fabsf(d - r) / 1.2f, 0.0f, 1.0f) * fade;
if (shell <= 0) continue;
uint8_t heat = constrain(255 - int(t * 0.33f) - int(d * 20), 60, 255);
at(x, y, z) += HeatColor(heat).nscale8(uint8_t(shell * 255));
}
}
// Regenbogen-Ebene rauscht einmal von unten nach oben
void drawRainbowWave(uint32_t now) {
if (!rainbowStart) return;
uint32_t t = now - rainbowStart;
if (t > 700) {
rainbowStart = 0;
return;
}
float pos = -1 + t / 700.0f * (NUM_LAYERS + 1); // in 0,7 s von unter Etage 0 bis über die oberste
for (uint8_t z = 0; z < NUM_LAYERS; z++) {
float f = constrain(1 - fabsf(z - pos) / 1.2f, 0.0f, 1.0f);
if (f <= 0) continue;
for (uint8_t y = 0; y < CUBE_SIZE; y++)
for (uint8_t x = 0; x < CUBE_SIZE; x++)
at(x, y, z) += CHSV(uint8_t((x + y) * 25 + t / 2), 255, uint8_t(f * 255));
}
}
void drawSpecials(uint32_t now) {
drawRainbowWave(now);
drawExplosion(now);
drawLightning(now);
}
// --- Effektwechsel ---------------------------------------------------------
void resetEffects() {
for (Particle &p : particles) p.life = 0;
for (Shock &w : shocks) w.start = 0;
audioBeat(); // alten Beat verwerfen
memset(history, 0, sizeof(history));
memset(ground, 0, sizeof(ground));
rocket.active = false;
}