diff --git a/README.md b/README.md index eacdd62..3b0c764 100644 --- a/README.md +++ b/README.md @@ -7,11 +7,11 @@

125 adressierbare RGB-LEDs in fünf gestapelten Etagen, gesteuert von einem -**ESP32-S3**. Der Würfel spielt 18 Animationen in Endlosschleife, hört über ein +**ESP32-S3**. Der Würfel spielt 84 Animationen in 7 Kategorien, hört über ein Mikrofon mit, tanzt zur Musik und lässt es blitzen, wenn man in die Hände klatscht. Im WLAN ist er per **REST-API** und **iPhone-App** fernsteuerbar. -- **18 Effekte** – von Gewitter und Feuerwerk bis Doppelhelix, weich überblendet +- **84 Effekte** in 7 Kategorien – Flash, Festtage, Musik, Floating, Natur, Fraktal und Ruhe, weich überblendet - **Musik-Visualisierung** – Spektrum, Beat-Erkennung und Lautstärke aus dem Mikrofon - **Klatschen → Blitz** – in jedem Effekt, abgestimmt gegen Sprache und Hintergrundlärm - **REST-API** – JSON über `http://cube.local`, sucht sich selbst das stärkste bekannte WLAN @@ -112,34 +112,46 @@ Port und Board lassen sich überschreiben, z. B. `make upload PORT=/dev/cu.usbmo ## Effekte -Die Effekte sind in Kategorien sortiert und laufen nacheinander in -Endlosschleife, mit 0,5 s überblendet. Der automatische Wechsel und Taster 1 -bleiben in der Kategorie des laufenden Effekts – wer Schnee auswählt, bekommt -danach nur noch Weihnachts-Effekte. Die App hat je Kategorie 12 Plätze; mehr -Effekte pro Kategorie lässt die Firmware schon beim Kompilieren nicht zu. +84 Effekte in 7 Kategorien, je 12 – so viele Plätze hat die App pro Kategorie; +mehr lässt die Firmware schon beim Kompilieren nicht zu. Die Effekte laufen +nacheinander in Endlosschleife und werden mit 0,5 s überblendet. Der +automatische Wechsel und Taster 1 bleiben in der Kategorie des laufenden +Effekts – wer den Weihnachtsbaum auswählt, bekommt danach nur noch Festtage. +Nach dem Einschalten läuft das Gewitter. -**Flash** +**Flash** – schnell und kräftig | | Effekt | `id` | Dauer | Beschreibung | | --- | --- | --- | --- | --- | -| ⛈️ | Gewitter | `gewitter` | 40 s | Wolken wabern in der obersten Etage, Regen fällt, verzweigte Blitze flackern und glühen nach | | 🧊 | Würfel im Würfel | `wuerfel` | 20 s | Pulse laufen als Würfelschalen von der Mitte zur Außenhaut | -| 🔥 | Feuer | `feuer` | 20 s | Flammen in jeder Säule, unten heiß, oben glimmend | | 🟩 | Matrix | `matrix` | 20 s | Grüne Zeichenketten rieseln herab | | 🏀 | Flummis | `flummis` | 20 s | Zwei Bälle springen durch den Würfel | +| 📸 | Blitzlicht | `blitzlicht` | 15 s | Würfel, Etage oder Ebene blitzt in wechselnden Farben (höchstens 2,5 Blitze/s) | +| 📡 | Scanner | `scanner` | 20 s | Eine Ebene fegt hin und her, jedes Mal entlang einer anderen Achse | +| ☄️ | Kometen | `kometen` | 20 s | Kometen mit Schweif fliegen quer durch | +| 🐍 | Schlange | `schlange` | 25 s | Eine Schlange kriecht durch den Würfel und weicht sich selbst aus | +| 🚁 | Rotor | `rotor` | 20 s | Eine senkrechte Ebene dreht sich schnell um die Mitte | +| 🧱 | Stapeln | `stapeln` | 40 s | Würfel fallen und stapeln sich, volle Etagen blitzen auf und verschwinden | +| 🚨 | Blaulicht | `blaulicht` | 15 s | Links blau, rechts rot, jeweils Doppelblitz | +| 👾 | Pixelsturm | `pixelsturm` | 20 s | Bunte 2×2×2-Blöcke blitzen überall auf | +| 🔫 | Laser | `laser` | 20 s | Strahlen schießen quer durch den Würfel | -**Weihnachten** +**Festtage** – Weihnachten und Silvester | | Effekt | `id` | Dauer | Beschreibung | | --- | --- | --- | --- | --- | +| 🎄 | Weihnachtsbaum | `weihnachtsbaum` | 40 s | Grüner Kegel mit funkelnden Kugeln, Stern an der Spitze, leiser Schnee | +| 🕯️ | Adventskranz | `adventskranz` | 40 s | Grüner Kranz mit Beeren, alle 8 s brennt eine Kerze mehr | | ❄️ | Schnee | `schnee` | 25 s | Flocken taumeln herab und bleiben unten kurz liegen | +| 💡 | Lichterkette | `lichterkette` | 30 s | Bunte Birnen als Spirale um den Würfel, abwechselnd Lauflicht und Blinken | +| ⭐ | Weihnachtsstern | `weihnachtsstern` | 25 s | Strahlen in alle Richtungen, Achsen und Diagonalen im Wechsel | +| 🎁 | Geschenk | `geschenk` | 24 s | Paket mit glitzernder Goldschleife, alle 8 s in einer anderen Farbe | +| 🍭 | Zuckerstange | `zuckerstange` | 20 s | Rot-weiße Streifen drehen sich als Spirale nach oben | | ✨ | Glitzer | `glitzer` | 20 s | Bunte Funken, die langsam verglühen | - -**Silvester** - -| | Effekt | `id` | Dauer | Beschreibung | -| --- | --- | --- | --- | --- | +| 🔟 | Countdown | `countdown` | 30 s | Fünf Etagen gehen im Sekundentakt aus, dann Explosion und Feuerwerk | | 🎆 | Feuerwerk | `feuerwerk` | 25 s | Raketen mit Schweif steigen auf und zerplatzen in bunte Funken | +| 🎇 | Wunderkerze | `wunderkerze` | 20 s | Sprüht Funken und brennt dabei von oben nach unten ab | +| 🥂 | Sekt | `sekt` | 25 s | Goldene Flüssigkeit mit Schaum, Perlen steigen auf | **Musik** – reagieren auf das Mikrofon @@ -151,8 +163,14 @@ Effekte pro Kategorie lässt die Firmware schon beim Kompilieren nicht zu. | 🎚️ | Klangschichten | `klangschichten` | 30 s | Unten Bass, oben Höhen; die Lautstärke bestimmt die leuchtende Fläche | | 〰️ | Klangwelle | `klangwelle` | 30 s | Kreiswellen, deren Höhe der Lautstärke folgt | | 🪩 | Disko | `disko` | 30 s | Bunte Funken mit der Lautstärke, bei jedem Beat ein ganzer Schwall | +| 📶 | Pegel | `pegel` | 30 s | Der Würfel füllt sich mit der Lautstärke, grün bis rot, der Spitzenwert bleibt kurz stehen | +| 🥁 | Beat-Ebenen | `beatebenen` | 30 s | Jeder Bass-Schlag lässt eine zufällige Ebene aufleuchten | +| 🔊 | Klangwürfel | `klangwuerfel` | 30 s | Bass in der Mitte, Mitten in der inneren Schale, Höhen außen | +| 🌠 | Funkenregen | `funkenregen` | 30 s | Funken fallen mit der Lautstärke, jeder Beat gibt einen Schwall | +| 📈 | Oszilloskop | `oszilloskop` | 30 s | Die Lautstärke als Linie, die von vorn nach hinten durchläuft | +| ⭕ | Ringe | `ringe` | 30 s | Bass in der Mittelsäule, Mitten im inneren Ring, Höhen am Rand | -**Floating** +**Floating** – fließend und schwebend | | Effekt | `id` | Dauer | Beschreibung | | --- | --- | --- | --- | --- | @@ -160,6 +178,65 @@ Effekte pro Kategorie lässt die Firmware schon beim Kompilieren nicht zu. | 🫧 | Lavalampe | `lavalampe` | 25 s | Glühende Blasen steigen langsam auf | | 🌊 | Sinuswelle | `sinuswelle` | 21 s | Eine wogende Fläche – quer, diagonal und als Kreiswellen | | 🧬 | Doppelhelix | `doppelhelix` | 20 s | Zwei Stränge winden sich um die Mitte | +| 🔮 | Plasma | `plasma` | 25 s | Überlagerte Sinuswellen als fließendes Farbfeld | +| 🫧 | Seifenblasen | `seifenblasen` | 30 s | Schillernde Kugelschalen steigen langsam auf | +| 🌫️ | Farbnebel | `farbnebel` | 25 s | Bunte Wolken ziehen durch den Würfel | +| 🟣 | Metabälle | `metabaelle` | 25 s | Drei weiche Farbkugeln, die ineinander verschmelzen | +| 🌀 | Wirbel | `wirbel` | 20 s | Farben drehen sich um die Mittelachse, oben schneller als unten | +| 🪐 | Schwerelos | `schwerelos` | 30 s | Lichtpunkte treiben langsam durch den Raum und ziehen Spuren | +| 🎡 | Kreisel | `kreisel` | 25 s | Zwei Ringe kippen und drehen sich ineinander | +| 🕰️ | Pendelwelle | `pendelwelle` | 60 s | 25 Pendel mit leicht verschiedenen Längen bilden Muster, nach 60 s wieder im Gleichtakt | + +**Natur** + +| | Effekt | `id` | Dauer | Beschreibung | +| --- | --- | --- | --- | --- | +| ⛈️ | Gewitter | `gewitter` | 40 s | Wolken wabern in der obersten Etage, Regen fällt, verzweigte Blitze flackern und glühen nach | +| 🔥 | Feuer | `feuer` | 20 s | Flammen in jeder Säule, unten heiß, oben glimmend | +| 🌧️ | Regen | `regen` | 25 s | Tropfen fallen und ziehen unten Kreise im Wasser | +| 🌌 | Polarlicht | `polarlicht` | 30 s | Grüne Vorhänge mit violetten Säumen wehen über verschneitem Boden | +| 🌊 | Ozean | `ozean` | 25 s | Wasser mit Wellen, Schaum auf den Kämmen | +| 🪲 | Glühwürmchen | `gluehwuermchen` | 30 s | Grünlich-gelbe Lichter blinken langsam im Dunkeln | +| 🌅 | Sonnenaufgang | `sonnenaufgang` | 40 s | Nacht mit Sternen, Morgenrot, Tag und Abendrot; die Sonne zieht ihre Bahn | +| 🌷 | Blumenwiese | `blumenwiese` | 30 s | Wogendes Gras, Blumen auf Stängeln, ein Schmetterling flattert | +| 🏞️ | Wasserfall | `wasserfall` | 25 s | Wasser stürzt an der Rückseite herab in ein Becken, Gischt spritzt | +| 🌋 | Vulkan | `vulkan` | 30 s | Glühender Krater, Lavaströme an den Hängen, immer wieder Ausbrüche | +| 🍂 | Herbstlaub | `herbstlaub` | 30 s | Bunte Blätter segeln im Wind herab und bleiben am Boden liegen | +| 🌠 | Sternschnuppen | `sternschnuppen` | 30 s | Funkelnder Nachthimmel, ab und zu zieht eine Schnuppe vorbei | + +**Fraktal** – Fraktale, seltsame Attraktoren und Zellautomaten + +| | Effekt | `id` | Dauer | Beschreibung | +| --- | --- | --- | --- | --- | +| 🌀 | Mandelbrot | `mandelbrot` | 24 s | Zoom ins Seepferdchental, jede Etage eine Stufe tiefer | +| 💠 | Julia | `julia` | 30 s | Julia-Menge, deren Parameter im Kreis wandert; jede Etage ist ein Stück voraus | +| 🔢 | Bitmuster | `bitmuster` | 24 s | Sierpinski-, XOR- und UND-Muster aus den Koordinaten, die durchwandern | +| 🌳 | Fraktalbaum | `fraktalbaum` | 27 s | Ein Baum wächst Etage für Etage, jeder Ast teilt sich in zwei | +| 🎲 | Chaosspiel | `chaosspiel` | 25 s | Immer halb zu einer zufälligen Ecke springen: ein Sierpinski-Tetraeder entsteht | +| 🦋 | Schmetterling | `schmetterling` | 30 s | Der Lorenz-Attraktor als Leuchtspur | +| ➰ | Attraktor | `attraktor` | 30 s | Der Thomas-Attraktor windet sich durch alle Ecken des Würfels | +| 🦠 | Leben 3D | `leben` | 40 s | Conways Spiel des Lebens im Würfel (Regel B5/S4567), neu gesät, wenn es festläuft | +| 🧮 | Zellautomat | `zellautomat` | 35 s | Regeln 30, 90, 110 und 150 um den Rand herum, ältere Generationen rutschen nach unten | +| 〽️ | Hilbertkurve | `hilbert` | 21 s | Ein Licht zeichnet die raumfüllende Hilbertkurve (4×4×4) | +| 💎 | Kristall | `kristall` | 40 s | Umherirrende Teilchen bleiben am Kristall hängen (diffusionsbegrenztes Wachstum) | +| ☁️ | Fraktalwolken | `fraktalwolken` | 30 s | Rauschen über drei Größenordnungen, von Schwarz über Violett bis Gold | + +**Ruhe** – sehr ruhig und langsam + +| | Effekt | `id` | Dauer | Beschreibung | +| --- | --- | --- | --- | --- | +| 😮‍💨 | Atmen | `atmen` | 60 s | Der ganze Würfel wird in 8 s hell und wieder dunkel | +| 🕯️ | Kerzenschein | `kerzenschein` | 60 s | Eine Flamme in der Mitte, warmes Licht ringsum | +| 🌃 | Sternenhimmel | `sternenhimmel` | 60 s | Dunkelblau, die Sterne funkeln ganz langsam | +| 🌕 | Mondlicht | `mondlicht` | 60 s | Blasser Mond, Wolken ziehen vorbei, unten glitzert Wasser | +| 🎨 | Farbwechsel | `farbwechsel` | 90 s | Der ganze Würfel in einer Farbe, eine Runde dauert 90 s | +| 🪵 | Glut | `glut` | 60 s | Glimmende Holzkohle, dunkelrot bis orange | +| 🐚 | Tiefsee | `tiefsee` | 60 s | Lichtflecken spielen langsam, ab und zu steigt eine Blase auf | +| 🌆 | Dämmerung | `daemmerung` | 60 s | Abendrot unten, Nachtblau oben, die Farben verschieben sich langsam | +| 🏖️ | Gezeiten | `gezeiten` | 60 s | Der Wasserspiegel hebt und senkt sich in 20 s | +| 🏮 | Laternen | `laternen` | 60 s | Warme Lichter steigen langsam auf und verglimmen oben | +| ⏳ | Sanduhr | `sanduhr` | 65 s | Sand rieselt Korn für Korn nach unten, dann wird umgedreht | +| 🖍️ | Pastell | `pastell` | 60 s | Sanfte Farbverläufe in hellen Tönen ziehen langsam durch | **Spezialeffekte** laufen kurz über jedem Effekt und werden per API oder App ausgelöst: @@ -170,11 +247,14 @@ ausgelöst: | `explosion` | Feuerball aus der Mitte: weißer Kern, die Schale verglüht über Gelb zu Rot | | `regenbogen` | Eine Regenbogen-Ebene rauscht in 0,7 s von unten nach oben | -Eigene Effekte: Funktion `renderXyz(uint32_t now)` in [`effects.cpp`](effects.cpp) -schreiben, in [`cube.h`](cube.h) deklarieren und mit ihrer Kategorie in die -Liste `EFFECTS` in [`cube.ino`](cube.ino) eintragen. Neue Kategorien kommen dort -in `CATEGORIES` und das `enum` darüber; die App übernimmt sie von selbst. Gezeichnet wird mit `at(x, y, z)` oder -`plot(x, y, z, farbe)` für Kommawerte; `z = 0` ist die unterste Etage. +Eigene Effekte: Funktion `renderXyz(uint32_t now)` in der Datei der Kategorie +(z. B. [`fx_natur.cpp`](fx_natur.cpp)) schreiben, in [`cube.h`](cube.h) +deklarieren und mit ihrer Kategorie in die Liste `EFFECTS` in +[`cube.ino`](cube.ino) eintragen. Neue Kategorien kommen dort in `CATEGORIES` +und das `enum` darüber; die App übernimmt sie von selbst. Gezeichnet wird mit +`at(x, y, z)`, `plot(x, y, z, farbe)` für Kommawerte oder `plotSoft()` für +weiche Bewegungen; `z = 0` ist die unterste Etage. Hilfen und Partikel stehen +in [`fx.h`](fx.h). ## Mikrofon und Musik @@ -309,7 +389,9 @@ Die WLAN-Zugangsdaten stehen in `secrets.h` (nicht im Repository, Vorlage: cube.ino Hauptprogramm: Effektliste, Überblendung, Taster, Hauptschleife cube.h gemeinsame Deklarationen, Koordinaten at(x, y, z) config.h Pins, LED-Typ, Helligkeit, Strom, Mikrofon-Schwellen -effects.cpp alle Effekte und Spezialeffekte +effects.cpp die ersten 18 Effekte, Spezialeffekte, gemeinsame Hilfen +fx_*.cpp die übrigen Effekte, eine Datei je Kategorie +fx.h gemeinsame Hilfen für die Effekte (plot, Partikel, ...) audio.cpp Mikrofon: DMA-Abtastung, Klatschen, Beat, FFT-Spektrum web.cpp WLAN-Verbindung, mDNS und REST-API secrets.example.h Vorlage für die WLAN-Zugangsdaten (secrets.h) diff --git a/cube.h b/cube.h index 184b07f..e884741 100644 --- a/cube.h +++ b/cube.h @@ -58,24 +58,96 @@ void triggerRainbowWave(uint32_t now); void drawLightning(uint32_t now); void drawSpecials(uint32_t now); // alle laufenden Spezialeffekte zeichnen -// Effekte (effects.cpp); now = millis() +// Effekte (effects.cpp und fx_*.cpp, eine Datei je Kategorie); now = millis() void resetEffects(); // beim Effektwechsel -void renderStorm(uint32_t now); -void renderFire(uint32_t now); -void renderRainbow(uint32_t now); -void renderWave(uint32_t now); -void renderGlitter(uint32_t now); -void renderFireworks(uint32_t now); -void renderMatrix(uint32_t now); -void renderSnow(uint32_t now); -void renderLava(uint32_t now); -void renderHelix(uint32_t now); -void renderBounce(uint32_t now); +// Flash void renderShells(uint32_t now); -// Musik-Effekte +void renderMatrix(uint32_t now); +void renderBounce(uint32_t now); +void renderStrobe(uint32_t now); +void renderScanner(uint32_t now); +void renderComets(uint32_t now); +void renderSnake(uint32_t now); +void renderRotor(uint32_t now); +void renderStack(uint32_t now); +void renderPolice(uint32_t now); +void renderPixelStorm(uint32_t now); +void renderLaser(uint32_t now); +// Festtage +void renderTree(uint32_t now); +void renderWreath(uint32_t now); +void renderSnow(uint32_t now); +void renderFairyLights(uint32_t now); +void renderXmasStar(uint32_t now); +void renderGift(uint32_t now); +void renderCandyCane(uint32_t now); +void renderGlitter(uint32_t now); +void renderCountdown(uint32_t now); +void renderFireworks(uint32_t now); +void renderSparkler(uint32_t now); +void renderBubbly(uint32_t now); +// Musik void renderSpectrum(uint32_t now); void renderPulse(uint32_t now); void renderShockwave(uint32_t now); void renderSoundLayers(uint32_t now); void renderSoundWave(uint32_t now); void renderDisco(uint32_t now); +void renderVu(uint32_t now); +void renderBeatPlanes(uint32_t now); +void renderSoundCube(uint32_t now); +void renderSparkRain(uint32_t now); +void renderScope(uint32_t now); +void renderRings(uint32_t now); +// Floating +void renderRainbow(uint32_t now); +void renderLava(uint32_t now); +void renderWave(uint32_t now); +void renderHelix(uint32_t now); +void renderPlasma(uint32_t now); +void renderBubbles(uint32_t now); +void renderColorFog(uint32_t now); +void renderMetaballs(uint32_t now); +void renderVortex(uint32_t now); +void renderWeightless(uint32_t now); +void renderRings3d(uint32_t now); +void renderPendulums(uint32_t now); +// Natur +void renderStorm(uint32_t now); +void renderFire(uint32_t now); +void renderRain(uint32_t now); +void renderAurora(uint32_t now); +void renderOcean(uint32_t now); +void renderFireflies(uint32_t now); +void renderSunrise(uint32_t now); +void renderMeadow(uint32_t now); +void renderWaterfall(uint32_t now); +void renderVolcano(uint32_t now); +void renderAutumn(uint32_t now); +void renderShootingStars(uint32_t now); +// Fraktal +void renderMandelbrot(uint32_t now); +void renderJulia(uint32_t now); +void renderBitPattern(uint32_t now); +void renderFractalTree(uint32_t now); +void renderChaosGame(uint32_t now); +void renderLorenz(uint32_t now); +void renderThomas(uint32_t now); +void renderLife3d(uint32_t now); +void renderAutomaton(uint32_t now); +void renderHilbert(uint32_t now); +void renderCrystal(uint32_t now); +void renderFractalClouds(uint32_t now); +// Ruhe +void renderBreathe(uint32_t now); +void renderCandle(uint32_t now); +void renderStarrySky(uint32_t now); +void renderMoonlight(uint32_t now); +void renderColorCycle(uint32_t now); +void renderEmbers(uint32_t now); +void renderDeepSea(uint32_t now); +void renderDusk(uint32_t now); +void renderTide(uint32_t now); +void renderLanterns(uint32_t now); +void renderHourglass(uint32_t now); +void renderPastel(uint32_t now); diff --git a/cube.ino b/cube.ino index 6fe43a1..b55fd46 100644 --- a/cube.ino +++ b/cube.ino @@ -1,7 +1,7 @@ // 5x5x5 RGB-LED-Würfel – Demo // // Die Effekte (effects.cpp) laufen nacheinander in Endlosschleife und werden -// weich überblendet – jeweils innerhalb ihrer Kategorie (z. B. Weihnachten oder Musik). +// weich überblendet – jeweils innerhalb ihrer Kategorie (z. B. Festtage oder Musik). // Taster 1: nächster Effekt, Taster 2: Helligkeit. // Klatschen löst in jedem Effekt einen Blitz aus (audio.cpp). // Steuerung per REST-API im WLAN: http://cube.local/api/... (web.cpp) @@ -27,17 +27,19 @@ void setLevel(uint8_t l) { // Kategorien in der Reihenfolge der App (linke Spalte). Enum und Tabelle // gehören zusammen: neue Kategorie an beiden Stellen an derselben Position eintragen. -enum : uint8_t { FLASH, WEIHNACHTEN, SILVESTER, MUSIK, FLOATING }; +enum : uint8_t { FLASH, FESTTAGE, MUSIK, FLOATING, NATUR, FRAKTAL, RUHE }; struct Category { const char *id; // feste Kennung für die API const char *name; }; constexpr Category CATEGORIES[] = { - {"flash", "Flash"}, - {"weihnachten", "Weihnachten"}, - {"silvester", "Silvester"}, - {"musik", "Musik"}, // reagieren auf das Mikrofon - {"floating", "Floating"}, + {"flash", "Flash"}, + {"festtage", "Festtage"}, // Weihnachten und Silvester + {"musik", "Musik"}, // reagieren auf das Mikrofon + {"floating", "Floating"}, + {"natur", "Natur"}, + {"fraktal", "Fraktal"}, + {"ruhe", "Ruhe"}, // sehr ruhig und langsam }; constexpr uint8_t NUM_CATEGORIES = sizeof(CATEGORIES) / sizeof(CATEGORIES[0]); constexpr uint8_t SLOTS = 12; // so viele Plätze hat die App je Kategorie @@ -49,26 +51,99 @@ struct Effect { uint32_t ms; uint8_t category; }; -// Innerhalb einer Kategorie laufen die Effekte in dieser Reihenfolge +// Innerhalb einer Kategorie laufen die Effekte in dieser Reihenfolge. +// Der erste Eintrag läuft nach dem Einschalten. constexpr Effect EFFECTS[] = { - {"gewitter", "Gewitter", renderStorm, 40000, FLASH}, - {"wuerfel", "Würfel im Würfel", renderShells, 20000, FLASH}, - {"feuer", "Feuer", renderFire, 20000, FLASH}, - {"matrix", "Matrix", renderMatrix, 20000, FLASH}, - {"flummis", "Flummis", renderBounce, 20000, FLASH}, - {"schnee", "Schnee", renderSnow, 25000, WEIHNACHTEN}, - {"glitzer", "Glitzer", renderGlitter, 20000, WEIHNACHTEN}, - {"feuerwerk", "Feuerwerk", renderFireworks, 25000, SILVESTER}, - {"spektrum", "Spektrum", renderSpectrum, 30000, MUSIK}, - {"puls", "Puls", renderPulse, 30000, MUSIK}, - {"schockwelle", "Schockwelle", renderShockwave, 30000, MUSIK}, - {"klangschichten", "Klangschichten", renderSoundLayers, 30000, MUSIK}, - {"klangwelle", "Klangwelle", renderSoundWave, 30000, MUSIK}, - {"disko", "Disko", renderDisco, 30000, MUSIK}, - {"regenbogen", "Regenbogen", renderRainbow, 20000, FLOATING}, - {"lavalampe", "Lavalampe", renderLava, 25000, FLOATING}, - {"sinuswelle", "Sinuswelle", renderWave, 21000, FLOATING}, - {"doppelhelix", "Doppelhelix", renderHelix, 20000, FLOATING}, + {"gewitter", "Gewitter", renderStorm, 40000, NATUR}, + {"feuer", "Feuer", renderFire, 20000, NATUR}, + {"regen", "Regen", renderRain, 25000, NATUR}, + {"polarlicht", "Polarlicht", renderAurora, 30000, NATUR}, + {"ozean", "Ozean", renderOcean, 25000, NATUR}, + {"gluehwuermchen", "Glühwürmchen", renderFireflies, 30000, NATUR}, + {"sonnenaufgang", "Sonnenaufgang", renderSunrise, 40000, NATUR}, + {"blumenwiese", "Blumenwiese", renderMeadow, 30000, NATUR}, + {"wasserfall", "Wasserfall", renderWaterfall, 25000, NATUR}, + {"vulkan", "Vulkan", renderVolcano, 30000, NATUR}, + {"herbstlaub", "Herbstlaub", renderAutumn, 30000, NATUR}, + {"sternschnuppen", "Sternschnuppen", renderShootingStars, 30000, NATUR}, + + {"wuerfel", "Würfel im Würfel", renderShells, 20000, FLASH}, + {"matrix", "Matrix", renderMatrix, 20000, FLASH}, + {"flummis", "Flummis", renderBounce, 20000, FLASH}, + {"blitzlicht", "Blitzlicht", renderStrobe, 15000, FLASH}, + {"scanner", "Scanner", renderScanner, 20000, FLASH}, + {"kometen", "Kometen", renderComets, 20000, FLASH}, + {"schlange", "Schlange", renderSnake, 25000, FLASH}, + {"rotor", "Rotor", renderRotor, 20000, FLASH}, + {"stapeln", "Stapeln", renderStack, 40000, FLASH}, + {"blaulicht", "Blaulicht", renderPolice, 15000, FLASH}, + {"pixelsturm", "Pixelsturm", renderPixelStorm, 20000, FLASH}, + {"laser", "Laser", renderLaser, 20000, FLASH}, + + {"weihnachtsbaum", "Weihnachtsbaum", renderTree, 40000, FESTTAGE}, + {"adventskranz", "Adventskranz", renderWreath, 40000, FESTTAGE}, + {"schnee", "Schnee", renderSnow, 25000, FESTTAGE}, + {"lichterkette", "Lichterkette", renderFairyLights, 30000, FESTTAGE}, + {"weihnachtsstern", "Weihnachtsstern", renderXmasStar, 25000, FESTTAGE}, + {"geschenk", "Geschenk", renderGift, 24000, FESTTAGE}, + {"zuckerstange", "Zuckerstange", renderCandyCane, 20000, FESTTAGE}, + {"glitzer", "Glitzer", renderGlitter, 20000, FESTTAGE}, + {"countdown", "Countdown", renderCountdown, 30000, FESTTAGE}, + {"feuerwerk", "Feuerwerk", renderFireworks, 25000, FESTTAGE}, + {"wunderkerze", "Wunderkerze", renderSparkler, 20000, FESTTAGE}, + {"sekt", "Sekt", renderBubbly, 25000, FESTTAGE}, + + {"spektrum", "Spektrum", renderSpectrum, 30000, MUSIK}, + {"puls", "Puls", renderPulse, 30000, MUSIK}, + {"schockwelle", "Schockwelle", renderShockwave, 30000, MUSIK}, + {"klangschichten", "Klangschichten", renderSoundLayers, 30000, MUSIK}, + {"klangwelle", "Klangwelle", renderSoundWave, 30000, MUSIK}, + {"disko", "Disko", renderDisco, 30000, MUSIK}, + {"pegel", "Pegel", renderVu, 30000, MUSIK}, + {"beatebenen", "Beat-Ebenen", renderBeatPlanes, 30000, MUSIK}, + {"klangwuerfel", "Klangwürfel", renderSoundCube, 30000, MUSIK}, + {"funkenregen", "Funkenregen", renderSparkRain, 30000, MUSIK}, + {"oszilloskop", "Oszilloskop", renderScope, 30000, MUSIK}, + {"ringe", "Ringe", renderRings, 30000, MUSIK}, + + {"regenbogen", "Regenbogen", renderRainbow, 20000, FLOATING}, + {"lavalampe", "Lavalampe", renderLava, 25000, FLOATING}, + {"sinuswelle", "Sinuswelle", renderWave, 21000, FLOATING}, + {"doppelhelix", "Doppelhelix", renderHelix, 20000, FLOATING}, + {"plasma", "Plasma", renderPlasma, 25000, FLOATING}, + {"seifenblasen", "Seifenblasen", renderBubbles, 30000, FLOATING}, + {"farbnebel", "Farbnebel", renderColorFog, 25000, FLOATING}, + {"metabaelle", "Metabälle", renderMetaballs, 25000, FLOATING}, + {"wirbel", "Wirbel", renderVortex, 20000, FLOATING}, + {"schwerelos", "Schwerelos", renderWeightless, 30000, FLOATING}, + {"kreisel", "Kreisel", renderRings3d, 25000, FLOATING}, + {"pendelwelle", "Pendelwelle", renderPendulums, 60000, FLOATING}, + + {"mandelbrot", "Mandelbrot", renderMandelbrot, 24000, FRAKTAL}, + {"julia", "Julia", renderJulia, 30000, FRAKTAL}, + {"bitmuster", "Bitmuster", renderBitPattern, 24000, FRAKTAL}, + {"fraktalbaum", "Fraktalbaum", renderFractalTree, 27000, FRAKTAL}, + {"chaosspiel", "Chaosspiel", renderChaosGame, 25000, FRAKTAL}, + {"schmetterling", "Schmetterling", renderLorenz, 30000, FRAKTAL}, + {"attraktor", "Attraktor", renderThomas, 30000, FRAKTAL}, + {"leben", "Leben 3D", renderLife3d, 40000, FRAKTAL}, + {"zellautomat", "Zellautomat", renderAutomaton, 35000, FRAKTAL}, + {"hilbert", "Hilbertkurve", renderHilbert, 21000, FRAKTAL}, + {"kristall", "Kristall", renderCrystal, 40000, FRAKTAL}, + {"fraktalwolken", "Fraktalwolken", renderFractalClouds, 30000, FRAKTAL}, + + {"atmen", "Atmen", renderBreathe, 60000, RUHE}, + {"kerzenschein", "Kerzenschein", renderCandle, 60000, RUHE}, + {"sternenhimmel", "Sternenhimmel", renderStarrySky, 60000, RUHE}, + {"mondlicht", "Mondlicht", renderMoonlight, 60000, RUHE}, + {"farbwechsel", "Farbwechsel", renderColorCycle, 90000, RUHE}, + {"glut", "Glut", renderEmbers, 60000, RUHE}, + {"tiefsee", "Tiefsee", renderDeepSea, 60000, RUHE}, + {"daemmerung", "Dämmerung", renderDusk, 60000, RUHE}, + {"gezeiten", "Gezeiten", renderTide, 60000, RUHE}, + {"laternen", "Laternen", renderLanterns, 60000, RUHE}, + {"sanduhr", "Sanduhr", renderHourglass, 65000, RUHE}, + {"pastell", "Pastell", renderPastel, 60000, RUHE}, }; const uint8_t NUM_EFFECTS = sizeof(EFFECTS) / sizeof(EFFECTS[0]); diff --git a/docs/api.md b/docs/api.md index 01f8e00..65f9408 100644 --- a/docs/api.md +++ b/docs/api.md @@ -86,11 +86,13 @@ curl -4 http://cube.local/api/categories ```json [ - {"id": "flash", "name": "Flash"}, - {"id": "weihnachten", "name": "Weihnachten"}, - {"id": "silvester", "name": "Silvester"}, - {"id": "musik", "name": "Musik"}, - {"id": "floating", "name": "Floating"} + {"id": "flash", "name": "Flash"}, + {"id": "festtage", "name": "Festtage"}, + {"id": "musik", "name": "Musik"}, + {"id": "floating", "name": "Floating"}, + {"id": "natur", "name": "Natur"}, + {"id": "fraktal", "name": "Fraktal"}, + {"id": "ruhe", "name": "Ruhe"} ] ``` @@ -107,8 +109,8 @@ curl -4 http://cube.local/api/effects ```json [ - {"id": "gewitter", "name": "Gewitter", "category": "flash"}, - {"id": "wuerfel", "name": "Würfel im Würfel", "category": "flash"}, + {"id": "gewitter", "name": "Gewitter", "category": "natur"}, + {"id": "feuer", "name": "Feuer", "category": "natur"}, … {"id": "spektrum", "name": "Spektrum", "category": "musik"}, … diff --git a/docs/img/app.png b/docs/img/app.png index 4b404bb..be79096 100644 Binary files a/docs/img/app.png and b/docs/img/app.png differ diff --git a/effects.cpp b/effects.cpp index 99cb866..23b37ce 100644 --- a/effects.cpp +++ b/effects.cpp @@ -1,6 +1,7 @@ -#include "cube.h" +#include "fx.h" -const float MID = (CUBE_SIZE - 1) / 2.0f; // Mitte des Würfels +bool fresh = true; +uint32_t fxStart = 0; float rnd(float a, float b) { return a + (b - a) * random16() / 65535.0f; @@ -13,14 +14,20 @@ void plot(float x, float y, float z, const CRGB &c) { at(ix, iy, iz) += c; } +// Verteilt einen Punkt anteilig auf die bis zu 8 umliegenden LEDs (weiche Bewegung). +void plotSoft(float x, float y, float z, const CRGB &c) { + int x0 = floorf(x), y0 = floorf(y), z0 = floorf(z); + float fx = x - x0, fy = y - y0, fz = z - z0; + for (uint8_t i = 0; i < 8; i++) { + int xi = x0 + (i & 1), yi = y0 + (i >> 1 & 1), zi = z0 + (i >> 2); + if (!inCube(xi, yi, zi)) continue; + float w = (i & 1 ? fx : 1 - fx) * (i & 2 ? fy : 1 - fy) * (i & 4 ? fz : 1 - fz); + if (w > 0.02f) at(xi, yi, zi) += CRGB(c).nscale8(uint8_t(sqrtf(w) * 255)); // Wurzel: wirkt gleichmäßiger hell + } +} + // --- 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) { @@ -582,6 +589,8 @@ void drawSpecials(uint32_t now) { // --- Effektwechsel --------------------------------------------------------- void resetEffects() { + fresh = true; + fxStart = millis(); for (Particle &p : particles) p.life = 0; for (Shock &w : shocks) w.start = 0; audioBeat(); // alten Beat verwerfen diff --git a/fx.h b/fx.h new file mode 100644 index 0000000..fa64714 --- /dev/null +++ b/fx.h @@ -0,0 +1,70 @@ +#pragma once + +// Gemeinsame Hilfen für die Effekte (effects.cpp und fx_*.cpp) + +#include "cube.h" + +constexpr float MID = (CUBE_SIZE - 1) / 2.0f; // Mitte des Würfels + +// Schleife über alle LEDs: z = Etage, x/y = Position in der Etage +#define FOR_XYZ \ + 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++) + +// true im ersten Bild nach einem Effektwechsel: Effekte mit eigenem Zustand +// setzen ihn dann zurück und schreiben fresh = false. +extern bool fresh; +extern uint32_t fxStart; // millis() beim Effektwechsel + +float rnd(float a, float b); // Zufallszahl a..b +void plot(float x, float y, float z, const CRGB &c); // nächste LED, addiert +void plotSoft(float x, float y, float z, const CRGB &c); // auf die 8 Nachbar-LEDs verteilt + +inline bool inCube(int x, int y, int z) { + return x >= 0 && y >= 0 && z >= 0 && x < CUBE_SIZE && y < CUBE_SIZE && z < NUM_LAYERS; +} + +inline float dist3(float x, float y, float z, float cx, float cy, float cz) { + return sqrtf(sq(x - cx) + sq(y - cy) + sq(z - cz)); +} + +// Abstand von der senkrechten Mittelachse +inline float distAxis(float x, float y) { return hypotf(x - MID, y - MID); } + +// Größter Abstand zur Mitte je Achse: 0 = Mitte, 1 = innere Schale, 2 = Außenhaut +inline uint8_t shell(uint8_t x, uint8_t y, uint8_t z) { + return max(max(abs(x - 2), abs(y - 2)), abs(z - 2)); +} + +// Die 16 LEDs am Rand einer Etage, im Kreis herum (i = 0..15) +inline void ringPos(uint8_t i, uint8_t &x, uint8_t &y) { + i %= 16; + if (i < 4) { x = i; y = 0; } + else if (i < 8) { x = 4; y = i - 4; } + else if (i < 12) { x = 12 - i; y = 4; } + else { x = 0; y = 16 - i; } +} + +// Kommazahl als Farbton: läuft wie uint8_t über (direktes uint8_t(f) wäre außerhalb 0..255 undefiniert) +inline uint8_t wrap8(float f) { return uint8_t(int32_t(f)); } + +// Weiche Ein-/Ausblendkurve 0..1 -> 0..1 +inline float smooth(float t) { + t = constrain(t, 0.0f, 1.0f); + return t * t * (3 - 2 * t); +} + +// --- Partikel (gemeinsamer Vorrat, wird beim Effektwechsel geleert) ---------- + +struct Particle { + float x, y, z, vx, vy, vz; + CRGB color; + uint8_t life; // 0 = frei, sonst Helligkeit +}; +const uint8_t MAX_PARTICLES = 48; +extern Particle particles[MAX_PARTICLES]; + +void spawnParticle(float x, float y, float z, float vx, float vy, float vz, const CRGB &color); +void moveParticles(float gravity, float drag, uint8_t fade); +void drawParticles(); diff --git a/fx_fest.cpp b/fx_fest.cpp new file mode 100644 index 0000000..8f5fb3f --- /dev/null +++ b/fx_fest.cpp @@ -0,0 +1,256 @@ +// Kategorie Festtage: Weihnachten und Silvester +// (dazu Schnee, Glitzer und Feuerwerk aus effects.cpp) + +#include "fx.h" + +// --- Weihnachtsbaum: grüner Kegel mit Kugeln, Stern an der Spitze, leiser Schnee -- + +static bool isTree(int x, int y, int z) { + float d = distAxis(x, y); + switch (z) { + case 1: return d <= 2.3f; // 21 LEDs + case 2: return d <= 2.0f; // 13 LEDs + case 3: return d <= 1.0f; // 5 LEDs + default: return false; // unten Stamm, oben Stern + } +} + +struct Bauble { + uint8_t x, y, z, phase; + CRGB color; +}; +static Bauble baubles[10]; + +static void placeBauble(Bauble &b) { + static const CRGB COLORS[] = {CRGB(255, 0, 0), CRGB(255, 170, 0), CRGB(0, 60, 255), CRGB(200, 0, 160), CRGB(255, 255, 255)}; + do { + b.x = random8(CUBE_SIZE); + b.y = random8(CUBE_SIZE); + b.z = random8(1, 4); + } while (!isTree(b.x, b.y, b.z) || (b.x == 2 && b.y == 2 && b.z < 3)); // nicht im Stamm-Inneren + b.color = COLORS[random8(5)]; + b.phase = random8(); +} + +void renderTree(uint32_t now) { + static uint32_t lastMove = 0; + if (fresh) { + fresh = false; + for (Bauble &b : baubles) placeBauble(b); + lastMove = now; + } + if (now - lastMove > 1500) { // ab und zu wandert ein Licht + lastMove = now; + placeBauble(baubles[random8(10)]); + } + + FastLED.clear(); + at(2, 2, 0) = CRGB(brightness / 2, brightness / 5, 0); // Stamm + FOR_XYZ { + if (!isTree(x, y, z)) continue; + uint8_t n = inoise8(x * 60, y * 60, z * 60 + now / 12); + at(x, y, z) = CHSV(96, 255, scale8(brightness, 140 + n / 3)); + } + for (Bauble &b : baubles) { + uint8_t v = 110 + scale8(sin8(now / 6 + b.phase), 145); + at(b.x, b.y, b.z) = CRGB(b.color).nscale8(scale8(highlight, v)); + } + // Stern: Mitte hell und funkelnd, die Zacken abwechselnd + uint8_t tw = sin8(now / 3); + at(2, 2, TOP) = CRGB(highlight, scale8(highlight, 200), scale8(highlight, tw / 3)); + for (uint8_t i = 0; i < 4; i++) { + static const int8_t DX[] = {1, -1, 0, 0}, DY[] = {0, 0, 1, -1}; + uint8_t v = scale8(highlight, 80 + scale8(sin8(now / 4 + i * 64), 120)); + at(2 + DX[i], 2 + DY[i], TOP) = CRGB(v, scale8(v, 170), 0); + } + if (random8() < 4) at(2, 2, TOP) = CRGB::White; + + // leiser Schnee rundherum + if (random8() < 6) spawnParticle(rnd(0, TOP), rnd(0, TOP), TOP + 0.4f, 0, 0, -rnd(0.015f, 0.025f), CRGB(brightness, brightness, brightness)); + moveParticles(0, 1, 0); + for (const Particle &p : particles) { + int x = lroundf(p.x), y = lroundf(p.y), z = lroundf(p.z); + if (p.life && !isTree(x, y, z) && !(x == 2 && y == 2)) plot(p.x, p.y, p.z, p.color); + } +} + +// --- Adventskranz: grüner Kranz, die Kerzen gehen nacheinander an -------------- + +void renderWreath(uint32_t now) { + static const uint8_t CX[] = {1, 3, 3, 1}, CY[] = {1, 1, 3, 3}; + static uint8_t flicker[4]; + FastLED.clear(); + for (uint8_t y = 0; y < CUBE_SIZE; y++) + for (uint8_t x = 0; x < CUBE_SIZE; x++) { + float d = distAxis(x, y); + if (d < 1 || d > 2.6f) continue; + bool berry = (x * 7 + y * 3) % 5 == 0; + uint8_t n = inoise8(x * 70, y * 70, now / 20); + at(x, y, 0) = berry ? CRGB(scale8(brightness, 220), 0, 0) : CRGB(CHSV(90, 255, scale8(brightness, 120 + n / 3))); + } + uint8_t lit = 1 + (now - fxStart) / 8000 % 4; // alle 8 s eine Kerze mehr + for (uint8_t i = 0; i < 4; i++) { + CRGB wax(scale8(brightness, 200), 0, brightness / 10); + at(CX[i], CY[i], 1) = at(CX[i], CY[i], 2) = wax; + if (i >= lit) continue; + flicker[i] = (flicker[i] * 3 + random8(140, 255)) / 4; + uint8_t f = scale8(highlight, flicker[i]); + at(CX[i], CY[i], 3) = CRGB(f, scale8(f, 140), scale8(f, 25)); + at(CX[i], CY[i], 4) = CRGB(f / 6, f / 12, 0); // Schein über der Flamme + } +} + +// --- Lichterkette: bunte Birnen winden sich als Spirale um den Würfel ----------- + +void renderFairyLights(uint32_t now) { + static const CRGB BULBS[] = {CRGB(255, 0, 0), CRGB(0, 200, 0), CRGB(0, 60, 255), CRGB(255, 160, 0), CRGB(200, 0, 200)}; + uint32_t t = now - fxStart; + bool chase = t / 6000 % 2 == 0; // abwechselnd Lauflicht und Blinken + FastLED.clear(); + for (uint8_t z = 0; z < NUM_LAYERS; z++) + for (uint8_t i = 0; i < 16; i++) { + uint8_t x, y; + ringPos(i + z * 3, x, y); // pro Etage versetzt: eine Spirale + uint8_t k = z * 16 + i; + uint8_t v = chase ? 60 + scale8(sin8(k * 24 - t / 3), 195) + : ((k + t / 600) % 2 ? 255 : 50); + at(x, y, z) = CRGB(BULBS[k % 5]).nscale8(scale8(highlight, v)); + } +} + +// --- Countdown: 5 Etagen gehen im Sekundentakt aus, dann Explosion und Feuerwerk -- + +void renderCountdown(uint32_t now) { + static bool boom = false; + if (fresh) boom = false; + uint32_t t = (now - fxStart) % 15000; + if (t < 5000) { + fresh = false; + boom = false; + uint8_t layers = 5 - t / 1000; + uint16_t inSecond = t % 1000; + FastLED.clear(); + FOR_XYZ { + if (z >= layers) continue; + if (z == layers - 1 && inSecond > 750) // oberste Etage blinkt, bevor sie ausgeht + at(x, y, z) = (inSecond / 80) % 2 ? CRGB(highlight, highlight, highlight) : CRGB::Black; + else + at(x, y, z) = CHSV(28 + z * 6, 200, min(255, brightness * 2)); + } + } else { + if (!boom) { + boom = true; + triggerExplosion(now); + } + renderFireworks(now); + } +} + +// --- Wunderkerze: sprüht Funken und brennt langsam von oben nach unten ab ------ + +void renderSparkler(uint32_t now) { + float burn = ((now - fxStart) % 20000) / 20000.0f; + float head = TOP - burn * 3.2f; + FastLED.clear(); + for (uint8_t z = 0; z < NUM_LAYERS && z < head; z++) at(2, 2, z) = CRGB(brightness / 4, brightness / 4, brightness / 4); // Draht + CRGB gold(highlight, scale8(highlight, 190), scale8(highlight, 70)); + for (uint8_t i = random8(2, 5); i > 0; i--) + spawnParticle(MID, MID, head, rnd(-0.16f, 0.16f), rnd(-0.16f, 0.16f), rnd(-0.06f, 0.16f), + random8(3) ? gold : CRGB(highlight, highlight, highlight)); + moveParticles(0.01f, 0.9f, 22); + drawParticles(); + uint8_t f = random8(180, 255); + plot(MID, MID, head, CRGB(scale8(highlight, f), scale8(highlight, f), scale8(highlight, f * 3 / 4))); +} + +// --- Geschenk: Paket mit goldener Schleife, wechselt alle 8 s die Farbe ---------- + +void renderGift(uint32_t now) { + uint32_t t = now - fxStart; + uint8_t hue = (t / 8000) * 85; // rot, grün, blau ... + uint16_t inSlot = t % 8000; + uint8_t fade = inSlot < 1020 ? inSlot / 4 : 255; // in der ersten Sekunde überblenden + uint8_t v = min(255, brightness * 2); + CRGB box = blend(CRGB(CHSV(hue - 85, 255, v)), CRGB(CHSV(hue, 255, v)), fade); + FastLED.clear(); + FOR_XYZ { + if (z == TOP) continue; + bool hull = x == 0 || x == TOP || y == 0 || y == TOP || z == 0 || z == TOP - 1; + if (!hull) continue; + bool ribbon = x == 2 || y == 2; + if (ribbon) { + uint8_t v = random8() < 8 ? 255 : 170; // glitzert + at(x, y, z) = CRGB(scale8(highlight, v), scale8(highlight, v * 3 / 4), 0); + } else { + at(x, y, z) = box; + } + } + // Schleife obendrauf + uint8_t pulse = 160 + scale8(sin8(t / 5), 95); + for (uint8_t i = 0; i < 5; i++) { + static const int8_t DX[] = {0, 1, -1, 0, 0}, DY[] = {0, 0, 0, 1, -1}; + uint8_t v = scale8(highlight, i ? pulse : 255); + at(2 + DX[i], 2 + DY[i], TOP) = CRGB(v, scale8(v, 190), 0); + } +} + +// --- Zuckerstange: rot-weiße Streifen drehen sich als Spirale nach oben ---------- + +void renderCandyCane(uint32_t now) { + float t = (now - fxStart) * 0.003f; + uint8_t v = min(255, brightness * 2); + CRGB red(v, 0, 0), white(scale8(v, 200), scale8(v, 200), scale8(v, 200)); + FastLED.clear(); + for (uint8_t z = 0; z < NUM_LAYERS; z++) + for (uint8_t i = 0; i < 16; i++) { + uint8_t x, y; + ringPos(i, x, y); + float s = sinf((i + z * 2) * (TWO_PI / 8) - t); + at(x, y, z) = blend(red, white, uint8_t(smooth(s * 2 + 0.5f) * 255)); + } +} + +// --- Sekt: goldene Flüssigkeit, Perlen steigen auf ------------------------------ + +void renderBubbly(uint32_t now) { + float t = (now - fxStart) * 0.001f; + float level = 2.6f + 0.2f * sinf(t * 2); + FastLED.clear(); + FOR_XYZ { + float f = constrain(level - z + 0.5f, 0.0f, 1.0f); + if (f > 0) at(x, y, z) = CRGB(brightness, scale8(brightness, 170), brightness / 8).nscale8(uint8_t(f * 255)); + if (fabsf(z - level) < 0.6f && random8() < 30) at(x, y, z) += CRGB(brightness / 2, brightness / 2, brightness / 3); // Schaum + } + if (random8() < 70) + spawnParticle(random8(CUBE_SIZE), random8(CUBE_SIZE), 0, 0, 0, rnd(0.03f, 0.07f), CRGB(highlight, highlight, scale8(highlight, 150))); + for (Particle &p : particles) { + if (!p.life) continue; + p.vx = rnd(-0.01f, 0.01f); + p.vy = rnd(-0.01f, 0.01f); + if (p.z > level) p.life = 0; // an der Oberfläche geplatzt + } + moveParticles(0, 1, 0); + drawParticles(); +} + +// --- Weihnachtsstern: Strahlen in alle Richtungen, Achsen und Diagonalen im Wechsel -- + +void renderXmasStar(uint32_t now) { + uint32_t t = now - fxStart; + uint8_t swap = sin8(t / 20); + FastLED.clear(); + FOR_XYZ { + int dx = abs(x - 2), dy = abs(y - 2), dz = abs(z - 2); + uint8_t nonzero = (dx > 0) + (dy > 0) + (dz > 0); + int m = max(max(dx, dy), dz); + bool axis = nonzero <= 1; + bool diagonal = nonzero >= 2 && (dx == 0 || dx == m) && (dy == 0 || dy == m) && (dz == 0 || dz == m); + if (!axis && !diagonal) continue; + float r = sqrtf(dx * dx + dy * dy + dz * dz); + uint8_t wave = sin8(wrap8(r * 50) - t / 4); + uint8_t mix = axis ? swap : 255 - swap; + uint8_t v = scale8(scale8(highlight, 90 + scale8(wave, 165)), mix); + at(x, y, z) = CRGB(v, scale8(v, 200), scale8(v, uint8_t(r * 50))); // außen weißlicher + } + at(2, 2, 2) = CRGB(highlight, highlight, highlight); +} diff --git a/fx_flash.cpp b/fx_flash.cpp new file mode 100644 index 0000000..7d61bbf --- /dev/null +++ b/fx_flash.cpp @@ -0,0 +1,272 @@ +// 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, 40); + 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, 80); + 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; +} diff --git a/fx_floating.cpp b/fx_floating.cpp new file mode 100644 index 0000000..e8faa0a --- /dev/null +++ b/fx_floating.cpp @@ -0,0 +1,173 @@ +// Kategorie Floating: fließende, schwebende Effekte +// (dazu Regenbogen, Lavalampe, Sinuswelle und Doppelhelix aus effects.cpp) + +#include "fx.h" + +// --- Plasma: überlagerte Sinuswellen als fließendes Farbfeld -------------------- + +void renderPlasma(uint32_t now) { + float t = (now - fxStart) * 0.001f; + FOR_XYZ { + float v = sinf(x * 0.9f + t) + sinf(y * 0.8f - t * 1.3f) + sinf(z * 0.7f + t * 0.7f) + + sinf(dist3(x, y, z, MID + 1.5f * sinf(t * 0.6f), MID, MID) * 1.5f - t * 2); + at(x, y, z) = CHSV(wrap8(v * 40 + t * 20), 240, brightness); + } +} + +// --- Seifenblasen: schillernde Kugelschalen steigen langsam auf ------------------ + +struct Bubble { + float x, y, z, r, vz, phase; + uint8_t hue; +}; +static Bubble bubbles[3]; + +static void newBubble(Bubble &b, bool anywhere) { + b.r = rnd(1.0f, 1.8f); + b.x = rnd(1, 3); + b.y = rnd(1, 3); + b.z = anywhere ? rnd(-b.r, TOP) : -b.r - rnd(0, 2); + b.vz = rnd(0.008f, 0.015f); + b.phase = rnd(0, TWO_PI); + b.hue = random8(); +} + +void renderBubbles(uint32_t now) { + if (fresh) { + fresh = false; + for (Bubble &b : bubbles) newBubble(b, true); + } + float t = (now - fxStart) * 0.001f; + FastLED.clear(); + for (Bubble &b : bubbles) { + b.z += b.vz; + float bx = b.x + 0.5f * sinf(t * 0.7f + b.phase), by = b.y + 0.5f * cosf(t * 0.5f + b.phase); + if (b.z - b.r > TOP + 0.5f) newBubble(b, false); + FOR_XYZ { + float d = dist3(x, y, z, bx, by, b.z); + float f = 1 - fabsf(d - b.r) / 0.7f; + if (f > 0) at(x, y, z) += CHSV(b.hue + wrap8((z - b.z) * 40 + t * 30), 170, uint8_t(f * highlight * 0.6f)); + } + } +} + +// --- Farbnebel: bunte Wolken ziehen durch den Würfel --------------------------- + +void renderColorFog(uint32_t now) { + uint32_t t = now - fxStart; + FOR_XYZ { + uint8_t hue = inoise8(x * 45, y * 45 + t / 12, z * 45 + t / 9); + uint8_t v = inoise8(x * 35 + 5000, y * 35 - t / 14, z * 35 + t / 11); + v = qsub8(v, 70); + v = qadd8(v, v); + at(x, y, z) = CHSV(hue * 2 + t / 80, 230, scale8(v, min(255, brightness * 3))); + } +} + +// --- Metabälle: drei weiche Farbkugeln, die ineinander verschmelzen ------------- + +void renderMetaballs(uint32_t now) { + float t = (now - fxStart) * 0.001f; + float px[3], py[3], pz[3]; + CRGB col[3]; + for (uint8_t i = 0; i < 3; i++) { + px[i] = MID + 1.7f * sinf(t * (0.5f + 0.13f * i) + i * 2); + py[i] = MID + 1.7f * sinf(t * (0.37f + 0.11f * i) + i); + pz[i] = MID + 1.7f * sinf(t * (0.43f + 0.07f * i) + i * 4); + col[i] = CHSV(wrap8(i * 85 + t * 8), 255, 255); + } + FOR_XYZ { + float sum = 0, r = 0, g = 0, b = 0; + for (uint8_t i = 0; i < 3; i++) { + float f = 1.2f / (sq(x - px[i]) + sq(y - py[i]) + sq(z - pz[i]) + 0.4f); + sum += f; + r += f * col[i].r; + g += f * col[i].g; + b += f * col[i].b; + } + float v = smooth((sum - 0.35f) * 1.5f) * min(255, brightness * 3) / 255.0f / sum; + at(x, y, z) = CRGB(min(255.0f, r * v), min(255.0f, g * v), min(255.0f, b * v)); + } +} + +// --- Wirbel: Farben drehen sich um die Mittelachse, oben schneller als unten ----- + +void renderVortex(uint32_t now) { + float t = (now - fxStart) * 0.001f; + FOR_XYZ { + float a = atan2f(y - MID, x - MID); + float r = distAxis(x, y); + float hue = a * (256 / TWO_PI) * 2 + r * 30 - t * (40 + z * 12); + at(x, y, z) = CHSV(wrap8(hue), 230, scale8(brightness, 140 + uint8_t(r * 40))); + } +} + +// --- Schwerelos: Lichtpunkte treiben langsam durch den Raum und ziehen Spuren ---- + +struct Drifter { + float p[3], v[3]; + uint8_t hue; +}; +static Drifter drifters[6]; + +void renderWeightless(uint32_t now) { + if (fresh) { + fresh = false; + for (Drifter &d : drifters) { + for (uint8_t i = 0; i < 3; i++) { + d.p[i] = rnd(0.5f, TOP - 0.5f); + d.v[i] = rnd(-0.02f, 0.02f); + } + d.hue = random8(); + } + } + fadeToBlackBy(leds, NUM_LEDS, 18); + for (Drifter &d : drifters) { + for (uint8_t i = 0; i < 3; i++) { + d.v[i] += rnd(-0.002f, 0.002f); + if (d.p[i] < 0.4f) d.v[i] += 0.003f; // weich vom Rand weg + if (d.p[i] > TOP - 0.4f) d.v[i] -= 0.003f; + d.v[i] = constrain(d.v[i], -0.03f, 0.03f); + d.p[i] += d.v[i]; + } + if (random8() < 20) d.hue++; + plotSoft(d.p[0], d.p[1], d.p[2], CHSV(d.hue, 190, highlight)); + } +} + +// --- Schwebende Ringe: zwei Kreise kippen und drehen sich wie ein Kreisel ------- + +// Abstand eines Punkts von einem Kreis um die Mitte (Radius R, Normale n) +static float ringDistance(float x, float y, float z, const float n[3], float R) { + float v[3] = {x - MID, y - MID, z - MID}; + float h = v[0] * n[0] + v[1] * n[1] + v[2] * n[2]; + float q = sqrtf(max(0.0f, v[0] * v[0] + v[1] * v[1] + v[2] * v[2] - h * h)); + return sqrtf(h * h + sq(q - R)); +} + +void renderRings3d(uint32_t now) { + float t = (now - fxStart) * 0.001f; + float a = t * 0.9f, b = t * 0.37f; + float n1[3] = {sinf(a) * cosf(b), sinf(a) * sinf(b), cosf(a)}; + float n2[3] = {cosf(-a * 0.8f), sinf(-a * 0.8f) * cosf(b), sinf(-a * 0.8f) * sinf(b)}; + FastLED.clear(); + FOR_XYZ { + float f1 = 1 - ringDistance(x, y, z, n1, 1.9f) / 0.7f, f2 = 1 - ringDistance(x, y, z, n2, 1.9f) / 0.7f; + if (f1 > 0) at(x, y, z) += CHSV(wrap8(t * 20), 220, uint8_t(f1 * highlight)); + if (f2 > 0) at(x, y, z) += CHSV(wrap8(t * 20 + 128), 220, uint8_t(f2 * highlight)); + } +} + +// --- Pendelwelle: 25 Pendel mit leicht verschiedenen Längen bilden Muster ------- +// Nach 60 s schwingen alle wieder im Gleichtakt. + +void renderPendulums(uint32_t now) { + float t = ((now - fxStart) % 60000) / 1000.0f; + FastLED.clear(); + for (uint8_t z = 0; z < NUM_LAYERS; z++) + for (uint8_t x = 0; x < CUBE_SIZE; x++) { + uint8_t k = z * CUBE_SIZE + x; + float y = MID + MID * cosf(TWO_PI * (20 + k) * t / 60); + plotSoft(x, y, z, CHSV(k * 10, 220, highlight)); + } +} diff --git a/fx_fraktal.cpp b/fx_fraktal.cpp new file mode 100644 index 0000000..744bbaa --- /dev/null +++ b/fx_fraktal.cpp @@ -0,0 +1,364 @@ +// Kategorie Fraktal: Fraktale, seltsame Attraktoren und Zellautomaten + +#include "fx.h" + +// Farbe für Fraktal-Iterationen: innen dunkel, außen bunt +static CRGB iterColor(uint8_t i, uint8_t maxIter, uint8_t shift) { + if (i >= maxIter) return CRGB(0, 0, brightness / 10); + return CHSV(i * 12 + shift, 255, scale8(min(255, brightness * 3), 90 + min(165, i * 20))); +} + +// --- Mandelbrot: Zoom ins Seepferdchental; jede Etage eine Stufe tiefer --------- + +void renderMandelbrot(uint32_t now) { + const float CX = -0.743643887f, CY = 0.131825904f; + float t = ((now - fxStart) % 24000) / 1000.0f; + float scale = 1.6f * powf(0.7f, t); // in 24 s rund 5000-fach + uint8_t maxIter = 30 + t * 3; + FOR_XYZ { + float s = scale * powf(0.72f, z); + float cr = CX + (x - MID) / MID * s, ci = CY + (y - MID) / MID * s; + float zr = 0, zi = 0; + uint8_t i = 0; + for (; i < maxIter && zr * zr + zi * zi < 4; i++) { + float tmp = zr * zr - zi * zi + cr; + zi = 2 * zr * zi + ci; + zr = tmp; + } + at(x, y, z) = iterColor(i, maxIter, t * 10); + } +} + +// --- Julia: der Parameter wandert im Kreis; jede Etage ist ein Stück voraus ----- + +void renderJulia(uint32_t now) { + float t = (now - fxStart) * 0.00025f; + const uint8_t MAX_ITER = 24; + FOR_XYZ { + float a = t + z * 0.06f; + float cr = 0.7885f * cosf(a), ci = 0.7885f * sinf(a); + float zr = (x - MID) / MID * 1.5f, zi = (y - MID) / MID * 1.5f; + uint8_t i = 0; + for (; i < MAX_ITER && zr * zr + zi * zi < 4; i++) { + float tmp = zr * zr - zi * zi + cr; + zi = 2 * zr * zi + ci; + zr = tmp; + } + at(x, y, z) = iterColor(i, MAX_ITER, now / 60); + } +} + +// --- Bitmuster: Sierpinski- und XOR-Muster aus den Koordinaten, die durchwandern -- + +void renderBitPattern(uint32_t now) { + uint32_t t = now - fxStart; + uint8_t mode = t / 8000 % 3; + uint8_t ox = t / 500, oy = t / 700, oz = t / 900; + FastLED.clear(); + FOR_XYZ { + uint8_t X = x + ox, Y = y + oy, Z = z + oz; + switch (mode) { + case 0: // Sierpinski-Tetraeder + if (((X & Y) | (Y & Z) | (X & Z)) % 8 == 0) at(x, y, z) = CHSV((X + Y + Z) * 10, 220, highlight); + break; + case 1: // XOR-Farben + at(x, y, z) = CHSV((X ^ Y ^ Z) * 32 + t / 30, 255, scale8(min(255, brightness * 2), sin8(((X ^ Y ^ Z) & 7) * 32 - t / 6))); + break; + default: // UND-Gitter + if ((X & Y & Z) % 4 != 0) at(x, y, z) = CHSV(160 + (X | Y | Z) * 8, 200, scale8(highlight, 200)); + break; + } + } +} + +// --- Fraktalbaum: wächst vom Stamm aus, jeder Ast teilt sich in zwei ------------- + +static int8_t treeX[NUM_LAYERS][8], treeY[NUM_LAYERS][8]; +static uint8_t treeN[NUM_LAYERS]; + +static void growTree() { + static const int8_t DIRS[8][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}, {1, 1}, {-1, -1}, {1, -1}, {-1, 1}}; + treeX[0][0] = treeX[1][0] = 2; + treeY[0][0] = treeY[1][0] = 2; + treeN[0] = treeN[1] = 1; + for (uint8_t z = 2; z < NUM_LAYERS; z++) { + treeN[z] = 0; + for (uint8_t i = 0; i < treeN[z - 1]; i++) { + uint8_t a = random8(8), b = (a + random8(1, 8)) % 8; // zwei verschiedene Richtungen + for (uint8_t d : {a, b}) { + treeX[z][treeN[z]] = constrain(treeX[z - 1][i] + DIRS[d][0], 0, TOP); + treeY[z][treeN[z]] = constrain(treeY[z - 1][i] + DIRS[d][1], 0, TOP); + treeN[z]++; + } + } + } +} + +void renderFractalTree(uint32_t now) { + static uint32_t cycleStart = 0; + static uint8_t leafHue = 0; + if (fresh || now - cycleStart > 9000) { + fresh = false; + cycleStart = now; + leafHue = random8(); + growTree(); + } + uint32_t t = now - cycleStart; + uint8_t shown = min(NUM_LAYERS, t / 600 + 1); // Etage für Etage wachsen + uint8_t fade = t < 7000 ? 255 : 255 - (t - 7000) * 255 / 2000; + FastLED.clear(); + for (uint8_t z = 0; z < shown; z++) + for (uint8_t i = 0; i < treeN[z]; i++) { + CRGB c = z < TOP ? CRGB(CHSV(20 + z * 15, 200, min(255, brightness * 2))) + : CRGB(CHSV(leafHue + i * 4, 255, scale8(highlight, 160 + scale8(sin8(now / 5 + i * 40), 95)))); + at(treeX[z][i], treeY[z][i], z) = c.nscale8(fade); + } +} + +// --- Chaosspiel: springt immer halb zu einer Ecke, es entsteht ein Sierpinski-Tetraeder + +void renderChaosGame(uint32_t now) { + static float p[3] = {MID, MID, MID}; + static const uint8_t TETRA[4][3] = {{0, 0, 0}, {TOP, TOP, 0}, {TOP, 0, TOP}, {0, TOP, TOP}}; + fadeToBlackBy(leds, NUM_LEDS, 10); + for (uint8_t n = 0; n < 6; n++) { + uint8_t k = random8(4); + for (uint8_t i = 0; i < 3; i++) p[i] = (p[i] + TETRA[k][i]) / 2; + plot(p[0], p[1], p[2], CHSV(k * 64 + now / 100, 220, scale8(highlight, 120))); + } +} + +// --- Lorenz-Attraktor: der berühmte Schmetterling, als Leuchtspur --------------- + +void renderLorenz(uint32_t now) { + static float x = 1, y = 1, z = 20; + if (fresh) { + fresh = false; + x = rnd(-1, 1); + y = 1; + z = 20; + } + fadeToBlackBy(leds, NUM_LEDS, 22); + for (uint8_t i = 0; i < 3; i++) { + const float dt = 0.006f; + float dx = 10 * (y - x), dy = x * (28 - z) - y, dz = x * y - 8.0f / 3 * z; + x += dx * dt; + y += dy * dt; + z += dz * dt; + } + plotSoft((x + 20) / 40 * TOP, (y + 27) / 54 * TOP, (z - 3) / 47 * TOP, CHSV(x > 0 ? 20 : 150 + now / 200 % 40, 220, highlight)); +} + +// --- Thomas-Attraktor: eine Spur windet sich durch alle Ecken des Würfels ------- + +void renderThomas(uint32_t now) { + static float p[3] = {1.1f, 1.1f, -0.01f}; + if (fresh) { + fresh = false; + p[0] = rnd(0.5f, 1.5f); + p[1] = 1.1f; + p[2] = -0.01f; + } + fadeToBlackBy(leds, NUM_LEDS, 14); + for (uint8_t i = 0; i < 4; i++) { + const float b = 0.208186f, dt = 0.05f; + float d[3] = {sinf(p[1]) - b * p[0], sinf(p[2]) - b * p[1], sinf(p[0]) - b * p[2]}; + for (uint8_t k = 0; k < 3; k++) p[k] += d[k] * dt; + } + plotSoft((p[0] + 4.5f) / 9 * TOP, (p[1] + 4.5f) / 9 * TOP, (p[2] + 4.5f) / 9 * TOP, + CHSV(wrap8(now / 40 + p[2] * 20), 220, highlight)); +} + +// --- Leben 3D: Conways Spiel des Lebens im Würfel (Regel B5/S4567) -------------- + +static uint8_t life[NUM_LAYERS][CUBE_SIZE][CUBE_SIZE], lifeOld[NUM_LAYERS][CUBE_SIZE][CUBE_SIZE]; + +static void seedLife() { + FOR_XYZ life[z][y][x] = random8() < 77; // 30 % + memset(lifeOld, 0, sizeof(lifeOld)); +} + +void renderLife3d(uint32_t now) { + static uint32_t last = 0; + static uint8_t gens = 0, hue = 0; + if (fresh) { + fresh = false; + seedLife(); + gens = 0; + last = now; + } + if (now - last >= 450) { + last = now; + uint8_t next[NUM_LAYERS][CUBE_SIZE][CUBE_SIZE]; + uint16_t alive = 0; + FOR_XYZ { + uint8_t n = 0; + for (int dz = -1; dz <= 1; dz++) + for (int dy = -1; dy <= 1; dy++) + for (int dx = -1; dx <= 1; dx++) + if (dx || dy || dz) n += life[(z + dz + NUM_LAYERS) % NUM_LAYERS][(y + dy + CUBE_SIZE) % CUBE_SIZE][(x + dx + CUBE_SIZE) % CUBE_SIZE]; + next[z][y][x] = life[z][y][x] ? n >= 4 && n <= 7 : n == 5; + alive += next[z][y][x]; + } + bool same = !memcmp(next, life, sizeof(life)), blink = !memcmp(next, lifeOld, sizeof(life)); + memcpy(lifeOld, life, sizeof(life)); + memcpy(life, next, sizeof(life)); + if (!alive || same || blink || ++gens > 60) { // ausgestorben oder festgefahren + seedLife(); + gens = 0; + hue += 70; + } + } + FOR_XYZ { + CRGB &led = at(x, y, z); + if (life[z][y][x]) led = CHSV(hue + z * 12, 220, lifeOld[z][y][x] ? min(255, brightness * 3) : highlight); // neu geboren: heller + else led.nscale8(200); // gestorbene glimmen kurz nach + } +} + +// --- Zellautomat: eindimensionale Regeln 30, 90, 110 und 150 um den Rand herum --- +// Jede Generation erscheint oben, ältere rutschen nach unten. + +void renderAutomaton(uint32_t now) { + static const uint8_t RULES[] = {30, 90, 110, 150}; + static uint16_t rows[NUM_LAYERS]; // Bit i = Zelle i auf dem Rand + static uint32_t last = 0; + static uint8_t gen = 0, rule = 0; + if (fresh) { + fresh = false; + memset(rows, 0, sizeof(rows)); + rows[TOP] = 1; + gen = 0; + last = now; + } + if (now - last >= 350) { + last = now; + uint16_t cur = rows[TOP], nxt = 0; + for (uint8_t i = 0; i < 16; i++) { + uint8_t l = cur >> ((i + 15) % 16) & 1, c = cur >> i & 1, r = cur >> ((i + 1) % 16) & 1; + if (RULES[rule] >> (l << 2 | c << 1 | r) & 1) nxt |= 1 << i; + } + memmove(rows, rows + 1, sizeof(rows[0]) * TOP); + rows[TOP] = nxt; + if (++gen >= 24 || !nxt || nxt == 0xFFFF) { // nächste Regel, neu mit einer Zelle + gen = 0; + rule = (rule + 1) % 4; + rows[TOP] |= 1 << random8(16); + } + } + FastLED.clear(); + for (uint8_t z = 0; z < NUM_LAYERS; z++) + for (uint8_t i = 0; i < 16; i++) { + if (!(rows[z] >> i & 1)) continue; + uint8_t x, y; + ringPos(i, x, y); + at(x, y, z) = CHSV(rule * 64 + z * 10, 230, z == TOP ? highlight : min(255, brightness * 2)); + } +} + +// --- Hilbertkurve: ein Licht zeichnet die raumfüllende Kurve (4×4×4) ------------- + +// Index 0..63 -> Koordinaten 0..3 (Algorithmus von J. Skilling, 3 Achsen, 2 Bit) +static void hilbertPoint(uint8_t h, uint8_t p[3]) { + for (uint8_t i = 0; i < 3; i++) p[i] = 0; + for (uint8_t j = 0; j < 2; j++) + for (uint8_t i = 0; i < 3; i++) p[i] |= (h >> (j * 3 + 2 - i) & 1) << j; + uint8_t t = p[2] >> 1; + for (uint8_t i = 2; i > 0; i--) p[i] ^= p[i - 1]; + p[0] ^= t; + for (uint8_t q = 2; q != 4; q <<= 1) { + uint8_t mask = q - 1; + for (int8_t i = 2; i >= 0; i--) { + if (p[i] & q) p[0] ^= mask; + else { + t = (p[0] ^ p[i]) & mask; + p[0] ^= t; + p[i] ^= t; + } + } + } +} + +void renderHilbert(uint32_t now) { + const float S = TOP / 3.0f; // 0..3 auf 0..4 strecken + float pos = ((now - fxStart) % 7000) / 7000.0f * 66; // 64 Punkte, dann kurz Pause + FastLED.clear(); + uint8_t a[3], b[3]; + for (uint8_t h = 0; h < 64 && h <= pos; h++) { + hilbertPoint(h, a); + uint8_t v = scale8(highlight, h + 4 > pos ? 255 : 110); + plotSoft(a[0] * S, a[1] * S, a[2] * S, CHSV(h * 4, 230, v)); + } + if (pos < 63) { // Kopf gleitet zum nächsten Punkt + hilbertPoint(pos, a); + hilbertPoint(pos + 1, b); + float f = pos - int(pos); + plotSoft((a[0] + (b[0] - a[0]) * f) * S, (a[1] + (b[1] - a[1]) * f) * S, (a[2] + (b[2] - a[2]) * f) * S, + CRGB(highlight, highlight, highlight)); + } +} + +// --- Kristall: umherirrende Teilchen bleiben am Kristall hängen (DLA) ------------ + +static uint8_t crystal[NUM_LAYERS][CUBE_SIZE][CUBE_SIZE]; // 0 = leer, sonst Reihenfolge + +void renderCrystal(uint32_t now) { + static int8_t w[3]; + static uint8_t count = 0; + static uint32_t doneAt = 0; + if (fresh || (doneAt && now - doneAt > 2500)) { + fresh = false; + memset(crystal, 0, sizeof(crystal)); + crystal[0][2][2] = count = 1; // Keim unten in der Mitte + doneAt = 0; + w[0] = -1; + } + if (!doneAt) + for (uint8_t step = 0; step < 6; step++) { + if (w[0] < 0) { // neues Teilchen oben irgendwo + w[0] = random8(CUBE_SIZE); + w[1] = random8(CUBE_SIZE); + w[2] = TOP; + } + 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}}; + bool stick = false; + for (const auto &d : DIRS) { + int x = w[0] + d[0], y = w[1] + d[1], z = w[2] + d[2]; + if (inCube(x, y, z) && crystal[z][y][x]) stick = true; + } + if (stick && !crystal[w[2]][w[1]][w[0]]) { + crystal[w[2]][w[1]][w[0]] = ++count; + if (w[2] == TOP || count > 70) doneAt = now; + w[0] = -1; + break; + } + const int8_t *d = DIRS[random8() < 40 ? 5 : random8(6)]; // leicht nach unten + int x = w[0] + d[0], y = w[1] + d[1], z = w[2] + d[2]; + if (inCube(x, y, z) && !crystal[z][y][x]) { + w[0] = x; + w[1] = y; + w[2] = z; + } + } + FastLED.clear(); + FOR_XYZ { + uint8_t c = crystal[z][y][x]; + if (!c) continue; + uint8_t v = doneAt ? scale8(highlight, 150 + scale8(sin8(now / 3 + c * 20), 105)) : min(255, brightness * 2); + at(x, y, z) = CHSV(140 + c * 2, 200, v); + } + if (w[0] >= 0 && !doneAt) at(w[0], w[1], w[2]) += CRGB(brightness / 2, brightness / 2, brightness / 2); +} + +// --- Fraktalwolken: Rauschen über drei Größenordnungen --------------------------- + +void renderFractalClouds(uint32_t now) { + uint32_t t = now - fxStart; + static const CRGBPalette16 palette(CRGB::Black, CRGB::DarkViolet, CRGB::DeepPink, CRGB::Gold); + FOR_XYZ { + uint8_t n = inoise8(x * 25, y * 25 + t / 20, z * 25) / 2 + inoise8(x * 70 + t / 8, y * 70, z * 70) / 4 + + inoise8(x * 160, y * 160, z * 160 + t / 3) / 8; // höchstens 221 + n = qsub8(n, 60); + at(x, y, z) = ColorFromPalette(palette, qadd8(n, n), min(255, brightness * 3)); + } +} diff --git a/fx_musik.cpp b/fx_musik.cpp new file mode 100644 index 0000000..177f7b8 --- /dev/null +++ b/fx_musik.cpp @@ -0,0 +1,117 @@ +// Kategorie Musik: reagieren auf das Mikrofon +// (dazu Spektrum, Puls, Schockwelle, Klangschichten, Klangwelle und Disko aus effects.cpp) + +#include "fx.h" + +// --- Pegel: der Würfel füllt sich mit der Lautstärke, Spitzenwert bleibt kurz stehen + +void renderVu(uint32_t now) { + static float level = 0, peak = 0; + if (fresh) { + fresh = false; + level = peak = 0; + } + float l = audioLevel() * NUM_LAYERS; + level = l > level ? l : level * 0.92f; // schnell hoch, langsam zurück + peak = level > peak ? level : max(0.0f, peak - 0.03f); + FastLED.clear(); + FOR_XYZ { + float f = constrain(level - z, 0.0f, 1.0f); + if (f > 0) at(x, y, z) = CHSV(96 - z * 24, 255, uint8_t(f * min(255, brightness * 2))); // grün .. rot + } + uint8_t pz = min(TOP, peak); + if (peak > 0.5f) + for (uint8_t i = 0; i < 16; i++) { // Spitzenwert als heller Ring + uint8_t x, y; + ringPos(i, x, y); + at(x, y, pz) = CRGB(highlight, highlight, highlight); + } +} + +// --- Beat-Ebenen: jeder Bass-Schlag lässt eine zufällige Ebene aufleuchten -------- + +void renderBeatPlanes(uint32_t now) { + static uint8_t hue = 0; + fadeToBlackBy(leds, NUM_LEDS, 20); + if (audioBeat()) { + hue += 50; + uint8_t axis = random8(3), pos = random8(CUBE_SIZE); + FOR_XYZ { + if ((axis == 0 ? x : axis == 1 ? y : z) == pos) at(x, y, z) = CHSV(hue, 255, highlight); + } + } + if (random8() < audioLevel() * 200) leds[random16(NUM_LEDS)] += CHSV(hue + 128, 200, brightness); +} + +// --- Klangwürfel: Bass in der Mitte, Mitten in der inneren Schale, Höhen außen ---- + +void renderSoundCube(uint32_t now) { + static float smooth3[3]; + float b[CUBE_SIZE]; + audioSpectrum(b); + float s[3] = {max(b[0], b[1]), b[2], max(b[3], b[4])}; + for (uint8_t i = 0; i < 3; i++) smooth3[i] = s[i] > smooth3[i] ? s[i] : smooth3[i] * 0.9f; + FOR_XYZ { + uint8_t d = shell(x, y, z); + uint8_t v = d == 2 ? min(255, brightness * 2) : highlight; // Außenhaut hat die meisten LEDs + at(x, y, z) = CHSV(uint8_t(now / 50) + d * 70, 230, uint8_t(smooth3[d] * v)); + } +} + +// --- Funkenregen: Funken fallen mit der Lautstärke, jeder Beat gibt einen Schwall -- + +void renderSparkRain(uint32_t now) { + static uint8_t hue = 0; + float l = audioLevel(); + hue = now / 80; + uint8_t n = l * 3 + (random8() < l * 255 ? 1 : 0); + for (uint8_t i = 0; i < n; i++) + spawnParticle(rnd(0, TOP), rnd(0, TOP), TOP, 0, 0, -rnd(0.05f, 0.1f), CHSV(hue + random8(30), 255, highlight)); + if (audioBeat()) + for (uint8_t i = 0; i < 12; i++) + spawnParticle(MID, MID, TOP, rnd(-0.12f, 0.12f), rnd(-0.12f, 0.12f), rnd(0, 0.08f), CHSV(hue + 128, 200, highlight)); + FastLED.clear(); + moveParticles(0.006f, 0.98f, 4); + drawParticles(); +} + +// --- Oszilloskop: die Lautstärke als Linie, die von vorn nach hinten durchläuft --- + +void renderScope(uint32_t now) { + const uint8_t N = CUBE_SIZE * CUBE_SIZE; + static float trace[N]; + static uint32_t last = 0; + if (fresh) { + fresh = false; + memset(trace, 0, sizeof(trace)); + } + if (now - last >= 60) { + last = now; + memmove(trace + 1, trace, sizeof(float) * (N - 1)); + trace[0] = audioLevel(); + } + FastLED.clear(); + for (uint8_t k = 0; k < N; k++) { + uint8_t y = k / CUBE_SIZE, x = y % 2 ? k % CUBE_SIZE : TOP - k % CUBE_SIZE; // Schlangenlinie + float h = trace[k] * TOP; + for (uint8_t z = 0; z < NUM_LAYERS; z++) { + float d = fabsf(z - h); + if (d < 1) at(x, y, z) += CHSV(160 - y * 30, 255, uint8_t((1 - d) * scale8(highlight, 255 - y * 45))); + } + } +} + +// --- Ringe: Bass in der Mittelsäule, Mitten im inneren Ring, Höhen am Rand ------ + +void renderRings(uint32_t now) { + float b[CUBE_SIZE]; + audioSpectrum(b); + float h[3] = {b[0] * NUM_LAYERS, (b[1] + b[2]) * NUM_LAYERS / 2, (b[3] + b[4]) * NUM_LAYERS / 2}; + FastLED.clear(); + FOR_XYZ { + uint8_t r = max(abs(x - 2), abs(y - 2)); + float f = constrain(h[r] - z, 0.0f, 1.0f); + uint8_t v = r == 2 ? min(255, brightness * 2) : highlight; + if (f > 0) at(x, y, z) = CHSV(r * 80 + now / 30, 255, uint8_t(f * v)); + } +} diff --git a/fx_natur.cpp b/fx_natur.cpp new file mode 100644 index 0000000..051531a --- /dev/null +++ b/fx_natur.cpp @@ -0,0 +1,333 @@ +// Kategorie Natur (dazu Gewitter und Feuer aus effects.cpp) + +#include "fx.h" + +// --- Regen: Tropfen fallen und ziehen unten Kreise im Wasser ------------------- + +struct Ripple { + float x, y; + uint32_t start; // 0 = frei +}; +static Ripple ripples[6]; + +void renderRain(uint32_t now) { + static uint8_t next = 0; + if (fresh) { + fresh = false; + for (Ripple &r : ripples) r.start = 0; + } + if (random8() < 30) + spawnParticle(random8(CUBE_SIZE), random8(CUBE_SIZE), TOP + 0.4f, 0, 0, -rnd(0.12f, 0.18f), + CRGB(highlight / 5, highlight / 3, highlight / 2)); + for (Particle &p : particles) + if (p.life && p.z + p.vz < 0.5f) { // trifft aufs Wasser + ripples[next] = {p.x, p.y, now}; + next = (next + 1) % 6; + p.life = 0; + } + moveParticles(0, 1, 0); + + FastLED.clear(); + for (uint8_t y = 0; y < CUBE_SIZE; y++) + for (uint8_t x = 0; x < CUBE_SIZE; x++) at(x, y, 0) = CRGB(0, brightness / 8, brightness / 3); + for (Ripple &r : ripples) { + if (!r.start) continue; + uint32_t t = now - r.start; + if (t > 900) { + r.start = 0; + continue; + } + float radius = t * 0.004f, fade = 1 - t / 900.0f; + for (uint8_t y = 0; y < CUBE_SIZE; y++) + for (uint8_t x = 0; x < CUBE_SIZE; x++) { + float f = (1 - fabsf(hypotf(x - r.x, y - r.y) - radius) / 0.6f) * fade; + if (f > 0) at(x, y, 0) += CRGB(0, uint8_t(f * highlight / 3), uint8_t(f * highlight / 1.5f)); + } + } + drawParticles(); +} + +// --- Polarlicht: grüne Vorhänge mit violetten Säumen wehen über den Himmel ------ + +void renderAurora(uint32_t now) { + static const float PROFILE[] = {0, 0.35f, 1, 0.85f, 0.55f}; // Helligkeit je Etage + uint32_t t = now - fxStart; + FOR_XYZ { + if (z == 0) { // verschneiter Boden + at(x, y, z) = CRGB(brightness / 14, brightness / 14, brightness / 8); + continue; + } + uint8_t n = inoise8(x * 45 + t / 25, y * 45 - t / 40, t / 20); + n = qsub8(n, 95); + n = qadd8(n, qadd8(n, n)); + uint8_t hue = 96 + (z >= 3 ? (z - 2) * 55 : 0) + n / 24; + at(x, y, z) = CHSV(hue, 230, uint8_t(scale8(n, min(255, brightness * 3)) * PROFILE[z])); + } +} + +// --- Ozean: Wasser mit Wellen, Schaum auf den Kämmen --------------------------- + +void renderOcean(uint32_t now) { + float t = (now - fxStart) * 0.001f; + uint16_t nt = (now - fxStart) * 6 / 100; + FastLED.clear(); + for (uint8_t y = 0; y < CUBE_SIZE; y++) + for (uint8_t x = 0; x < CUBE_SIZE; x++) { + float h = 2.1f + 0.9f * sinf(x * 0.9f + t * 1.4f) * cosf(y * 0.7f - t) + + (inoise8(x * 40, y * 40, nt) - 128) / 128.0f * 0.6f; + for (uint8_t z = 0; z < NUM_LAYERS; z++) { + if (z < h - 0.5f) { + at(x, y, z) = CHSV(152 - z * 4, 255, uint8_t(brightness * (0.35f + 0.15f * z))); + } else { + float f = 1 - fabsf(z - h) / 0.8f; // Oberfläche + if (f <= 0) continue; + bool foam = h > 2.8f; + at(x, y, z) = CHSV(140, foam ? 60 : 160, uint8_t(f * highlight * (foam ? 0.8f : 0.5f))); + } + } + } +} + +// --- Glühwürmchen: grünlich-gelbe Lichter blinken langsam im Dunkeln ----------- + +struct Firefly { + float p[3], v[3]; + uint32_t start; // Beginn des nächsten Leuchtens +}; +static Firefly flies[10]; + +void renderFireflies(uint32_t now) { + if (fresh) { + fresh = false; + for (Firefly &f : flies) { + for (uint8_t i = 0; i < 3; i++) { + f.p[i] = rnd(0, TOP); + f.v[i] = 0; + } + f.start = now + random16(3000); + } + } + FastLED.clear(); + for (uint8_t y = 0; y < CUBE_SIZE; y++) + for (uint8_t x = 0; x < CUBE_SIZE; x++) at(x, y, 0) = CRGB(0, brightness / 14, 0); // Wiese + for (Firefly &f : flies) { + for (uint8_t i = 0; i < 3; i++) { + f.v[i] = constrain(f.v[i] + rnd(-0.002f, 0.002f), -0.015f, 0.015f); + f.p[i] += f.v[i]; + if (f.p[i] < 0 || f.p[i] > TOP) f.v[i] = -f.v[i]; + f.p[i] = constrain(f.p[i], 0.0f, float(TOP)); + } + int32_t t = now - f.start; + if (t < 0) continue; + float env = t < 400 ? t / 400.0f : t < 700 ? 1 : t < 1500 ? 1 - (t - 700) / 800.0f : 0; + if (t >= 1500) f.start = now + random16(1000, 4000); + if (env > 0) plotSoft(f.p[0], f.p[1], f.p[2], CRGB(scale8(highlight, 150), highlight, 0).nscale8(uint8_t(env * 255))); + } +} + +// --- Sonnenaufgang: Nacht, Morgenrot, Tag und Abendrot in 40 s ------------------ + +void renderSunrise(uint32_t now) { + float ph = ((now - fxStart) % 40000) / 40000.0f * TWO_PI - HALF_PI; // Start in der Nacht + float e = sinf(ph); // Sonnenhöhe -1..1 + float sunX = MID - 2.6f * cosf(ph), sunZ = -0.5f + e * 4.5f; + float day = constrain(e * 2 + 0.3f, 0.0f, 1.0f); + float dawn = max(0.0f, 1 - fabsf(e) * 3); + CRGB night(0, 0, brightness / 6), sky(brightness / 3, brightness / 2, brightness), red(brightness, brightness / 3, 0); + FOR_XYZ { + CRGB c = blend(night, sky, uint8_t(day * 255)); + c += CRGB(red).nscale8(uint8_t(dawn * 255 * (1 - z / float(NUM_LAYERS)))); // Morgenrot am Horizont + float d = dist3(x, y, z, sunX, MID, sunZ); + if (d < 1.6f) c += CRGB(highlight, scale8(highlight, 130 + uint8_t(day * 100)), scale8(highlight, 40)).nscale8(uint8_t((1 - d / 1.6f) * 255)); + if (z >= 2 && (x * 7 + y * 13 + z * 5) % 9 == 0) // Sterne, nur nachts + c += CRGB(brightness, brightness, brightness).nscale8(uint8_t((1 - day) * scale8(sin8(now / 9 + x * 50 + y * 30), 200))); + at(x, y, z) = c; + } +} + +// --- Blumenwiese: wogendes Gras, Blumen auf Stängeln, ein Schmetterling --------- + +struct Flower { + uint8_t x, y, h, hue; +}; +static Flower flowers[6]; +static float butterfly[3], butterflyV[3]; + +void renderMeadow(uint32_t now) { + static const uint8_t HUES[] = {0, 40, 200, 160, 64, 230}; // 64 = weiß + if (fresh) { + fresh = false; + for (uint8_t i = 0; i < 6; i++) { + bool taken; + do { + flowers[i] = {random8(CUBE_SIZE), random8(CUBE_SIZE), random8(2, 4), HUES[i]}; + taken = false; + for (uint8_t k = 0; k < i; k++) taken |= flowers[k].x == flowers[i].x && flowers[k].y == flowers[i].y; + } while (taken); + } + for (uint8_t i = 0; i < 3; i++) { + butterfly[i] = MID; + butterflyV[i] = 0; + } + } + uint32_t t = now - fxStart; + FastLED.clear(); + for (uint8_t y = 0; y < CUBE_SIZE; y++) + for (uint8_t x = 0; x < CUBE_SIZE; x++) { + uint8_t n = inoise8(x * 60 + t / 8, y * 60, t / 10); // Wind im Gras + at(x, y, 0) = CHSV(80 + n / 16, 255, scale8(brightness, 120 + n / 3)); + if (n > 140) at(x, y, 1) = CHSV(88, 255, scale8(brightness, (n - 140) * 2)); + } + for (Flower &f : flowers) { + for (uint8_t z = 1; z < f.h; z++) at(f.x, f.y, z) = CHSV(96, 255, brightness / 2); + at(f.x, f.y, f.h) = CHSV(f.hue, f.hue == 64 ? 0 : 200, scale8(highlight, 170 + scale8(sin8(t / 10 + f.hue), 85))); + } + for (uint8_t i = 0; i < 3; i++) { // Schmetterling flattert oben herum + butterflyV[i] = constrain(butterflyV[i] + rnd(-0.01f, 0.01f), -0.04f, 0.04f); + butterfly[i] += butterflyV[i]; + float lo = i == 2 ? 2.5f : 0, hi = TOP; + if (butterfly[i] < lo || butterfly[i] > hi) butterflyV[i] = -butterflyV[i]; + butterfly[i] = constrain(butterfly[i], lo, hi); + } + if (t / 120 % 2) plot(butterfly[0], butterfly[1], butterfly[2], CRGB(highlight, scale8(highlight, 120), 0)); +} + +// --- Wasserfall: Wasser stürzt an der Rückseite herab in ein Becken ------------ + +void renderWaterfall(uint32_t now) { + uint32_t t = now - fxStart; + FastLED.clear(); + FOR_XYZ { + if (y == TOP) { // fallendes Wasser: Muster wandert nach unten + uint8_t n = inoise8(x * 90, z * 70 + t / 2); + n = qadd8(qsub8(n, 60), qsub8(n, 60)); + at(x, y, z) = CHSV(150, 140 - n / 3, scale8(n, highlight)); + } else if (z == 0) { // Becken mit Wellen, die von hinten nach vorn laufen + uint8_t w = sin8((TOP - y) * 50 - t / 3); + at(x, y, z) = CHSV(155, 255, scale8(brightness, 120 + w / 2)); + if (y == TOP - 1 && random8() < 50) at(x, y, z) += CRGB(highlight / 2, highlight / 2, highlight / 2); // Gischt + } + } + if (random8() < 40) spawnParticle(rnd(0, TOP), TOP - 1, 0.5f, 0, rnd(-0.04f, -0.01f), rnd(0.04f, 0.08f), CRGB(highlight / 2, highlight / 2, highlight / 2)); + moveParticles(0.008f, 0.97f, 12); + drawParticles(); +} + +// --- Vulkan: glühender Krater, Lavaströme und Ausbrüche ------------------------- + +static bool isMountain(int x, int y, int z) { + float d = distAxis(x, y); + return (z == 0 && d <= 2.3f) || (z == 1 && d <= 1.5f && d > 0.5f) || (z == 2 && d <= 1.0f && d > 0.5f); +} + +void renderVolcano(uint32_t now) { + static uint32_t nextEruption = 0; + static int8_t flowDir[2][2]; + if (fresh) { + fresh = false; + nextEruption = now + 1500; + for (auto &d : flowDir) { + d[0] = random8(2) ? 1 : -1; + d[1] = random8(3) - 1; + } + } + uint32_t t = now - fxStart; + FastLED.clear(); + FOR_XYZ { + if (isMountain(x, y, z)) at(x, y, z) = CRGB(brightness / 5, brightness / 9, brightness / 12); + } + // Krater und Schlot glühen + at(2, 2, 1) = HeatColor(170 + scale8(sin8(t / 4), 60)).nscale8(highlight); + at(2, 2, 2) = HeatColor(200 + random8(40)).nscale8(highlight); + // zwei Lavaströme fließen die Hänge hinab + for (auto &d : flowDir) + for (uint8_t k = 1; k <= 2; k++) { + uint8_t pulse = sin8(k * 70 - t / 3); + at(2 + d[0] * k, 2 + d[1] * k, 2 - k) = HeatColor(120 + pulse / 3).nscale8(scale8(highlight, 150 + pulse / 3)); + } + if (int32_t(now - nextEruption) >= 0) { + nextEruption = now + random16(1500, 4000); + for (uint8_t i = random8(12, 20); i > 0; i--) + spawnParticle(MID, MID, 2.5f, rnd(-0.06f, 0.06f), rnd(-0.06f, 0.06f), rnd(0.12f, 0.2f), HeatColor(random8(160, 255)).nscale8(highlight)); + } + moveParticles(0.006f, 0.99f, 3); + drawParticles(); +} + +// --- Herbstlaub: bunte Blätter segeln herab und bleiben am Boden liegen -------- + +static uint8_t leafHue[CUBE_SIZE][CUBE_SIZE], leafLevel[CUBE_SIZE][CUBE_SIZE]; + +void renderAutumn(uint32_t now) { + static const uint8_t HUES[] = {0, 12, 25, 40, 20}; + if (fresh) { + fresh = false; + memset(leafLevel, 0, sizeof(leafLevel)); + } + float wind = 0.012f * sinf((now - fxStart) * 0.0005f); // Böen von wechselnder Seite + if (random8() < 10) + spawnParticle(rnd(0, TOP), rnd(0, TOP), TOP + 0.4f, 0, 0, -rnd(0.012f, 0.02f), CHSV(HUES[random8(5)], 255, scale8(highlight, 180))); + for (Particle &p : particles) { + if (!p.life) continue; + p.vx = wind + 0.02f * sinf(now * 0.003f + p.y * 3); // hin und her segeln + p.vy = 0.01f * cosf(now * 0.002f + p.x * 3); + if (p.z + p.vz < 0) { // gelandet + uint8_t x = constrain(lroundf(p.x), 0, TOP), y = constrain(lroundf(p.y), 0, TOP); + leafLevel[x][y] = 255; + leafHue[x][y] = rgb2hsv_approximate(p.color).h; + p.life = 0; + } + if (p.x < 0 || p.x > TOP) p.vx = -p.vx; + } + moveParticles(0, 1, 0); + static uint8_t frame = 0; + bool rot = ++frame % 8 == 0; + FastLED.clear(); + for (uint8_t y = 0; y < CUBE_SIZE; y++) + for (uint8_t x = 0; x < CUBE_SIZE; x++) { + if (rot) leafLevel[x][y] = qsub8(leafLevel[x][y], 1); + at(x, y, 0) = CHSV(leafHue[x][y], 255, scale8(scale8(highlight, 150), leafLevel[x][y])); + } + for (const Particle &p : particles) // Blätter taumeln: Helligkeit flackert + if (p.life) plot(p.x, p.y, p.z, CRGB(p.color).nscale8(160 + scale8(sin8(now / 3 + p.x * 40), 95))); +} + +// --- Sternschnuppen: funkelnder Nachthimmel, ab und zu zieht eine Schnuppe vorbei -- + +struct Meteor { + bool active; + float x, y, z, vx, vy, vz; +}; + +void renderShootingStars(uint32_t now) { + static Meteor m; + static uint32_t next = 0; + if (fresh) { + fresh = false; + m.active = false; + next = now + 1000; + } + FastLED.clear(); + FOR_XYZ { + if ((x * 7 + y * 11 + z * 13) % 7 == 0 && z >= 1) { + uint8_t tw = sin8(now / 7 + x * 40 + y * 70 + z * 20); + at(x, y, z) = CRGB(brightness / 2, brightness / 2, brightness).nscale8(60 + scale8(tw, 195)); + } + } + if (!m.active && int32_t(now - next) >= 0) { + bool left = random8(2); + m = {true, left ? -0.5f : TOP + 0.5f, rnd(0, TOP), rnd(3, TOP + 0.5f), + (left ? 1 : -1) * rnd(0.18f, 0.26f), rnd(-0.05f, 0.05f), -rnd(0.04f, 0.09f)}; + next = now + random16(1500, 5000); + } + if (m.active) { + spawnParticle(m.x, m.y, m.z, 0, 0, 0, CRGB(highlight / 2, highlight / 2, highlight / 3)); // Schweif + m.x += m.vx; + m.y += m.vy; + m.z += m.vz; + if (m.x < -1 || m.x > TOP + 1 || m.z < -0.5f) m.active = false; + else plot(m.x, m.y, m.z, CRGB(highlight, highlight, scale8(highlight, 200))); + } + moveParticles(0, 1, 30); + drawParticles(); +} diff --git a/fx_ruhe.cpp b/fx_ruhe.cpp new file mode 100644 index 0000000..b8eae5d --- /dev/null +++ b/fx_ruhe.cpp @@ -0,0 +1,225 @@ +// Kategorie Ruhe: sehr ruhige, langsame Effekte + +#include "fx.h" + +// --- Atmen: der ganze Würfel wird langsam hell und wieder dunkel ---------------- + +void renderBreathe(uint32_t now) { + uint32_t t = now - fxStart; + float breath = (1 - cosf(t * (TWO_PI / 8000))) / 2; // ein Atemzug in 8 s + uint8_t hue = 140 + t / 1000; // Farbe wandert sehr langsam + FOR_XYZ { + float d = dist3(x, y, z, MID, MID, MID); + float v = (0.12f + 0.88f * breath) * (1 - d / 6); + at(x, y, z) = CHSV(hue + wrap8(d * 6), 200, uint8_t(v * min(255, brightness * 2))); + } +} + +// --- Kerzenschein: eine Flamme in der Mitte, warmes Licht ringsum --------------- + +void renderCandle(uint32_t now) { + static float flick = 1; + flick += (rnd(0.65f, 1.0f) - flick) * 0.08f; // sanftes Flackern + float fx = MID + (inoise8(now / 3) - 128) / 128.0f * 0.35f; + float fy = MID + (inoise8(now / 3 + 9000) - 128) / 128.0f * 0.35f; + FOR_XYZ { + float d = dist3(x, y, z, fx, fy, 2.3f); + float g = flick * min(255, brightness * 4) / (1 + d * d * 1.3f); + at(x, y, z) = CRGB(g, g * 0.5f, g * 0.12f); + } + at(2, 2, 0) += CRGB(brightness / 3, brightness / 4, brightness / 5); // Kerze + at(2, 2, 1) += CRGB(brightness / 3, brightness / 4, brightness / 5); +} + +// --- Sternenhimmel: dunkelblau, die Sterne funkeln ganz langsam ---------------- + +struct Star { + uint8_t x, y, z, phase, speed; + CRGB color; +}; +static Star stars[20]; + +void renderStarrySky(uint32_t now) { + if (fresh) { + fresh = false; + static const CRGB TINTS[] = {CRGB(255, 255, 255), CRGB(180, 200, 255), CRGB(255, 220, 170)}; + for (Star &s : stars) s = {random8(CUBE_SIZE), random8(CUBE_SIZE), random8(NUM_LAYERS), random8(), random8(2, 6), TINTS[random8(3)]}; + } + FOR_XYZ at(x, y, z) = CRGB(0, 0, brightness / 14); + for (const Star &s : stars) { + uint8_t v = scale8(sin8(now * s.speed / 64 + s.phase), min(255, brightness * 2)); + at(s.x, s.y, s.z) = CRGB(s.color).nscale8(v) + CRGB(0, 0, brightness / 14); + } +} + +// --- Mondlicht: blasser Mond, Wolken ziehen langsam vorbei ------------------- + +void renderMoonlight(uint32_t now) { + uint32_t t = now - fxStart; + FOR_XYZ { + float d = dist3(x, y, z, 3.4f, 3.4f, 3.6f); + float moon = constrain(1.6f - d, 0.0f, 1.0f); + uint8_t cloud = qsub8(inoise8(x * 50 + t / 30, y * 50, z * 50 + t / 45), 110); // Wolken + cloud = qadd8(cloud, cloud); + CRGB c(0, 0, brightness / 10); // Nachthimmel + c += CRGB(brightness, brightness, scale8(min(255, brightness * 2), 230)).nscale8(uint8_t(moon * scale8(255 - cloud, 255))); + c += CRGB(brightness / 4, brightness / 4, brightness / 3).nscale8(cloud); // vom Mond beschienene Wolken + if (z == 0) c += CRGB(0, 0, scale8(brightness / 3, sin8(x * 60 + y * 40 + t / 20))); // Wasser glitzert + at(x, y, z) = c; + } +} + +// --- Farbwechsel: der ganze Würfel in einer Farbe, die sich ganz langsam ändert --- + +void renderColorCycle(uint32_t now) { + uint32_t t = now - fxStart; + FOR_XYZ at(x, y, z) = CHSV(t / 350 + z * 4, 210, brightness); // eine Runde in 90 s +} + +// --- Glut: glimmende Holzkohle, dunkelrot bis orange --------------------------- + +void renderEmbers(uint32_t now) { + uint32_t t = now - fxStart; + FOR_XYZ { + uint8_t n = inoise8(x * 60, y * 60 + t / 40, z * 60 - t / 30); + uint8_t heat = scale8(n, 150 - z * 22); // unten heißer + at(x, y, z) = HeatColor(heat).nscale8(min(255, brightness * 3)); + } +} + +// --- Tiefsee: Lichtflecken spielen langsam, ab und zu steigt eine Blase auf ------ + +void renderDeepSea(uint32_t now) { + uint32_t t = now - fxStart; + FOR_XYZ { + uint8_t n = inoise8(x * 60 + t / 30, y * 60 + t / 40, z * 30 + t / 50); + n = qsub8(n, 100); + n = qadd8(n, n); + uint8_t depth = 90 + z * 40; // oben heller + at(x, y, z) = CHSV(150 + n / 16, 230, scale8(scale8(depth, 60 + n), min(255, brightness * 2))); + } + if (random8() < 3) + spawnParticle(random8(CUBE_SIZE), random8(CUBE_SIZE), 0, 0, 0, rnd(0.01f, 0.02f), CRGB(brightness / 2, brightness, brightness)); + for (Particle &p : particles) p.vx = p.life ? 0.004f * sinf(now * 0.002f + p.y) : 0; + moveParticles(0, 1, 0); + for (Particle &p : particles) + if (p.life && p.z > TOP) p.life = 0; + drawParticles(); +} + +// --- Dämmerung: Abendrot unten, Nachtblau oben, die Farben verschieben sich langsam + +void renderDusk(uint32_t now) { + static const CRGBPalette16 palette(CRGB(255, 80, 0), CRGB(200, 0, 60), CRGB(70, 0, 120), CRGB(0, 10, 60)); + uint32_t t = now - fxStart; + uint8_t shift = sin8(t / 240) / 4; // langsam hin und her + FOR_XYZ { + uint8_t n = inoise8(x * 40, y * 40, t / 25) / 8; + at(x, y, z) = ColorFromPalette(palette, min(240, z * 55 + shift + n), brightness); + } +} + +// --- Gezeiten: der Wasserspiegel hebt und senkt sich langsam -------------------- + +void renderTide(uint32_t now) { + float t = (now - fxStart) * 0.001f; + float level = 2 + 1.6f * sinf(t * TWO_PI / 20); // Ebbe und Flut in 20 s + FOR_XYZ { + float ripple = 0.15f * sinf(x * 1.3f + t) * cosf(y * 1.1f - t * 0.8f); + float f = constrain(level + ripple - z + 0.5f, 0.0f, 1.0f); + float surface = constrain(1 - fabsf(level + ripple - z) * 1.5f, 0.0f, 1.0f); + CRGB c = CHSV(150 - z * 3, 240, uint8_t(f * brightness)); + c += CHSV(135, 120, uint8_t(surface * brightness)); + at(x, y, z) = c; + } +} + +// --- Laternen: warme Lichter steigen langsam auf und verglimmen oben ------------- + +struct Lantern { + float x, y, z, vz, phase; + uint8_t hue; +}; +static Lantern lanterns[4]; + +static void newLantern(Lantern &l, bool anywhere) { + l = {rnd(0.5f, TOP - 0.5f), rnd(0.5f, TOP - 0.5f), anywhere ? rnd(-1, TOP) : rnd(-3, -1), rnd(0.004f, 0.008f), rnd(0, TWO_PI), random8(15, 35)}; +} + +void renderLanterns(uint32_t now) { + if (fresh) { + fresh = false; + for (Lantern &l : lanterns) newLantern(l, true); + } + float t = (now - fxStart) * 0.001f; + FastLED.clear(); + for (Lantern &l : lanterns) { + l.z += l.vz; + if (l.z > TOP + 0.6f) newLantern(l, false); + float fade = smooth((l.z + 1) / 1.5f) * smooth((TOP + 0.6f - l.z) / 1.5f); // unten auf-, oben abblenden + float flick = 0.85f + 0.15f * sinf(t * 3 + l.phase); + plotSoft(l.x + 0.4f * sinf(t * 0.4f + l.phase), l.y + 0.4f * cosf(t * 0.3f + l.phase), l.z, + CHSV(l.hue, 230, uint8_t(fade * flick * highlight))); + } +} + +// --- Sanduhr: Sand rieselt Korn für Korn nach unten, dann wird umgedreht --------- + +static uint8_t sandOrder[2][50][3]; // Reihenfolge der Plätze: [oben/unten][Platz] = x, y, z + +static void sortCells(uint8_t cells[][3], bool top) { + // oben: am Rand und unten bleibt Sand am längsten liegen; unten: Hügel von der Mitte aus + uint8_t n = 0; + float key[50]; + for (uint8_t z = top ? 3 : 0; z < (top ? 5 : 2); z++) + for (uint8_t y = 0; y < CUBE_SIZE; y++) + for (uint8_t x = 0; x < CUBE_SIZE; x++) { + float d = distAxis(x, y); + key[n] = top ? z * 1.5f + (3 - d) : z * 1.5f + d; + cells[n][0] = x; + cells[n][1] = y; + cells[n][2] = z; + n++; + } + for (uint8_t i = 1; i < n; i++) // Einfügesortierung nach key + for (uint8_t j = i; j > 0 && key[j] < key[j - 1]; j--) { + float k = key[j]; + key[j] = key[j - 1]; + key[j - 1] = k; + for (uint8_t c = 0; c < 3; c++) { + uint8_t v = cells[j][c]; + cells[j][c] = cells[j - 1][c]; + cells[j - 1][c] = v; + } + } +} + +void renderHourglass(uint32_t now) { + const uint8_t GRAINS = 25; + const uint16_t GRAIN_MS = 1200; + static uint32_t runStart = 0; + if (fresh) { + fresh = false; + sortCells(sandOrder[0], true); + sortCells(sandOrder[1], false); + runStart = now; + } + uint32_t t = now - runStart; + if (t > GRAINS * GRAIN_MS + 2500) { // durchgelaufen: umdrehen, der Sand ist wieder oben + runStart = now; + t = 0; + } + uint8_t fallen = min(GRAINS, t / GRAIN_MS); + CRGB sand(min(255, brightness * 3 / 2), min(255, brightness * 11 / 10), brightness * 2 / 5); + FastLED.clear(); + for (uint8_t i = 0; i < GRAINS - fallen; i++) at(sandOrder[0][i][0], sandOrder[0][i][1], sandOrder[0][i][2]) = sand; + for (uint8_t i = 0; i < fallen; i++) at(sandOrder[1][i][0], sandOrder[1][i][1], sandOrder[1][i][2]) = sand; + if (fallen < GRAINS) at(2, 2, 2) = CRGB(sand).nscale8(128 + scale8(sin8(t / 4), 127)); // rieselndes Korn in der Engstelle +} + +// --- Pastell: sanfte Farbverläufe in hellen Tönen ziehen langsam durch ---------- + +void renderPastel(uint32_t now) { + uint32_t t = now - fxStart; + FOR_XYZ at(x, y, z) = CHSV(x * 8 + y * 12 + z * 16 + t / 300, 110, brightness); +} diff --git a/ios/CubeRemote/ContentView.swift b/ios/CubeRemote/ContentView.swift index 13b2340..d27c380 100644 --- a/ios/CubeRemote/ContentView.swift +++ b/ios/CubeRemote/ContentView.swift @@ -202,10 +202,12 @@ struct ContentView: View { private static func color(_ category: String) -> Color { switch category { case "flash": .yellow - case "weihnachten": .red - case "silvester": .orange + case "festtage": .red case "musik": .indigo - case "floating": .teal + case "floating": .cyan + case "natur": .green + case "fraktal": .purple + case "ruhe": .brown default: .gray } }