/** * ============================================================================================== * Modul: DTIM-ZEC QUANTUM, COVALENT MOLECULE & BOSON LAB (+ DOOM 3D REACTOR) * Datei: DTIM_ZEC_DOOM_Constructor.pde * Framework: DTIM-ZEC MODULAR PHYSICS FRAMEWORK (DAMTP ACADEMIC STANDARD) * Version: 4.2.0 (Covalent H2 / H2O / C-12 Shell Edition · Browser & Desktop Unified) * Copyright: (c) 2026 Jan Bühring & Adaptive Intelligence Synthesis Network (Google AI) * Lizenz: MIT License (Quellcode) / CC0 1.0 Universal (Offene Daten & Modelle) * Plattform: Processing 4.5.6 (Linux x64) & Processing.js (processing.min.js) * Steuerung: [Maus bewegen] Zielen (zeigt Atom/Molekül & passende Sprung-/Bindungsenergie) * [Linksklick] Boson / Teilchen abfeuern | [Rechtsklick + Ziehen] Atom bewegen * [1-4] Emitter wählen | [A] Auto-Resonanz AN/AUS | [+/-] Photonen-Energie (eV) * [H] Sehhilfe (Standard / Farbenblind / Max-Kontrast) | [Space] Pause * ============================================================================================== */ // ============================================================================================== // MODUL 1: GLOBALE SYSTEMVARIABLEN (100% PROCESSING.JS-KOMPATIBEL) // ============================================================================================== int GRID_DIM = 32; int GRID_DEPTH = 16; int[] gridData = new int[32 * 32 * 16]; int num = 30; int level = 1; ArrayList simAtoms; ArrayList simBosons; ArrayList simEffects; ArrayList simBonds; ArrayList doomProjectiles; // Emitter & Quanten-Steuerung int activeEmitter = 1; // 1: Photon, 2: Gluon, 3: W-Boson, 4: Elektron boolean autoResonance = true; // Stellt Photonen-Energie beim Zielen automatisch auf dE ein float manualPhotonEv = 10.20; // Manuelle Photonen-Energie in eV int photonTargetMode = 0; // 0: Quantensprung (Schale +1), 1: Ionisation / Bindung spalten // Ziel-Erfassung (Auto-Targeting beim Bewegen der Maus) LabAtom lockedAtom = null; float lockedTransitionEv = 10.20; String lockedLabel = ""; // Labor-Geometrie & 2.5D-Optik int LAB_LEFT = 315; int LAB_WIDTH = 785; float gravCX = 708.0; float gravCY = 365.0; float focalLen = 420.0; // UI-Status & Barrierefreiheit int currentTheme = 0; // 0: DTIM Standard (Schwarz/Blutrot/Nachtblau), 1: Farbenblind, 2: Max-Kontrast boolean simPaused = false; LabAtom draggedAtom = null; float dragOffX = 0.0; float dragOffY = 0.0; String bannerText = "Ziele auf ein Atom oder Molekül und klicke zum Feuern! [1-4] Boson wählen"; int bannerTimer = 240; // DOOM 3D Reaktor-Modus boolean doomMode = false; boolean toroidalFieldActive = false; float posX = 4.5; float posY = 4.5; float dirX = 1.0; float dirY = 0.0; float planeX = 0.0; float planeY = 0.66; float moveSpeed = 0.085; float rotSpeed = 0.045; int DOOM_START_X = 315; int DOOM_VIEW_W = 785; float[] zBuffer = new float[785]; boolean keyW = false; boolean keyA = false; boolean keyS = false; boolean keyD = false; boolean keyTurnL = false; boolean keyTurnR = false; // ============================================================================================== // MODUL 2: FARB-PALETTEN & PHYSIKALISCHE FORMELN (SLATER-BOHR & BETHE-WEIZSÄCKER) // ============================================================================================== int getUiColor(int theme, int role) { if (theme == 1) { // Farbenblind-Optimiert (Blau / Gold-Amber) if (role == 0) return color(6, 10, 18); if (role == 1) return color(12, 18, 30); if (role == 2) return color(180, 120, 10); if (role == 3) return color(10, 75, 130); if (role == 4) return color(251, 191, 36); return color(255, 255, 255); } if (theme == 2) { // Maximal-Kontrast if (role == 0) return color(0, 0, 0); if (role == 1) return color(0, 0, 0); if (role == 2) return color(0, 0, 0); if (role == 3) return color(0, 0, 0); if (role == 4) return color(255, 255, 0); return color(255, 255, 255); } // Standard-Palette: Tiefschwarz, Dunkles Blutrot, Dunkles Nachtblau, Helles Silbergrau if (role == 0) return color(6, 8, 13); if (role == 1) return color(13, 16, 25); if (role == 2) return color(122, 16, 38); if (role == 3) return color(18, 46, 98); if (role == 4) return color(225, 55, 85); return color(242, 246, 255); } int getParticleColor(int theme, int pType) { // 1: Proton, 2: Neutron, 3: Elektron, 4: Photon, 5: Gluon, 6: W-Boson, 7: Positron, 8: Neutrino if (theme == 1) { if (pType == 1) return color(230, 159, 0); if (pType == 2) return color(190, 205, 225); if (pType == 3) return color(56, 189, 248); if (pType == 4) return color(250, 230, 70); if (pType == 5) return color(16, 185, 129); if (pType == 6) return color(213, 94, 0); if (pType == 7) return color(244, 114, 182); return color(165, 243, 252); } if (theme == 2) { if (pType == 1) return color(255, 255, 0); if (pType == 2) return color(255, 255, 255); if (pType == 3) return color(0, 255, 255); if (pType == 4) return color(255, 255, 0); if (pType == 5) return color(0, 255, 120); if (pType == 6) return color(255, 120, 255); if (pType == 7) return color(255, 180, 0); return color(255, 255, 255); } if (pType == 1) return color(220, 42, 74); // Proton: Blutrot if (pType == 2) return color(185, 198, 220); // Neutron: Silbergrau if (pType == 3) return color(65, 145, 255); // Elektron: Leuchtendes Blau if (pType == 4) return color(255, 215, 55); // Photon: Goldgelb if (pType == 5) return color(35, 205, 145); // Gluon: Smaragd if (pType == 6) return color(205, 85, 235); // W-Boson: Violett if (pType == 7) return color(255, 120, 150); // Positron: Hellrot return color(140, 235, 255); // Neutrino: Cyan } // Schalen-Energie nach Bohr-Slater-Modell in eV (liefert realistische Werte für H, He, C-12, O-16) float getShellEnergyEv(int Z, int electrons, int n) { if (Z <= 0) return -1.5; float zEff = 1.0; if (electrons <= 2) { zEff = max(1.0, float(Z) - 0.30 * float(electrons - 1)); } else { zEff = max(1.15, float(Z) - 0.85 * float(electrons - 1)); } return -13.6 * (zEff * zEff) / float(n * n); } // Bethe-Weizsäcker-Formel für die Kernbindungsenergie in MeV (C-12 -> ~92.16 MeV) float calcBetheWeizsaecker(int Z, int N) { int A = Z + N; if (A <= 1 || Z <= 0) return 0.0; float av = 15.8; float as = 18.3; float ac = 0.714; float aa = 23.2; float ap = 12.0; float Evol = av * A; float Esurf = as * pow(float(A), 2.0 / 3.0); float Ecoul = ac * Z * (Z - 1) / pow(float(A), 1.0 / 3.0); float Esym = aa * pow(float(A - 2 * Z), 2.0 / 3.0); // Korrekter Symmetrieterm (A - 2Z)^2 / A Esym = aa * pow(float(A - 2 * Z), 2.0) / float(A); float Epair = 0.0; if (A % 2 == 0) { if (Z % 2 == 0 && N % 2 == 0) Epair = ap / sqrt(float(A)); else Epair = -ap / sqrt(float(A)); } return max(0.0, Evol - Esurf - Ecoul - Esym + Epair); } String getElementSymbol(int Z) { if (Z == 0) return "n (Neutron)"; if (Z == 1) return "H (Wasserstoff)"; if (Z == 2) return "He (Helium)"; if (Z == 3) return "Li (Lithium)"; if (Z == 4) return "Be (Beryllium)"; if (Z == 5) return "B (Bor)"; if (Z == 6) return "C-12 (Kohlenstoff)"; if (Z == 7) return "N (Stickstoff)"; if (Z == 8) return "O (Sauerstoff)"; return "Z=" + Z; } void setBanner(String txt) { bannerText = txt; bannerTimer = 240; } // ============================================================================================== // MODUL 3: INITIALISIERUNG & EXPERIMENT-PRESETS (INKL. KOVALENTES H2, C-12 & H2O) // ============================================================================================== void setup() { size(1100, 720); noSmooth(); frameRate(60); simAtoms = new ArrayList(); simBosons = new ArrayList(); simEffects = new ArrayList(); simBonds = new ArrayList(); doomProjectiles = new ArrayList(); seedDefaultReactorGrid(); loadPresetExperiment(2); // Startet direkt mit der anschaulichen kovalenten H2-Bindung! } void loadPresetExperiment(int presetId) { simAtoms.clear(); simBosons.clear(); simEffects.clear(); simBonds.clear(); if (presetId == 1) { // Preset 1: Wasserstoff-Atom (n=1) + H+ Ion -> Photonen-Quantensprung & Elektronentausch LabAtom h1 = new LabAtom(gravCX - 110, gravCY - 20, 1, 0, 1); h1.vx = 0.35; h1.vy = -0.3; simAtoms.add(h1); LabAtom pIon = new LabAtom(gravCX + 120, gravCY + 30, 1, 0, 0); pIon.vx = -0.35; pIon.vy = 0.25; simAtoms.add(pIon); setBanner("H-Atom (n=1) & H+ Ion · Ziele mit Photon [1] für Quantensprung (10.20 eV)!"); } else if (presetId == 2) { // Preset 2: Kovalente H2-Bindung (2 Wasserstoff-Atome teilen sich ein Elektronenpaar!) LabAtom hLeft = new LabAtom(gravCX - 54, gravCY, 1, 0, 1); LabAtom hRight = new LabAtom(gravCX + 54, gravCY, 1, 0, 1); simAtoms.add(hLeft); simAtoms.add(hRight); setBanner("Kovalente H2-Bindung: Beide H-Atome teilen sich 2 Elektronen (Bindung: 4.52 eV)!"); } else if (presetId == 3) { // Preset 3: Kohlenstoff C-12 (6p, 6n, 6e -> 2 innere K-Elektronen + 4 äußere Valenzelektronen) LabAtom c12 = new LabAtom(gravCX, gravCY, 6, 6, 6); simAtoms.add(c12); float bMeV = calcBetheWeizsaecker(6, 6); setBanner("Kohlenstoff C-12: 2 innere (n=1) + 4 Valenzelektronen (n=2) · Kernbindung: " + nf(bMeV, 1, 2) + " MeV!"); } else if (presetId == 4) { // Preset 4: Wasser-Molekül H2O (Sauerstoff O-16 + 2 kovalent gebundene H-Atome im 104.5°-Winkel) LabAtom oxygen = new LabAtom(gravCX, gravCY - 26, 8, 8, 8); float halfRad = radians(52.25); // 104.5° / 2 float bondLen = 112.0; LabAtom hA = new LabAtom(gravCX - sin(halfRad) * bondLen, gravCY - 26 + cos(halfRad) * bondLen, 1, 0, 1); LabAtom hB = new LabAtom(gravCX + sin(halfRad) * bondLen, gravCY - 26 + cos(halfRad) * bondLen, 1, 0, 1); simAtoms.add(oxygen); simAtoms.add(hA); simAtoms.add(hB); setBanner("Wasser-Molekül H2O (104.5°): Sauerstoff (6 Valenz-e-) teilt je 1 Paar mit 2 H-Atomen!"); } else if (presetId == 5) { // Preset 5: Protonen-Fusion mit Gluon [2] LabAtom p1 = new LabAtom(gravCX - 46, gravCY - 20, 1, 0, 0); LabAtom p2 = new LabAtom(gravCX + 46, gravCY + 20, 1, 0, 0); LabAtom n1 = new LabAtom(gravCX, gravCY - 62, 0, 1, 0); simAtoms.add(p1); simAtoms.add(p2); simAtoms.add(n1); setBanner("Kernfusion: Schieße mit Gluon [2] zwischen die Protonen (überwindet Coulomb-Abstoßung)!"); } else if (presetId == 6) { // Preset 6: Helium-4 Edelgas-Atom (2p, 2n, 2e -> abgeschlossene K-Schale) LabAtom he4 = new LabAtom(gravCX, gravCY, 2, 2, 2); simAtoms.add(he4); setBanner("Helium-4 (abgeschlossene Schale n=1): Teste W-Boson [3] auf den Kern oder Ionisation!"); } } // ============================================================================================== // MODUL 4: HAUPTSCHLEIFE // ============================================================================================== void draw() { if (doomMode) { drawDoomMode(); return; } // 1. Hintergrund & Raumzeit-Gitter drawSpacetimeGrid(); // 2. Auto-Zielerfassung (berechnet Live-Sprungenergie dE beim Zielen mit der Maus) updateAutoTargeting(); // 3. Physik-Update (Atome, kovalente Bindungen, Elektronentausch, Bosonen) if (!simPaused) { updateAtomsAndBonds(); updateBosons(); } updateAndDrawEffects(); // 4. Kovalente Molekülorbitale & geteilte Elektronenpaare zeichnen drawCovalentBonds(); // 5. Atome & Schalen zeichnen for (int i = 0; i < simAtoms.size(); i++) { LabAtom a = (LabAtom) simAtoms.get(i); a.display(); } // 6. Bosonen-Projektile zeichnen for (int i = 0; i < simBosons.size(); i++) { BosonShot b = (BosonShot) simBosons.get(i); b.display(); } // 7. Ziel-Laser & Live-Energie-Anzeige im Labor drawTargetingOverlay(); // 8. Linkes Steuerpult & obere Statusleiste drawLeftControlDeck(); drawTopStatusBar(); } void drawSpacetimeGrid() { int bg = getUiColor(currentTheme, 0); background(bg); float R = 30.0; float sqrt3 = 1.7320508; strokeWeight(1.0); for (int q = -9; q <= 9; q++) { for (int r = -9; r <= 9; r++) { if (abs(q + r) <= 10) { float hx = gravCX + R * sqrt3 * (q + r * 0.5); float hy = gravCY + R * 1.5 * r; float d = dist(hx, hy, gravCX, gravCY); float vz = 380.0 * exp(-(d * d) / 36000.0); float sc = focalLen / (focalLen + vz); int glow = int(map(vz, 0, 380, 18, 120)); if (currentTheme == 2) stroke(75); else if (currentTheme == 1) stroke(20, 65 + glow, 140, 85); else stroke(25 + glow / 3, 48 + glow / 2, 125 + glow / 2, 85); noFill(); beginShape(); for (int i = 0; i < 6; i++) { float ang = radians(60 * i + 30); float vx = hx + R * cos(ang); float vy = hy + R * sin(ang); float px = gravCX + (vx - gravCX) * sc; float py = gravCY + (vy - gravCY) * sc; vertex(px, py); } endShape(CLOSE); } } } } // ============================================================================================== // MODUL 5: AUTO-TARGETING & RESONANZ-ENERGIE-BERECHNUNG // ============================================================================================== void updateAutoTargeting() { lockedAtom = null; float bestDist = 135.0; if (mouseX > LAB_LEFT) { for (int i = 0; i < simAtoms.size(); i++) { LabAtom a = (LabAtom) simAtoms.get(i); float d = dist(mouseX, mouseY, a.x, a.y); if (d < bestDist) { bestDist = d; lockedAtom = a; } } } if (lockedAtom != null) { if (activeEmitter == 1) { if (lockedAtom.electrons > 0) { int baseN = lockedAtom.getGroundOuterShell(); int curN = min(3, baseN + lockedAtom.excitedLevel); float eCur = getShellEnergyEv(lockedAtom.protons, lockedAtom.electrons, curN); if (photonTargetMode == 1 || curN >= 3) { if (lockedAtom.activeBondCount > 0 && photonTargetMode == 1) { lockedTransitionEv = 4.52; lockedLabel = "Photodissoziation (Bindung spalten): 4.52 eV"; } else { lockedTransitionEv = abs(eCur); lockedLabel = "Ionisation (n=" + curN + " -> frei): " + nf(lockedTransitionEv, 1, 2) + " eV"; } } else { int nextN = curN + 1; float eNext = getShellEnergyEv(lockedAtom.protons, lockedAtom.electrons, nextN); lockedTransitionEv = max(0.2, eNext - eCur); lockedLabel = "Quantensprung (n=" + curN + " -> n=" + nextN + "): " + nf(lockedTransitionEv, 1, 2) + " eV"; } if (autoResonance) { manualPhotonEv = lockedTransitionEv; } } else { lockedTransitionEv = 13.6; lockedLabel = "Kein Elektron (nackter Kern Z=" + lockedAtom.protons + ")"; } } else if (activeEmitter == 2) { lockedLabel = "Gluon-Kopplung: Überwindet Coulomb-Barriere bei Abstand < 95 px"; } else if (activeEmitter == 3) { if (lockedAtom.protons > 0) lockedLabel = "W-Boson: p -> n + Positron (e+) + Neutrino"; else if (lockedAtom.neutrons > 0) lockedLabel = "W-Boson: n -> p + Elektron (e-) + Anti-Neutrino"; else lockedLabel = "Schwache Wechselwirkung bereit"; } else { lockedLabel = "Elektron-Injektion: Füllt Schale von " + getElementSymbol(lockedAtom.protons); } } else { lockedLabel = ""; } } void drawTargetingOverlay() { float gunX = gravCX; float gunY = height - 22; float aimX = (lockedAtom != null) ? lockedAtom.x : max(LAB_LEFT + 20, mouseX); float aimY = (lockedAtom != null) ? lockedAtom.y : min(height - 50, max(50, mouseY)); int pIdx = 3; if (activeEmitter == 1) pIdx = 4; else if (activeEmitter == 2) pIdx = 5; else if (activeEmitter == 3) pIdx = 6; int beamCol = getParticleColor(currentTheme, pIdx); stroke(beamCol); strokeWeight(lockedAtom != null ? 2.0 : 1.0); line(gunX, gunY, aimX, aimY); strokeWeight(1.0); fill(getUiColor(currentTheme, 2)); stroke(255); ellipse(gunX, gunY, 24, 24); if (lockedAtom != null) { noFill(); stroke(beamCol); strokeWeight(2.0); ellipse(lockedAtom.x, lockedAtom.y, 92, 92); strokeWeight(1.0); float boxX = constrain(lockedAtom.x + 54, LAB_LEFT + 10, width - 305); float boxY = constrain(lockedAtom.y - 34, 46, height - 66); fill(10, 13, 22, 238); stroke(beamCol); rect(boxX, boxY, 295, 48, 6); fill(255); textSize(11); textAlign(LEFT, TOP); String bondTag = (lockedAtom.activeBondCount > 0) ? " · Kovalent (" + lockedAtom.activeBondCount + ")" : ""; text("ZIEL: " + getElementSymbol(lockedAtom.protons) + " (Z=" + lockedAtom.protons + ", e=" + lockedAtom.electrons + ")" + bondTag, boxX + 8, boxY + 6); fill(beamCol); text(lockedLabel, boxX + 8, boxY + 24); } } // ============================================================================================== // MODUL 6: ATOM-KLASSE (MEHRSCHALEN-MODELL), KOVALENTE BINDUNGEN & ELEKTRONENTAUSCH // ============================================================================================== class CovalentLink { LabAtom a; LabAtom b; float eqDist; CovalentLink(LabAtom atomA, LabAtom atomB, float distEq) { a = atomA; b = atomB; eqDist = distEq; } } class LabAtom { float x, y, vx, vy; int protons; int neutrons; int electrons; int excitedLevel; // 0 = Grundzustand, 1 = +1 Schale, 2 = +2 Schalen int excitationTimer; int bondCooldown; // Sperrzeit nach Photodissoziation int activeBondCount; // Anzahl aktueller kovalenter Bindungen float orbitAngle; boolean destroyed; LabAtom(float startX, float startY, int p, int n, int e) { x = startX; y = startY; vx = 0.0; vy = 0.0; protons = p; neutrons = n; electrons = e; excitedLevel = 0; excitationTimer = 0; bondCooldown = 0; activeBondCount = 0; orbitAngle = random(TWO_PI); destroyed = false; } int getGroundOuterShell() { if (electrons <= 2) return 1; if (electrons <= 10) return 2; return 3; } // Maximale kovalente Bindungszahl nach Oktett-/Duplett-Regel (H: 1, C: 4, N: 3, O: 2, He: 0) int getMaxCovalentBonds() { if (protons <= 0 || electrons <= 0) return 0; if (protons == 1) { return (electrons == 1) ? 1 : 0; } if (protons <= 10) { int valenceE = max(0, electrons - 2); int openSlots = max(0, 8 - valenceE); return min(valenceE, openSlots); } return 1; } void update() { orbitAngle += 0.042 / float(getGroundOuterShell() + excitedLevel); if (bondCooldown > 0) bondCooldown--; // Spontane Emission: Angeregtes Elektron fällt in Grundschale zurück und sendet Photon aus! if (excitedLevel > 0 && electrons > 0) { excitationTimer--; if (excitationTimer <= 0) { int baseN = getGroundOuterShell(); int oldN = min(3, baseN + excitedLevel); excitedLevel = 0; float eOld = getShellEnergyEv(protons, electrons, oldN); float eNew = getShellEnergyEv(protons, electrons, baseN); float emittedEv = max(0.5, eOld - eNew); float emitAng = random(TWO_PI); BosonShot emittedPhoton = new BosonShot(x, y, cos(emitAng) * 5.2, sin(emitAng) * 5.2, 4, emittedEv, true); simBosons.add(emittedPhoton); simEffects.add(new WaveRing(x, y, getParticleColor(currentTheme, 4))); setBanner("Spontane Emission! Elektron fällt n=" + oldN + " -> n=" + baseN + " und sendet Photon (" + nf(emittedEv, 1, 2) + " eV) aus!"); } } if (draggedAtom != this) { // Sanfte Gravitations-Zentrierung ins Labor float dx = gravCX - x; float dy = gravCY - y; float d = sqrt(dx * dx + dy * dy); if (d > 30.0) { vx += (dx / d) * 0.010; vy += (dy / d) * 0.010; } vx *= 0.96; vy *= 0.96; x += vx; y += vy; if (x < LAB_LEFT + 55) { x = LAB_LEFT + 55; vx = abs(vx) * 0.7; } if (x > width - 55) { x = width - 55; vx = -abs(vx) * 0.7; } if (y < 75) { y = 75; vy = abs(vy) * 0.7; } if (y > height - 55) { y = height - 55; vy = -abs(vy) * 0.7; } } } void display() { int baseN = getGroundOuterShell(); int activeOuterN = min(3, baseN + excitedLevel); // Elektronen auf Schalen n=1 (K), n=2 (L), n=3 (M) aufteilen int e1 = min(2, electrons); int e2 = max(0, min(8, electrons - 2)); int e3 = max(0, electrons - 10); if (excitedLevel > 0 && electrons > 0) { if (e3 > 0) { // bleibt auf M } else if (e2 > 0) { e2--; e3++; } else if (e1 > 0) { e1--; if (excitedLevel == 1) e2++; else e3++; } } // 1. Schalen-Ringe (n=1, 2, 3) zeichnen noFill(); for (int s = 1; s <= 3; s++) { float sr = 28.0 + s * 17.0; boolean hasE = (s == 1 && e1 > 0) || (s == 2 && e2 > 0) || (s == 3 && e3 > 0); if (hasE) { stroke(getParticleColor(currentTheme, 3)); strokeWeight(s == activeOuterN ? 1.5 : 1.0); } else { stroke(65, 80, 110, 75); strokeWeight(1.0); } ellipse(x, y, sr * 2.0, sr * 2.0); } // 2. Elektronen auf K-, L- und M-Schale zeichnen drawShellElectrons(1, e1, orbitAngle * 1.35); drawShellElectrons(2, e2, -orbitAngle * 0.95); drawShellElectrons(3, e3, orbitAngle * 0.70); // 3. Atomkern (Protonen & Neutronen) int totalNuc = protons + neutrons; if (totalNuc == 0) { fill(getParticleColor(currentTheme, 3)); stroke(255); ellipse(x, y, 14, 14); } else { int pCol = getParticleColor(currentTheme, 1); int nCol = getParticleColor(currentTheme, 2); for (int k = 0; k < totalNuc; k++) { float offX = 0.0; float offY = 0.0; if (totalNuc > 1) { float kAng = (TWO_PI * k) / float(totalNuc) + frameCount * 0.015; float kRad = min(15.0, 4.0 + totalNuc * 1.15); offX = cos(kAng) * kRad; offY = sin(kAng) * kRad; } if (k < protons) fill(pCol); else fill(nCol); stroke(255, 160); ellipse(x + offX, y + offY, 15, 15); } } // 4. Beschriftung unter dem äußersten belegten Orbital float labelOffset = 28.0 + activeOuterN * 17.0 + 7.0; int netCharge = protons - electrons; String chargeStr = (netCharge == 0) ? "neutral" : ((netCharge > 0) ? "+" + netCharge + " Ion" : netCharge + " Ion"); fill(245); textSize(11); textAlign(CENTER, TOP); String title = (totalNuc == 0) ? "Freies e-" : getElementSymbol(protons) + " [" + chargeStr + "]"; text(title, x, y + labelOffset); } void drawShellElectrons(int shellNum, int count, float phaseBase) { if (count <= 0) return; float sr = 28.0 + shellNum * 17.0; int eCol = getParticleColor(currentTheme, 3); for (int i = 0; i < count; i++) { float ang = phaseBase + (TWO_PI * i) / float(count); float ex = x + cos(ang) * sr; float ey = y + sin(ang) * sr; noStroke(); fill(eCol); ellipse(ex, ey, 10, 10); fill(255); ellipse(ex - 2, ey - 2, 3, 3); } } } void updateAtomsAndBonds() { simBonds.clear(); for (int i = 0; i < simAtoms.size(); i++) { LabAtom a = (LabAtom) simAtoms.get(i); a.activeBondCount = 0; a.update(); } // Paarweise Wechselwirkungen: Kovalente Bindung, Elektronentausch & Coulomb-Abstoßung for (int i = 0; i < simAtoms.size(); i++) { LabAtom a1 = (LabAtom) simAtoms.get(i); if (a1.destroyed) continue; for (int j = i + 1; j < simAtoms.size(); j++) { LabAtom a2 = (LabAtom) simAtoms.get(j); if (a2.destroyed) continue; float dx = a2.x - a1.x; float dy = a2.y - a1.y; float d = max(1.0, sqrt(dx * dx + dy * dy)); // A) Freies Elektron wird von positivem Ion eingefangen if (a1.protons == 0 && a1.neutrons == 0 && a1.electrons > 0 && a2.protons > a2.electrons && d < 75.0) { a2.electrons += a1.electrons; a1.destroyed = true; simEffects.add(new WaveRing(a2.x, a2.y, getParticleColor(currentTheme, 3))); setBanner("Elektronen-Einfang! " + getElementSymbol(a2.protons) + " fängt freies Elektron ein."); break; } if (a2.protons == 0 && a2.neutrons == 0 && a2.electrons > 0 && a1.protons > a1.electrons && d < 75.0) { a1.electrons += a2.electrons; a2.destroyed = true; simEffects.add(new WaveRing(a1.x, a1.y, getParticleColor(currentTheme, 3))); setBanner("Elektronen-Einfang! " + getElementSymbol(a1.protons) + " fängt freies Elektron ein."); break; } // B) Kovalente Elektronenpaar-Bindung (z. B. H2, C-H, H2O) boolean canBond1 = (a1.bondCooldown == 0) && (a1.activeBondCount < a1.getMaxCovalentBonds()); boolean canBond2 = (a2.bondCooldown == 0) && (a2.activeBondCount < a2.getMaxCovalentBonds()); if (canBond1 && canBond2 && d >= 55.0 && d <= 155.0) { float eqDist = (a1.protons == 1 && a2.protons == 1) ? 104.0 : 114.0; simBonds.add(new CovalentLink(a1, a2, eqDist)); a1.activeBondCount++; a2.activeBondCount++; // Harmonische Bindungsfeder (hält Molekül im Gleichgewichtsabstand) float springF = (d - eqDist) * 0.014; float nx = dx / d; float ny = dy / d; if (draggedAtom != a1) { a1.vx += nx * springF; a1.vy += ny * springF; } if (draggedAtom != a2) { a2.vx -= nx * springF; a2.vy -= ny * springF; } continue; } // C) Elektronentausch zwischen Ion und Atom bei mittlerem Abstand if (d > 65.0 && d < 145.0 && a1.protons > 0 && a2.protons > 0) { int q1 = a1.protons - a1.electrons; int q2 = a2.protons - a2.electrons; if ((q1 > 0 && a2.electrons > 0) || (q2 > 0 && a1.electrons > 0)) { stroke(getParticleColor(currentTheme, 3)); strokeWeight(1.4); line(a1.x, a1.y, a2.x, a2.y); strokeWeight(1.0); if (frameCount % 95 == 0) { if (q1 > 0 && a2.electrons > 0) { a2.electrons--; a1.electrons++; simEffects.add(new WaveRing((a1.x + a2.x) * 0.5, (a1.y + a2.y) * 0.5, getParticleColor(currentTheme, 3))); setBanner("Elektronentausch! Elektron springt von " + getElementSymbol(a2.protons) + " zu " + getElementSymbol(a1.protons)); } else if (q2 > 0 && a1.electrons > 0) { a1.electrons--; a2.electrons++; simEffects.add(new WaveRing((a1.x + a2.x) * 0.5, (a1.y + a2.y) * 0.5, getParticleColor(currentTheme, 3))); setBanner("Elektronentausch! Elektron springt von " + getElementSymbol(a1.protons) + " zu " + getElementSymbol(a2.protons)); } } } } // D) Coulomb-Abstoßung bei zu geringem Kernabstand (< 88 px) if (d < 88.0 && a1.protons > 0 && a2.protons > 0) { float push = (88.0 - d) * 0.020; float nx = dx / d; float ny = dy / d; a1.vx -= nx * push; a1.vy -= ny * push; a2.vx += nx * push; a2.vy += ny * push; noFill(); stroke(255, 110, 110, 120); ellipse((a1.x + a2.x) * 0.5, (a1.y + a2.y) * 0.5, 34, 34); } } } for (int i = simAtoms.size() - 1; i >= 0; i--) { LabAtom a = (LabAtom) simAtoms.get(i); if (a.destroyed) simAtoms.remove(i); } } // Zeichnet für jede kovalente Bindung das gemeinsame Molekülorbital + 2 Figure-8-Elektronen void drawCovalentBonds() { int eCol = getParticleColor(currentTheme, 3); int glowCol = (currentTheme == 2) ? color(255, 255, 0) : color(56, 189, 248); for (int i = 0; i < simBonds.size(); i++) { CovalentLink link = (CovalentLink) simBonds.get(i); float mx = (link.a.x + link.b.x) * 0.5; float my = (link.a.y + link.b.y) * 0.5; float dx = link.b.x - link.a.x; float dy = link.b.y - link.a.y; float d = max(1.0, sqrt(dx * dx + dy * dy)); float ang = atan2(dy, dx); pushMatrix(); translate(mx, my); rotate(ang); // Äußere Molekülorbital-Hülle (bindendes Sigma-Orbital) noFill(); stroke(glowCol); strokeWeight(1.8); ellipse(0, 0, d + 44.0, 44.0); strokeWeight(1.0); // Zwei gemeinsam geteilte Elektronen auf einer Figure-8-Bahn (Lemniskate) um beide Kerne! float t1 = frameCount * 0.055 + i; float t2 = t1 + PI; float semiA = d * 0.62; float semiB = 16.0; float ex1 = sin(t1) * semiA; float ey1 = sin(2.0 * t1) * semiB; float ex2 = sin(t2) * semiA; float ey2 = sin(2.0 * t2) * semiB; noStroke(); fill(eCol); ellipse(ex1, ey1, 11, 11); ellipse(ex2, ey2, 11, 11); fill(255); ellipse(ex1 - 2, ey1 - 2, 3, 3); ellipse(ex2 - 2, ey2 - 2, 3, 3); popMatrix(); } } // ============================================================================================== // MODUL 7: BOSONEN-BESCHUSS (PHOTON, GLUON, W-BOSON, ELEKTRON) // ============================================================================================== class BosonShot { float x, y, vx, vy; int kind; float energyEv; boolean isEmitted; int life; BosonShot(float sx, float sy, float svx, float svy, int k, float ev, boolean emitted) { x = sx; y = sy; vx = svx; vy = svy; kind = k; energyEv = ev; isEmitted = emitted; life = 160; } void display() { int col = getParticleColor(currentTheme, kind); if (kind == 4) { stroke(col); strokeWeight(2.5); float ang = atan2(vy, vx); pushMatrix(); translate(x, y); rotate(ang); noFill(); beginShape(); for (int wx = -14; wx <= 14; wx += 4) { vertex(wx, sin(wx * 0.45 + frameCount * 0.4) * 5.0); } endShape(); popMatrix(); strokeWeight(1.0); } else { fill(col); stroke(255); ellipse(x, y, 13, 13); } } } void fireActiveEmitter() { float gunX = gravCX; float gunY = height - 22; float tx = (lockedAtom != null) ? lockedAtom.x : max(LAB_LEFT + 20, mouseX); float ty = (lockedAtom != null) ? lockedAtom.y : min(height - 50, max(50, mouseY)); float ang = atan2(ty - gunY, tx - gunX); float spd = 7.4; if (activeEmitter == 1) { simBosons.add(new BosonShot(gunX, gunY, cos(ang) * spd, sin(ang) * spd, 4, manualPhotonEv, false)); } else if (activeEmitter == 2) { simBosons.add(new BosonShot(gunX, gunY, cos(ang) * spd, sin(ang) * spd, 5, 15.0, false)); } else if (activeEmitter == 3) { simBosons.add(new BosonShot(gunX, gunY, cos(ang) * spd, sin(ang) * spd, 6, 80.4, false)); } else { LabAtom freeE = new LabAtom(gunX, gunY - 12, 0, 0, 1); freeE.vx = cos(ang) * 4.8; freeE.vy = sin(ang) * 4.8; simAtoms.add(freeE); setBanner("Freies Elektron (e-) abgefeuert!"); } } void updateBosons() { for (int i = simBosons.size() - 1; i >= 0; i--) { BosonShot b = (BosonShot) simBosons.get(i); b.x += b.vx; b.y += b.vy; b.life--; if (b.life <= 0 || b.x < LAB_LEFT || b.x > width || b.y < 36 || b.y > height) { simBosons.remove(i); continue; } if (b.isEmitted) continue; boolean hitHandled = false; for (int j = 0; j < simAtoms.size(); j++) { LabAtom a = (LabAtom) simAtoms.get(j); if (a.destroyed) continue; int outerN = min(3, a.getGroundOuterShell() + a.excitedLevel); float hitRadius = 30.0 + outerN * 15.0; if (dist(b.x, b.y, a.x, a.y) < hitRadius) { resolveBosonImpact(b, a); hitHandled = true; break; } } if (hitHandled) { simBosons.remove(i); } } } void resolveBosonImpact(BosonShot b, LabAtom target) { if (b.kind == 4) { // 1. PHOTON-TREFFER (Photodissoziation, Photo-Ionisation oder Quantensprung) if (target.electrons <= 0) { setBanner("Photon trifft nackten Kern (kein Elektron vorhanden)."); return; } // Photodissoziation, falls target kovalent gebunden ist und im Spalt-/Ionisations-Modus getroffen wird if (target.activeBondCount > 0 && photonTargetMode == 1 && b.energyEv >= 4.4) { target.bondCooldown = 210; target.vx += b.vx * 0.45; target.vy += b.vy * 0.45; simEffects.add(new WaveRing(target.x, target.y, getParticleColor(currentTheme, 4))); setBanner("PHOTODISSOZIATION! Photon (" + nf(b.energyEv, 1, 2) + " eV) spaltet die kovalente Bindung!"); return; } int baseN = target.getGroundOuterShell(); int curN = min(3, baseN + target.excitedLevel); float eCur = getShellEnergyEv(target.protons, target.electrons, curN); float ionEv = abs(eCur); if (b.energyEv >= ionEv - 0.15) { target.electrons--; target.excitedLevel = 0; LabAtom ejectedE = new LabAtom(target.x + 30, target.y - 22, 0, 0, 1); ejectedE.vx = b.vx * 0.55 + random(-1.0, 1.0); ejectedE.vy = b.vy * 0.55 + random(-1.0, 1.0); simAtoms.add(ejectedE); simEffects.add(new WaveRing(target.x, target.y, getParticleColor(currentTheme, 4))); setBanner("PHOTO-IONISATION! Photon (" + nf(b.energyEv, 1, 2) + " eV) löst Elektron aus " + getElementSymbol(target.protons) + "!"); } else if (curN < 3) { float eNext = getShellEnergyEv(target.protons, target.electrons, curN + 1); float neededEv = eNext - eCur; if (abs(b.energyEv - neededEv) <= 0.65) { target.excitedLevel++; target.excitationTimer = 180; int newShell = min(3, baseN + target.excitedLevel); simEffects.add(new WaveRing(target.x, target.y, getParticleColor(currentTheme, 3))); setBanner("QUANTENSPRUNG! Elektron springt auf Schale n=" + newShell + " (dE = " + nf(neededEv, 1, 2) + " eV)!"); } else { setBanner("Keine Resonanz! Photon (" + nf(b.energyEv, 1, 2) + " eV) != Sprung-Energie (" + nf(neededEv, 1, 2) + " eV)."); } } } else if (b.kind == 5) { // 2. GLUON-TREFFER (Starke Kernkraft -> Kernfusion) LabAtom partner = null; float bestD = 125.0; for (int k = 0; k < simAtoms.size(); k++) { LabAtom other = (LabAtom) simAtoms.get(k); if (other != target && !other.destroyed && (other.protons + other.neutrons) > 0) { float d = dist(target.x, target.y, other.x, other.y); if (d < bestD) { bestD = d; partner = other; } } } if (partner != null) { target.protons += partner.protons; target.neutrons += partner.neutrons; target.electrons += partner.electrons; target.x = (target.x + partner.x) * 0.5; target.y = (target.y + partner.y) * 0.5; partner.destroyed = true; float bindMeV = calcBetheWeizsaecker(target.protons, target.neutrons); simEffects.add(new WaveRing(target.x, target.y, getParticleColor(currentTheme, 5))); setBanner("KERNFUSION! Neuer Kern: " + getElementSymbol(target.protons) + " (A=" + (target.protons + target.neutrons) + ") · Bindungsenergie: " + nf(bindMeV, 1, 2) + " MeV!"); } else { simEffects.add(new WaveRing(target.x, target.y, getParticleColor(currentTheme, 5))); setBanner("Gluon stärkt Kernbindung! (Ziehe zweiten Kern mit Rechtsklick näher heran für Fusion)"); } } else if (b.kind == 6) { // 3. W-BOSON (Schwache Wechselwirkung: p <-> n Umwandlung) if (target.protons > 0) { target.protons--; target.neutrons++; simBosons.add(new BosonShot(target.x, target.y, -3.8, -2.6, 7, 0.51, true)); simBosons.add(new BosonShot(target.x, target.y, 4.2, -2.1, 8, 0.10, true)); simEffects.add(new WaveRing(target.x, target.y, getParticleColor(currentTheme, 6))); setBanner("SCHWACHE WECHSELWIRKUNG: Proton -> Neutron + Positron (e+) + Neutrino!"); } else if (target.neutrons > 0) { target.neutrons--; target.protons++; LabAtom betaE = new LabAtom(target.x + 25, target.y - 15, 0, 0, 1); betaE.vx = 3.5; betaE.vy = -2.2; simAtoms.add(betaE); simBosons.add(new BosonShot(target.x, target.y, -4.0, -2.5, 8, 0.10, true)); simEffects.add(new WaveRing(target.x, target.y, getParticleColor(currentTheme, 6))); setBanner("BETA-ZERFALL: Neutron -> Proton + Elektron (e-) + Anti-Neutrino!"); } } } class WaveRing { float x, y, r; int col; int alpha; WaveRing(float wx, float wy, int c) { x = wx; y = wy; r = 12.0; col = c; alpha = 235; } } void updateAndDrawEffects() { for (int i = simEffects.size() - 1; i >= 0; i--) { WaveRing w = (WaveRing) simEffects.get(i); w.r += 2.6; w.alpha -= 9; if (w.alpha <= 0) { simEffects.remove(i); } else { noFill(); stroke(red(w.col), green(w.col), blue(w.col), w.alpha); strokeWeight(2.2); ellipse(w.x, w.y, w.r * 2.0, w.r * 2.0); strokeWeight(1.0); } } } // ============================================================================================== // MODUL 8: LINKES STEUERPULT & OBERE STATUSLEISTE // ============================================================================================== void drawTopStatusBar() { int barBg = getUiColor(currentTheme, 1); int borderC = getUiColor(currentTheme, 4); fill(barBg); noStroke(); rect(LAB_LEFT, 0, LAB_WIDTH, 38); stroke(borderC); line(LAB_LEFT, 38, width, 38); fill(255); textSize(12); textAlign(LEFT, CENTER); if (bannerTimer > 0) bannerTimer--; text(bannerText, LAB_LEFT + 12, 19); int btnBlue = getUiColor(currentTheme, 3); int btnBlood = getUiColor(currentTheme, 2); String a11yLbl = "Sehhilfe [H]"; if (currentTheme == 1) a11yLbl = "Farbenblind"; if (currentTheme == 2) a11yLbl = "Max-Kontrast"; drawUiBtn(width - 375, 6, 128, 26, a11yLbl, btnBlue); drawUiBtn(width - 240, 6, 115, 26, "DOOM 3D", btnBlood); drawUiBtn(width - 118, 6, 106, 26, simPaused ? "Weiter" : "Pause", btnBlue); } void drawLeftControlDeck() { int panelBg = getUiColor(currentTheme, 1); int bloodC = getUiColor(currentTheme, 2); int blueC = getUiColor(currentTheme, 3); int accentC = getUiColor(currentTheme, 4); fill(panelBg); stroke(accentC); rect(0, 0, LAB_LEFT, height); // Titelblock fill(bloodC); noStroke(); rect(1, 1, LAB_LEFT - 2, 36); fill(255); textSize(14); textAlign(LEFT, CENTER); text("DTIM-ZEC QUANTEN- & MOLEKÜL-LABOR", 12, 19); // Sektion 1: Bosonen- & Teilchen-Emitter (1..4) fill(230, 238, 250); textSize(11); text("1. BOSONEN-KANONE WÄHLEN:", 14, 50); drawEmitterChoice(14, 62, 1, "[1] Photon (Quantensprung)", getParticleColor(currentTheme, 4)); drawEmitterChoice(14, 98, 2, "[2] Gluon (Kern-Fusion)", getParticleColor(currentTheme, 5)); drawEmitterChoice(14, 134, 3, "[3] W-Boson (p <-> n)", getParticleColor(currentTheme, 6)); drawEmitterChoice(14, 170, 4, "[4] Elektron (Schale / Ion)", getParticleColor(currentTheme, 3)); // Sektion 2: Photonen-Energie & Auto-Resonanz fill(blueC); stroke(accentC); rect(14, 212, LAB_LEFT - 28, 114, 6); fill(255); textSize(11); textAlign(LEFT, TOP); text("2. SPRUNG- & BINDUNGSENERGIE:", 22, 219); int resBg = autoResonance ? color(20, 125, 75) : color(55, 65, 85); drawUiBtn(22, 238, LAB_LEFT - 44, 26, autoResonance ? "Auto-Resonanz [A]: AN" : "Auto-Resonanz [A]: AUS", resBg); drawUiBtn(22, 270, 146, 25, photonTargetMode == 0 ? "Ziel: Schale +1" : "Ziel: Ionis./Spalten", bloodC); drawUiBtn(174, 270, 56, 25, "- eV", color(30, 38, 55)); drawUiBtn(236, 270, 56, 25, "+ eV", color(30, 38, 55)); fill(255); textSize(12); textAlign(LEFT, CENTER); text("Energie: " + nf(manualPhotonEv, 1, 2) + " eV", 22, 310); // Sektion 3: Spiel- & Lern-Szenarien (6 Presets inkl. H2, C-12, H2O) fill(230, 238, 250); textSize(11); textAlign(LEFT, CENTER); text("3. MOLEKÜL- & ATOM-PRESETS:", 14, 342); drawUiBtn(14, 354, LAB_LEFT - 28, 26, "H-Atom & H+ (Quantensprung)", blueC); drawUiBtn(14, 384, LAB_LEFT - 28, 26, "Kovalente H2-Bindung (Molekül)", bloodC); drawUiBtn(14, 414, LAB_LEFT - 28, 26, "Kohlenstoff C-12 (2 + 4 e-)", blueC); drawUiBtn(14, 444, LAB_LEFT - 28, 26, "Wasser-Molekül H2O (104.5°)", blueC); drawUiBtn(14, 474, LAB_LEFT - 28, 26, "Protonen-Fusion (mit Gluon)", blueC); drawUiBtn(14, 504, LAB_LEFT - 28, 26, "Helium-4 Kern (W-Boson & Ion)", blueC); // Sektion 4: Atome & Bausteine direkt hinzufügen fill(230, 238, 250); text("4. BAUSTEINE HINZUFÜGEN:", 14, 546); drawUiBtn(14, 558, 138, 26, "+ Proton (H+)", getParticleColor(currentTheme, 1)); drawUiBtn(162, 558, 138, 26, "+ Neutron (n)", color(75, 88, 110)); drawUiBtn(14, 590, 138, 26, "+ H-Atom (1p,1e)", blueC); drawUiBtn(162, 590, 138, 26, "Labor leeren", bloodC); // Kurzanleitung unten fill(205, 218, 240); textSize(11); textAlign(LEFT, TOP); text("Linksklick = Boson abfeuern\nRechtsklick + Ziehen = Atom bewegen\nTipp: H-Atome an C-12 andocken!", 14, 628); } void drawEmitterChoice(int bx, int by, int id, String label, int badgeCol) { boolean selected = (activeEmitter == id); if (currentTheme == 2) { fill(0); if (selected) stroke(255, 255, 0); else stroke(255); } else { if (selected) { fill(getUiColor(currentTheme, 2)); stroke(getUiColor(currentTheme, 4)); } else { fill(20, 25, 38); stroke(55, 68, 95); } } rect(bx, by, LAB_LEFT - 28, 30, 5); fill(badgeCol); stroke(255); ellipse(bx + 16, by + 15, 13, 13); fill(255); textSize(12); textAlign(LEFT, CENTER); text(label, bx + 30, by + 15); } void drawUiBtn(int bx, int by, int bw, int bh, String label, int bgCol) { if (currentTheme == 2) { fill(0); stroke(255, 255, 0); } else { fill(bgCol); stroke(120, 145, 195); } rect(bx, by, bw, bh, 5); if (currentTheme == 2) fill(255, 255, 0); else fill(255); textSize(11); textAlign(CENTER, CENTER); text(label, bx + bw * 0.5, by + bh * 0.5); } // ============================================================================================== // MODUL 9: DOOM 3D REAKTOR-MODUS (OHNE P3D) // ============================================================================================== int getGridCell(int x, int y, int z) { if (x < 0 || x >= GRID_DIM || y < 0 || y >= GRID_DIM || z < 0 || z >= GRID_DEPTH) return -1; return gridData[x + y * GRID_DIM + z * GRID_DIM * GRID_DIM]; } void setGridCell(int x, int y, int z, int val) { if (x < 0 || x >= GRID_DIM || y < 0 || y >= GRID_DIM || z < 0 || z >= GRID_DEPTH) return; gridData[x + y * GRID_DIM + z * GRID_DIM * GRID_DIM] = val; } void seedDefaultReactorGrid() { for (int z = 0; z < GRID_DEPTH; z++) { for (int y = 0; y <= num; y++) { for (int x = 0; x <= num; x++) { if (x == 0 || y == 0 || x == num || y == num) setGridCell(x, y, z, (z % 2 == 0) ? 1 : 3); else setGridCell(x, y, z, 0); } } if (z < 6) { for (int k = 10; k <= 20; k++) { if (k != 15) { setGridCell(k, 10, z, 3); setGridCell(k, 20, z, 3); setGridCell(10, k, z, 1); setGridCell(20, k, z, 1); } } } } } void drawDoomMode() { background(0); float spd = toroidalFieldActive ? moveSpeed * 3.0 : moveSpeed; if (keyTurnL) rotateDoomCam(-rotSpeed); if (keyTurnR) rotateDoomCam(rotSpeed); if (keyW) { if (toroidalFieldActive || getGridCell(int(posX + dirX * spd), int(posY), level) == 0) posX += dirX * spd; if (toroidalFieldActive || getGridCell(int(posX), int(posY + dirY * spd), level) == 0) posY += dirY * spd; } if (keyS) { if (toroidalFieldActive || getGridCell(int(posX - dirX * spd), int(posY), level) == 0) posX -= dirX * spd; if (toroidalFieldActive || getGridCell(int(posX), int(posY - dirY * spd), level) == 0) posY -= dirY * spd; } if (keyA) { float sx = dirY; float sy = -dirX; if (toroidalFieldActive || getGridCell(int(posX + sx * spd), int(posY), level) == 0) posX += sx * spd; if (toroidalFieldActive || getGridCell(int(posX), int(posY + sy * spd), level) == 0) posY += sy * spd; } if (keyD) { float sx = -dirY; float sy = dirX; if (toroidalFieldActive || getGridCell(int(posX + sx * spd), int(posY), level) == 0) posX += sx * spd; if (toroidalFieldActive || getGridCell(int(posX), int(posY + sy * spd), level) == 0) posY += sy * spd; } float span = float(num - 2); if (posX < 1.1) posX += span; if (posX >= num - 1.1) posX -= span; if (posY < 1.1) posY += span; if (posY >= num - 1.1) posY -= span; noStroke(); fill(18, 6, 12); rect(DOOM_START_X, 0, DOOM_VIEW_W, height / 2); fill(10, 16, 30); rect(DOOM_START_X, height / 2, DOOM_VIEW_W, height / 2); for (int x = 0; x < DOOM_VIEW_W; x++) { float camX = 2.0 * x / float(DOOM_VIEW_W) - 1.0; float rdx = dirX + planeX * camX; float rdy = dirY + planeY * camX; int mx = int(posX); int my = int(posY); float ddx = (rdx == 0.0) ? 1e30 : abs(1.0 / rdx); float ddy = (rdy == 0.0) ? 1e30 : abs(1.0 / rdy); int stepX = (rdx < 0) ? -1 : 1; int stepY = (rdy < 0) ? -1 : 1; float sdx = (rdx < 0) ? (posX - mx) * ddx : (mx + 1.0 - posX) * ddx; float sdy = (rdy < 0) ? (posY - my) * ddy : (my + 1.0 - posY) * ddy; int hit = 0, side = 0, hType = 0, guard = 0; while (hit == 0 && guard < 64 && mx > 0 && mx < num && my > 0 && my < num) { guard++; if (sdx < sdy) { sdx += ddx; mx += stepX; side = 0; } else { sdy += ddy; my += stepY; side = 1; } hType = getGridCell(mx, my, level); if (hType != 0) hit = 1; } float distW = (side == 0) ? max(0.08, (mx - posX + (1 - stepX) * 0.5) / rdx) : max(0.08, (my - posY + (1 - stepY) * 0.5) / rdy); zBuffer[x] = distW; int lh = int(height / distW); int y0 = max(0, -lh / 2 + height / 2); int y1 = min(height - 1, lh / 2 + height / 2); int baseC = (hType <= 0) ? color(130, 140, 160) : getParticleColor(currentTheme, hType); float sh = constrain(1.0 / (1.0 + distW * 0.14), 0.22, 1.0); if (side == 1) sh *= 0.72; stroke(red(baseC) * sh, green(baseC) * sh, blue(baseC) * sh); line(DOOM_START_X + x, y0, DOOM_START_X + x, y1); } fill(getUiColor(currentTheme, 1)); noStroke(); rect(0, 0, DOOM_START_X, height); stroke(getUiColor(currentTheme, 4)); line(DOOM_START_X, 0, DOOM_START_X, height); fill(255); textSize(15); textAlign(LEFT, TOP); text("DTIM-ZEC DOOM 3D REAKTOR", 16, 16); textSize(12); text("Steuerung: [W/A/S/D] + Maus ziehen\n[T] Torus-Feld | [ESC] Zurück", 16, 44); float tile = 260.0 / float(num + 1); for (int y = 0; y <= num; y++) { for (int x = 0; x <= num; x++) { int c = getGridCell(x, y, level); if (c > 0) fill(getParticleColor(currentTheme, c)); else fill(15, 20, 32); noStroke(); rect(25 + x * tile, 100 + y * tile, tile - 1, tile - 1); } } fill(255, 230, 60); ellipse(25 + posX * tile, 100 + posY * tile, 7, 7); drawUiBtn(25, 650, 260, 42, "← ZURÜCK ZUM QUANTEN-LABOR", getUiColor(currentTheme, 2)); } void rotateDoomCam(float rot) { float oldDirX = dirX; dirX = dirX * cos(rot) - dirY * sin(rot); dirY = oldDirX * sin(rot) + dirY * cos(rot); float oldPlaneX = planeX; planeX = planeX * cos(rot) - planeY * sin(rot); planeY = oldPlaneX * sin(rot) + planeY * cos(rot); } // ============================================================================================== // MODUL 10: MAUS- & TASTATUR-INTERAKTION // ============================================================================================== void mousePressed() { if (doomMode) { if (mouseX >= 25 && mouseX <= 285 && mouseY >= 650 && mouseY <= 692) { doomMode = false; } return; } // 1. Obere Statusleiste Buttons if (mouseY <= 38) { if (mouseX >= width - 375 && mouseX <= width - 247) { currentTheme = (currentTheme + 1) % 3; return; } if (mouseX >= width - 240 && mouseX <= width - 125) { doomMode = true; return; } if (mouseX >= width - 118 && mouseX <= width - 12) { simPaused = !simPaused; return; } } // 2. Linkes Steuerpult if (mouseX <= LAB_LEFT) { if (mouseX >= 14 && mouseX <= LAB_LEFT - 14) { // Emitter 1..4 if (mouseY >= 62 && mouseY <= 92) { activeEmitter = 1; return; } if (mouseY >= 98 && mouseY <= 128) { activeEmitter = 2; return; } if (mouseY >= 134 && mouseY <= 164) { activeEmitter = 3; return; } if (mouseY >= 170 && mouseY <= 200) { activeEmitter = 4; return; } // Auto-Resonanz Toggle if (mouseY >= 238 && mouseY <= 264) { autoResonance = !autoResonance; return; } // Zielmodus (Schale +1 vs. Ionis./Spalten) & +/- eV if (mouseY >= 270 && mouseY <= 295) { if (mouseX <= 168) { photonTargetMode = (photonTargetMode + 1) % 2; } else if (mouseX <= 230) { autoResonance = false; manualPhotonEv = max(0.5, manualPhotonEv - 0.5); } else { autoResonance = false; manualPhotonEv = min(45.0, manualPhotonEv + 0.5); } return; } // 6 Molekül- & Atom-Presets if (mouseY >= 354 && mouseY <= 380) { loadPresetExperiment(1); return; } if (mouseY >= 384 && mouseY <= 410) { loadPresetExperiment(2); return; } if (mouseY >= 414 && mouseY <= 440) { loadPresetExperiment(3); return; } if (mouseY >= 444 && mouseY <= 470) { loadPresetExperiment(4); return; } if (mouseY >= 474 && mouseY <= 500) { loadPresetExperiment(5); return; } if (mouseY >= 504 && mouseY <= 530) { loadPresetExperiment(6); return; } // Bausteine hinzufügen / Labor leeren if (mouseY >= 558 && mouseY <= 584) { if (mouseX <= 152) { simAtoms.add(new LabAtom(gravCX + random(-90, 90), gravCY + random(-70, 70), 1, 0, 0)); setBanner("Freies Proton (H+) hinzugefügt"); } else { simAtoms.add(new LabAtom(gravCX + random(-90, 90), gravCY + random(-70, 70), 0, 1, 0)); setBanner("Freies Neutron (n) hinzugefügt"); } return; } if (mouseY >= 590 && mouseY <= 616) { if (mouseX <= 152) { simAtoms.add(new LabAtom(gravCX + random(-95, 95), gravCY + random(-75, 75), 1, 0, 1)); setBanner("Wasserstoff-Atom (H-1) hinzugefügt — nähert sich kovalent an!"); } else { simAtoms.clear(); simBosons.clear(); simEffects.clear(); simBonds.clear(); setBanner("Labor geleert — wähle ein Preset oder setze Bausteine!"); } return; } } return; } // 3. Rechtsklick greift Atom zum Ziehen; Linksklick feuert aktiven Bosonen-Emitter if (mouseButton == RIGHT) { for (int i = 0; i < simAtoms.size(); i++) { LabAtom a = (LabAtom) simAtoms.get(i); if (dist(mouseX, mouseY, a.x, a.y) < 55.0) { draggedAtom = a; dragOffX = mouseX - a.x; dragOffY = mouseY - a.y; a.vx = 0.0; a.vy = 0.0; return; } } } else if (mouseButton == LEFT && mouseY > 38) { fireActiveEmitter(); } } void mouseDragged() { if (doomMode && mouseX > DOOM_START_X) { rotateDoomCam(-(mouseX - pmouseX) * rotSpeed * 0.45); } else if (draggedAtom != null) { draggedAtom.x = constrain(mouseX - dragOffX, LAB_LEFT + 55, width - 55); draggedAtom.y = constrain(mouseY - dragOffY, 75, height - 55); } } void mouseReleased() { draggedAtom = null; } void keyPressed() { if (key == ESC) { if (doomMode) doomMode = false; key = 0; return; } if (key == '1') activeEmitter = 1; if (key == '2') activeEmitter = 2; if (key == '3') activeEmitter = 3; if (key == '4') activeEmitter = 4; if (key == 'a' || key == 'A') autoResonance = !autoResonance; if (key == 'h' || key == 'H') currentTheme = (currentTheme + 1) % 3; if (key == ' ') { if (!doomMode) simPaused = !simPaused; } if (key == '+') { autoResonance = false; manualPhotonEv = min(45.0, manualPhotonEv + 0.5); } if (key == '-') { autoResonance = false; manualPhotonEv = max(0.5, manualPhotonEv - 0.5); } if (key == 'w' || key == 'W') keyW = true; if (key == 'a' || key == 'A') keyA = true; if (key == 's' || key == 'S') keyS = true; if (key == 'd' || key == 'D') keyD = true; if (key == 't' || key == 'T') toroidalFieldActive = !toroidalFieldActive; if (key == CODED) { if (keyCode == UP) keyW = true; if (keyCode == DOWN) keyS = true; if (keyCode == LEFT) keyTurnL = true; if (keyCode == RIGHT) keyTurnR = true; } } void keyReleased() { if (key == 'w' || key == 'W') keyW = false; if (key == 'a' || key == 'A') keyA = false; if (key == 's' || key == 'S') keyS = false; if (key == 'd' || key == 'D') keyD = false; if (key == CODED) { if (keyCode == UP) keyW = false; if (keyCode == DOWN) keyS = false; if (keyCode == LEFT) keyTurnL = false; if (keyCode == RIGHT) keyTurnR = false; } }