/* ============================================================================================== DTIM-ZEC TEMPORAL PHYSICS FRAMEWORK (2.5D ATOM SIMULATOR) Theoretical Framework : Discrete Topological Information Matrix (DTIM) Constraint Condition : 3-State Temporal ZIP-Engine (Background Auto-Ring-Buffer) Academic Target : DAMTP (Department of Applied Mathematics & Theoretical Physics) Version : 3.2.1 (Toroidal Field Generator & Bugfixes) Author : Jan Buehring License : MIT License / CC0 1.0 Universal ============================================================================================== */ import java.io.*; import java.util.ArrayList; import java.util.HashMap; import java.util.zip.*; // ============================================================================================== // 1. GLOBALE VARIABLEN (ATOM SMILE EDITOR) // ============================================================================================== ArrayList activeAtoms; ArrayList activeProjectiles; ArrayList activeVisualEffects; Atom currentAssemblyAtom; // DTIM "Allwissendes Gitter" (Hintergrund-Matrix) int[][][][] gridData = new int[105][105][105][16]; float feld = 10.0f; int num = 30; int level = 0; // Z-Achse int ordner = 0; int iv = 1; class Particle { int id; int type; int x, y, z; int[] props = new int[16]; } ArrayList particles = new ArrayList(); int[] typeCounters = new int[9]; // Erweitert für 9 Partikel-Typen // Temporal Engine (Invisible Background Ring Buffer) int slotPast = 0; int slotPresent = 1; int slotFuture = 2; // UI & Message System String flashMsg = ""; int flashMsgTimer = 0; boolean isSimulationPaused = false; boolean isNuclearProcessesActive = true; Atom draggedAtom = null; float dragOffsetX = 0.0f; float dragOffsetY = 0.0f; // Optische 2.5D Konstante & Gravitations-Zentrum float focalLength = 400.0f; float gravCX = 700.0f; float gravCY = 400.0f; PFont mainFont; // Design & Color Themes int currentTheme = 0; color[][] colorThemes = { { color(255, 255, 255), color(255, 50, 50), color(50, 255, 50), color(50, 100, 255), color(255, 255, 50), color(255, 50, 255), color(50, 255, 255), color(255, 0, 200), color(255, 200, 0) }, { color(255, 255, 255), color(230, 159, 0), color(86, 180, 233), color(0, 158, 115), color(240, 228, 66), color(0, 114, 178), color(213, 94, 0), color(255, 0, 200), color(255, 200, 0) }, { color(255, 255, 255), color(200, 0, 0), color(0, 200, 0), color(0, 0, 200), color(255, 200, 0), color(200, 0, 200), color(0, 200, 200), color(255, 0, 200), color(255, 200, 0) } }; String[] particleNames = {"Nix", "Proton", "Neutron", "Elektron", "Photon", "Positron", "Neutrino", "Anker", "T-Gun"}; int currentParticle = 1; // ============================================================================================== // 2. GLOBALE VARIABLEN (DTIM ZEC DOOM RAYCASTER) // ============================================================================================== boolean doomMode = false; boolean toroidalFieldActive = false; // Toroidaler Generator-Status float posX = 1.5, posY = 1.5; float dirX = -1.0, dirY = 0.0; float planeX = 0.0, planeY = 0.66; float moveSpeed = 0.08; float rotSpeed = 0.04; float[] zBuffer = new float[800]; float doomFlash = 0; color doomFlashColor = color(255); // Zuverlässige Tastatur-Abfrage (Web-Safe) boolean keyW = false, keyA = false, keyS = false, keyD = false; class DoomProjectile { float x, y, vx, vy; color c; int type; int life = 100; DoomProjectile(float startX, float startY, float vX, float vY, int pType) { x = startX; y = startY; vx = vX; vy = vY; type = pType; c = colorThemes[currentTheme][type]; } } ArrayList doomProjectiles = new ArrayList(); float[] doomParticleSpeeds = { 0.0, 0.15, 0.15, 0.30, 0.40, 0.10, 0.20, 0.00, 0.00 }; // ============================================================================================== // UTILITY FUNCTIONS // ============================================================================================== void showMessage(String text) { flashMsg = text; flashMsgTimer = 180; } void ensureDir(String path) { try { File f = new File(sketchPath(path)); if (!f.exists()) f.mkdirs(); } catch (Exception e) {} } void setDefaultProps(Particle p) { switch(p.type) { case 1: p.props[4]=938; p.props[5]=1; p.props[6]=1; break; case 2: p.props[4]=939; p.props[5]=0; p.props[6]=1; break; case 3: p.props[4]=1; p.props[5]=-1; p.props[6]=1; break; case 4: p.props[4]=0; p.props[5]=0; p.props[6]=2; break; case 5: p.props[4]=1; p.props[5]=1; p.props[6]=1; break; case 6: p.props[4]=0; p.props[5]=0; p.props[6]=1; break; case 7: p.props[4]=0; p.props[5]=0; p.props[6]=0; break; case 8: p.props[4]=0; p.props[5]=0; p.props[6]=0; break; } } float calcBetheWeizsaecker(int Z, int N) { int A = Z + N; if (A <= 1 || Z <= 0) return 0.0f; float av = 15.8f; float as = 18.3f; float ac = 0.714f; float aa = 23.2f; float ap = 12.0f; float Evol = av * A; float Esurf = as * pow((float)A, 2.0f / 3.0f); float Ecoul = ac * Z * (Z - 1) / pow((float)A, 1.0f / 3.0f); float Esym = aa * pow((float)(A - 2 * Z), 2.0f) / (float)A; float Epair = 0.0f; if (A % 2 != 0) Epair = 0.0f; else if (Z % 2 == 0 && N % 2 == 0) Epair = ap / sqrt((float)A); else Epair = -ap / sqrt((float)A); return max(0.0f, Evol - Esurf - Ecoul - Esym + Epair); } // ============================================================================================== // INITIALIZATION // ============================================================================================== public void setup() { size(1100, 750); noSmooth(); mainFont = createFont("SansSerif", 12); textFont(mainFont); activeAtoms = new ArrayList(); activeProjectiles = new ArrayList(); activeVisualEffects = new ArrayList(); currentAssemblyAtom = new Atom(150.0f, 180.0f, true); ensureDir("sim_temporal/"); saveTemporalState(slotPresent); } // ============================================================================================== // DTIM SPACETIME GRAVITY WELL (Hexagonal Lattice) // ============================================================================================== void drawHexagonalGravityWell() { background(5, 8, 12); strokeWeight(1.5f); float R = 28.0f; for (int q = -9; q <= 9; q++) { for (int r = -9; r <= 9; r++) { if (abs(q + r) <= 10) { float hx = gravCX + R * sqrt(3) * (q + r / 2.0f); float hy = gravCY + R * 3.0f / 2.0f * r; beginShape(); for(int i = 0; i < 6; i++) { float angle = radians(60 * i + 30); float vx = hx + R * cos(angle); float vy = hy + R * sin(angle); float d = dist(vx, vy, gravCX, gravCY); float vz = 450.0f * exp(-(d * d) / 35000.0f); float scale = focalLength / (focalLength + vz); float projX = gravCX + (vx - gravCX) * scale; float projY = gravCY + (vy - gravCY) * scale; int colVal = (int)map(vz, 0, 450, 20, 220); stroke(0, 100 + colVal/2, 255, 60 + colVal/2); fill(0, 10, 20 + colVal/3, 80); vertex(projX, projY); } endShape(CLOSE); } } } } // ============================================================================================== // MAIN EXECUTION LOOP (MULTIPLEXER) // ============================================================================================== public void draw() { if (doomMode) { drawDoomMode(); return; } drawHexagonalGravityWell(); drawAssemblyWorkbench(); if (!isSimulationPaused) { checkFusionCollisions(); applyDTIMAdjacencyShortcuts(); if (isNuclearProcessesActive) processStochasticNuclearDecay(); if (frameCount % 120 == 0) shiftTimeForwardBackground(); } updateAndDrawVisualEffects(); updateAndDrawProjectiles(); for (int i = activeAtoms.size() - 1; i >= 0; i--) { Atom a = activeAtoms.get(i); if (!isSimulationPaused) { a.updateGravitationalPhysics(); a.updateQuantumJumps(); a.checkDecay(); } a.display(); if (a.isDestroyed) activeAtoms.remove(i); } currentAssemblyAtom.display(); displayGlobalHUD(); drawPeriodicTablePanel(); if (draggedAtom != null) { float scale = focalLength / (focalLength + draggedAtom.z); float pX = gravCX + (draggedAtom.x - gravCX) * scale; float pY = gravCY + (draggedAtom.y - gravCY) * scale; stroke(0, 255, 200, 180); strokeWeight(1.5f); noFill(); ellipse(pX, pY, 90 * scale, 90 * scale); fill(0, 255, 200); textSize(10); textAlign(CENTER, BOTTOM); text("DRAG & DROP", pX, pY - (45 * scale)); } } // ============================================================================================== // UPDATE SYSTEM LOOPS // ============================================================================================== void updateAndDrawVisualEffects() { for (int i = activeVisualEffects.size() - 1; i >= 0; i--) { VisualEffect fx = activeVisualEffects.get(i); if (!isSimulationPaused) fx.update(); fx.display(); if (fx.isDead) activeVisualEffects.remove(i); } } void updateAndDrawProjectiles() { for (int i = activeProjectiles.size() - 1; i >= 0; i--) { Projectile proj = activeProjectiles.get(i); if (!isSimulationPaused) proj.update(); proj.display(); if (proj.isDead) activeProjectiles.remove(i); } } void processStochasticNuclearDecay() { for (int i = 0; i < activeAtoms.size(); i++) { Atom a = activeAtoms.get(i); if (a.isDestroyed || a.isWorkbench) continue; if (a.protons == 1 && a.neutrons >= 2) { if (random(1.0f) < 0.002f) { for (int k = 0; k < a.nodes.size(); k++) { GraphNode n = a.nodes.get(k); if (n.type == 2) { n.type = 1; n.energy = 938.27f; a.neutrons--; a.protons++; a.addParticle(3, 0); activeVisualEffects.add(new VisualEffect(a.x, a.y, 1)); break; } } a.calculateBindingEnergy(); a.checkStability(); } } } } void applyDTIMAdjacencyShortcuts() { for (int i = activeProjectiles.size() - 1; i >= 0; i--) { Projectile proj = activeProjectiles.get(i); if (proj.typeIndex == 1 && !proj.isDead) { for (Atom target : activeAtoms) { if (!target.isDestroyed && target.protons > target.electrons) { activeVisualEffects.add(new VisualEffect(proj.x, proj.y, 1)); proj.isDead = true; target.addParticle(3, 0); activeVisualEffects.add(new VisualEffect(target.x, target.y, 3)); break; } } } } } // ============================================================================================== // ATOM & NODE CLASSES // ============================================================================================== class Atom { float x, y, z, vx, vy; boolean isWorkbench, isDestroyed = false, hasFusionPermit = false; ArrayList nodes; int protons, neutrons, electrons; float bindingEnergy = 0.0f; int decayTimer = 0; boolean isUnstable = false; Atom(float x, float y, boolean isWorkbench) { this.x = x; this.y = y; this.z = 0; this.isWorkbench = isWorkbench; nodes = new ArrayList(); protons = 0; neutrons = 0; electrons = 0; } void addParticle(int type, int mode) { float posE = (type == 3) ? 0.511f : 938.27f; float rx = random(-18, 18), ry = random(-18, 18), rz = random(-18, 18); if (type == 3) { float angle = random(TWO_PI); rx = cos(angle) * 60.0f; ry = sin(angle) * 60.0f; rz = random(-40, 40); } GraphNode node = new GraphNode(rx, ry, rz, type, posE); nodes.add(node); if (type == 1) protons++; if (type == 2) neutrons++; if (type == 3) electrons++; calculateBindingEnergy(); checkStability(); } void mergeWith(Atom other) { for (GraphNode n : other.nodes) { n.relX += (other.x - x); n.relY += (other.y - y); n.relZ += (other.z - z); nodes.add(n); } protons += other.protons; neutrons += other.neutrons; electrons += other.electrons; vx = (vx + other.vx) * 0.5f; vy = (vy + other.vy) * 0.5f; calculateBindingEnergy(); checkStability(); } void updateQuantumJumps() { float nucX = 0, nucY = 0, nucZ = 0; int count = 0; for (GraphNode n : nodes) { if (n.type == 1 || n.type == 2) { nucX+=n.relX; nucY+=n.relY; nucZ+=n.relZ; count++; } } if(count > 0) { nucX/=count; nucY/=count; nucZ/=count; } for (GraphNode n : nodes) { if (n.type == 1 || n.type == 2) { n.relZ += sin(frameCount * 0.1f + n.type) * 0.5f; n.relX = lerp(n.relX, n.relX - nucX, 0.15f) + random(-0.2f, 0.2f); n.relY = lerp(n.relY, n.relY - nucY, 0.15f) + random(-0.2f, 0.2f); } else if (n.type == 3) { float r = 50.0f; float angle = frameCount * 0.05f + n.type * 10; n.relX = nucX + cos(angle) * r; n.relZ = nucZ + sin(angle) * r; } } } void calculateBindingEnergy() { bindingEnergy = -calcBetheWeizsaecker(protons, neutrons); } void checkStability() { if (protons > 0) { float ratio = (float)neutrons / (float)protons; isUnstable = (protons >= 2 && ratio < 0.5f) || ratio > 2.3f || protons > 10; } else { isUnstable = neutrons > 0; } } void checkDecay() { if (isUnstable && !isWorkbench && isNuclearProcessesActive) { decayTimer++; if (decayTimer > 150) { isDestroyed = true; if (protons == 0 && neutrons > 0) { Atom pAtom = new Atom(x, y, false); pAtom.addParticle(1, 0); activeAtoms.add(pAtom); activeProjectiles.add(new Projectile(x, y, random(TWO_PI), 5.0f, 1)); } else { for(int k = 0; k < 3; k++) activeProjectiles.add(new Projectile(x, y, random(TWO_PI), 4.0f, 0)); } } } } void updateGravitationalPhysics() { if (!isWorkbench && draggedAtom != this) { float dx = gravCX - x; float dy = gravCY - y; float d = sqrt(dx * dx + dy * dy); if (d > 15.0f) { float force = 150.0f / (d * d); vx += (dx / d) * force; vy += (dy / d) * force; } vx *= 0.998f; vy *= 0.998f; x += vx; y += vy; this.z = 450.0f * exp(-(d * d) / 35000.0f); } } void display() { pushMatrix(); float pX = x; float pY = y; float atomScale = 1.0f; if (!isWorkbench) { atomScale = focalLength / (focalLength + z); pX = gravCX + (x - gravCX) * atomScale; pY = gravCY + (y - gravCY) * atomScale; } translate(pX, pY); scale(atomScale); if (hasFusionPermit) { stroke(255, 200, 0, 80); strokeWeight(1.5f); noFill(); ellipse(0, 0, 80, 80); } noFill(); strokeWeight(1); if (electrons > 0) { stroke(0, 180, 255, 60); ellipse(0, 0, 120, 120); } for (GraphNode n : nodes) if (n.type == 3 && n.relZ < 0) n.display(); for (GraphNode n : nodes) if (n.type == 1 || n.type == 2) n.display(); for (GraphNode n : nodes) if (n.type == 3 && n.relZ >= 0) n.display(); fill(255, 200); textAlign(CENTER); textSize(11); text("Z=" + protons + " N=" + neutrons, 0, 75); popMatrix(); } } class GraphNode { float relX, relY, relZ; int type; float energy; GraphNode(float rx, float ry, float rz, int t, float e) { relX = rx; relY = ry; relZ = rz; type = t; energy = e; } void display() { pushMatrix(); translate(relX, relY); float nodeScale = focalLength / (focalLength + relZ); scale(nodeScale); if (type == 1 || type == 2) { if (type == 1) fill(220, 50, 50, 180); else fill(140, 150, 160, 180); stroke(255, 100); strokeWeight(1); ellipse(0, 0, 36, 36); noStroke(); fill(255, 200, 0); ellipse(-8, -8, 7, 7); ellipse(8, -8, 7, 7); if (type == 1) fill(255, 200, 0); else fill(0, 220, 255); ellipse(0, 8, 7, 7); } else if (type == 3) { fill(40, 140, 255); noStroke(); ellipse(0, 0, 12, 12); stroke(0, 180, 255, 150); noFill(); ellipse(0, 0, 18, 18); } popMatrix(); } } class Projectile { float x, y, z, vx, vy; int typeIndex, life = 220; boolean isDead = false; Projectile(float x, float y, float angle, float speed, int type) { this.x = x; this.y = y; this.z = 0; this.vx = cos(angle)*speed; this.vy = sin(angle)*speed; this.typeIndex = type; } void update() { x += vx; y += vy; life--; if(life<=0) isDead=true; float d = dist(x, y, gravCX, gravCY); this.z = 450.0f * exp(-(d * d) / 35000.0f); } void display() { pushMatrix(); float pScale = focalLength / (focalLength + z); float pX = gravCX + (x - gravCX) * pScale; float pY = gravCY + (y - gravCY) * pScale; translate(pX, pY); scale(pScale); fill(255, 255, 0, life); noStroke(); ellipse(0,0,10,10); popMatrix(); } } class VisualEffect { float x, y, z; int type; float radius = 5.0f, maxRadius = 40.0f; int life = 255; boolean isDead = false; VisualEffect(float x, float y, int type) { this.x = x; this.y = y; this.type = type; float d = dist(x, y, gravCX, gravCY); this.z = 450.0f * exp(-(d * d) / 35000.0f); } void update() { radius += 2.5f; life -= 12; if (life <= 0) isDead = true; } void display() { pushMatrix(); float pScale = focalLength / (focalLength + z); float pX = gravCX + (x - gravCX) * pScale; float pY = gravCY + (y - gravCY) * pScale; translate(pX, pY); scale(pScale); noFill(); stroke(0, 255, 255, life); strokeWeight(2.5f); ellipse(0, 0, radius * 2, radius * 2); popMatrix(); } } void checkFusionCollisions() { for (int i = 0; i < activeAtoms.size(); i++) { Atom a1 = activeAtoms.get(i); if (a1.isDestroyed) continue; for (int j = i + 1; j < activeAtoms.size(); j++) { Atom a2 = activeAtoms.get(j); if (a2.isDestroyed) continue; float d = dist(a1.x, a1.y, a2.x, a2.y); if (d < 45.0f && (a1.hasFusionPermit || a2.hasFusionPermit)) { a1.mergeWith(a2); a2.isDestroyed = true; break; } else if (d < 70.0f) { float overlap = 70.0f - d; float ax = (a1.x - a2.x) / d; float ay = (a1.y - a2.y) / d; a1.x += ax * overlap * 0.1f; a1.y += ay * overlap * 0.1f; a2.x -= ax * overlap * 0.1f; a2.y -= ay * overlap * 0.1f; } } } } // ============================================================================================== // BACKGROUND TEMPORAL ENGINE // ============================================================================================== void saveTemporalState(int timeSlot) { String zipFileName = sketchPath("sim_temporal/frame_000" + timeSlot + ".zip"); try { ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFileName)); zos.putNextEntry(new ZipEntry("state.txt")); PrintWriter out = new PrintWriter(new OutputStreamWriter(zos, "UTF-8")); out.println(activeAtoms.size()); for(Atom a : activeAtoms) out.println(a.x + " " + a.y + " " + a.z + " " + a.vx + " " + a.vy + " " + a.protons + " " + a.neutrons + " " + a.electrons + " " + (a.hasFusionPermit?1:0)); out.println("eof"); out.flush(); zos.closeEntry(); zos.close(); } catch (Exception e) {} } void shiftTimeForwardBackground() { int temp = slotPast; slotPast = slotPresent; slotPresent = slotFuture; slotFuture = temp; saveTemporalState(slotPresent); } // ============================================================================================== // UI & PANELS (ATOM SIMULATOR) // ============================================================================================== void displayGlobalHUD() { if (isSimulationPaused) fill(220, 120, 40); else fill(40, 60, 80); rect(width - 140, 20, 120, 40, 8); fill(255); textAlign(CENTER, CENTER); text(isSimulationPaused ? "PLAY" : "PAUSE", width - 80, 40); fill(color(0, 255, 200)); stroke(150); rect(width - 270, 20, 120, 40, 8); fill(0, 100, 50); text("DOOM 3D", width - 210, 40); if (flashMsgTimer > 0) { fill(0, 200); stroke(255); rect(350, 350, 500, 50, 10); fill(255); textSize(14); text(flashMsg, 600, 375); flashMsgTimer--; } } void drawAssemblyWorkbench() { fill(18, 22, 32); stroke(40, 50, 70); rect(0, 0, 300, height); fill(12, 15, 22); stroke(0, 180, 255, 100); rect(15, 40, 270, 290, 12); fill(0, 180, 255); textSize(13); textAlign(CENTER, CENTER); text("KONSTRUKTIONS-BOX", 150, 25); textAlign(LEFT, CENTER); fill(200, 50, 50); rect(20, 440, 260, 32, 6); fill(255); text("+ Proton (2u, 1d)", 35, 456); fill(120, 130, 140); rect(20, 480, 260, 32, 6); fill(255); text("+ Neutron (1u, 2d)", 35, 496); fill(40, 120, 220); rect(20, 520, 260, 32, 6); fill(255); text("+ Elektron / Huelle", 35, 536); fill(200, 150, 0); rect(20, 560, 260, 32, 6); fill(255); text("+ Alpha (2p, 2n) [QUICK-BUILD]", 35, 576); fill(200); textSize(12); text("FUSION ERLAUBT:", 20, 617); if (currentAssemblyAtom.hasFusionPermit) { fill(0, 200, 100); rect(140, 605, 40, 24, 4); fill(50); rect(190, 605, 40, 24, 4); } else { fill(50); rect(140, 605, 40, 24, 4); fill(200, 50, 50); rect(190, 605, 40, 24, 4); } fill(255); textAlign(CENTER, CENTER); text("1", 160, 617); text("0", 210, 617); textAlign(LEFT, CENTER); fill(0, 200, 120); rect(20, 650, 260, 40, 8); fill(10, 20, 15); textAlign(CENTER, CENTER); text("FREISETZEN ->", 150, 670); fill(180, 40, 40); rect(20, 700, 260, 32, 6); fill(255); text("RESET SIMULATION", 150, 716); } void drawPeriodicTablePanel() { fill(15, 20, 30, 230); stroke(40, 60, 90); rect(305, height - 125, 420, 115, 8); fill(0, 200, 255); textSize(11); textAlign(LEFT, TOP); text("PERIODENSYSTEM & Z-TIEFE", 315, height - 120); int p = currentAssemblyAtom.protons; int n = currentAssemblyAtom.neutrons; if (draggedAtom != null) { p = draggedAtom.protons; n = draggedAtom.neutrons; } else if (activeAtoms.size() > 0) { p = activeAtoms.get(0).protons; n = activeAtoms.get(0).neutrons; } fill(255); textSize(10); text("Z = " + p + " | N = " + n, 320, height - 95); fill(0, 255, 180); text("Bethe-Weizsäcker Bindungsenergie:", 320, height - 60); text(nf(calcBetheWeizsaecker(p, n), 1, 2) + " MeV", 320, height - 45); } // ============================================================================================== // DTIM-ZEC DOOM RAYCASTER (Modus 2) - TOROIDALES FELD // ============================================================================================== void enterDoomMode() { doomMode = true; posX = num / 2.0f; posY = num / 2.0f; keyW = false; keyA = false; keyS = false; keyD = false; toroidalFieldActive = false; // Reset Torus-Feld } void exitDoomMode() { doomMode = false; keyW = false; keyA = false; keyS = false; keyD = false; toroidalFieldActive = false; background(255); } int getDoomMapCell(int x, int y) { if (x <= 0 || x >= num || y <= 0 || y >= num) return -1; return gridData[x][y][level][3]; } void drawDoomMode() { background(0); handleDoomKinematics(); updateDoomProjectiles(); renderRaycast3D(); renderDoomProjectiles3D(); renderDoomHUD2D(); if (doomFlash > 0) { fill(red(doomFlashColor), green(doomFlashColor), blue(doomFlashColor), doomFlash); rect(400, 0, 800, height); doomFlash -= 15; } } void handleDoomKinematics() { // DTIM-ZEC MAGIC: Das toroidale Feld entkoppelt den Raum (Trägheitslosigkeit) float spd = toroidalFieldActive ? moveSpeed * 4.0f : moveSpeed; if (keyW) { if (toroidalFieldActive || getDoomMapCell((int)(posX + dirX * spd), (int)posY) == 0) posX += dirX * spd; if (toroidalFieldActive || getDoomMapCell((int)posX, (int)(posY + dirY * spd)) == 0) posY += dirY * spd; } if (keyS) { if (toroidalFieldActive || getDoomMapCell((int)(posX - dirX * spd), (int)posY) == 0) posX -= dirX * spd; if (toroidalFieldActive || getDoomMapCell((int)posX, (int)(posY - dirY * spd)) == 0) posY -= dirY * spd; } if (keyA) { float sX = dirY; float sY = -dirX; if (toroidalFieldActive || getDoomMapCell((int)(posX + sX * spd), (int)posY) == 0) posX += sX * spd; if (toroidalFieldActive || getDoomMapCell((int)posX, (int)(posY + sY * spd)) == 0) posY += sY * spd; } if (keyD) { float sX = -dirY; float sY = dirX; if (toroidalFieldActive || getDoomMapCell((int)(posX + sX * spd), (int)posY) == 0) posX += sX * spd; if (toroidalFieldActive || getDoomMapCell((int)posX, (int)(posY + sY * spd)) == 0) posY += sY * spd; } // Wrap-Around (Phasing) im Toroidal-Modus, um nicht das Array zu verlassen if (posX < 1.0f) posX += num - 2.0f; if (posX >= num - 1.0f) posX -= num - 2.0f; if (posY < 1.0f) posY += num - 2.0f; if (posY >= num - 1.0f) posY -= num - 2.0f; } void renderRaycast3D() { int viewW = 800; int viewH = height; int startX = 400; // Toroidale Hintergrund-Illusion (Dehnung des Voids) if (toroidalFieldActive) { fill(0, 30, 40); rect(startX, 0, viewW, viewH / 2); fill(0, 10, 20); rect(startX, viewH / 2, viewW, viewH / 2); } else { fill(10, 15, 25); rect(startX, 0, viewW, viewH / 2); fill(20, 30, 40); rect(startX, viewH / 2, viewW, viewH / 2); } for (int x = 0; x < viewW; x++) { float cameraX = 2 * x / float(viewW) - 1; float rayDirX = dirX + planeX * cameraX; float rayDirY = dirY + planeY * cameraX; int mapX = (int)posX; int mapY = (int)posY; float deltaDistX = (rayDirX == 0) ? 9999999.0f : abs(1.0f / rayDirX); float deltaDistY = (rayDirY == 0) ? 9999999.0f : abs(1.0f / rayDirY); float perpWallDist; int stepX, stepY; float sideDistX, sideDistY; if (rayDirX < 0) { stepX = -1; sideDistX = (posX - mapX) * deltaDistX; } else { stepX = 1; sideDistX = (mapX + 1.0f - posX) * deltaDistX; } if (rayDirY < 0) { stepY = -1; sideDistY = (posY - mapY) * deltaDistY; } else { stepY = 1; sideDistY = (mapY + 1.0f - posY) * deltaDistY; } int hit = 0; int side = 0; int hitType = 0; while (hit == 0 && mapX > 0 && mapX < num && mapY > 0 && mapY < num) { if (sideDistX < sideDistY) { sideDistX += deltaDistX; mapX += stepX; side = 0; } else { sideDistY += deltaDistY; mapY += stepY; side = 1; } hitType = getDoomMapCell(mapX, mapY); if (hitType != 0) hit = 1; } if (side == 0) perpWallDist = (mapX - posX + (1 - stepX) / 2.0f) / rayDirX; else perpWallDist = (mapY - posY + (1 - stepY) / 2.0f) / rayDirY; zBuffer[x] = perpWallDist; int lineHeight = (int)(viewH / perpWallDist); int drawStart = max(0, -lineHeight / 2 + viewH / 2); int drawEnd = min(viewH - 1, lineHeight / 2 + viewH / 2); color wallColor = (hitType == -1) ? color(100) : colorThemes[currentTheme][hitType]; if (side == 1) wallColor = color(red(wallColor)*0.7f, green(wallColor)*0.7f, blue(wallColor)*0.7f); // Toroidales Feld: Transparente Wände! if (toroidalFieldActive) { wallColor = color(red(wallColor)*0.3f, green(wallColor)*0.8f, 255, 120); stroke(wallColor); line(startX + x, drawStart, startX + x, drawEnd); if (x % 10 == 0 || drawStart % 10 == 0) { stroke(0, 255, 255, 200); line(startX + x, drawStart, startX + x, drawEnd); } } else { stroke(wallColor); line(startX + x, drawStart, startX + x, drawEnd); if (x % 20 == 0 || drawStart % 20 == 0) { stroke(255, 50); line(startX + x, drawStart, startX + x, drawEnd); } } } } void fireDoomParticle() { if (currentParticle == 0) return; if (currentParticle == 7 || currentParticle == 8) { float rayDirX = dirX; float rayDirY = dirY; int mapX = (int)posX; int mapY = (int)posY; float deltaDistX = (rayDirX == 0) ? 9999999.0f : abs(1.0f / rayDirX); float deltaDistY = (rayDirY == 0) ? 9999999.0f : abs(1.0f / rayDirY); int stepX, stepY; float sideDistX, sideDistY; if (rayDirX < 0) { stepX = -1; sideDistX = (posX - mapX) * deltaDistX; } else { stepX = 1; sideDistX = (mapX + 1.0f - posX) * deltaDistX; } if (rayDirY < 0) { stepY = -1; sideDistY = (posY - mapY) * deltaDistY; } else { stepY = 1; sideDistY = (mapY + 1.0f - posY) * deltaDistY; } int hit = 0; int hitType = 0; int side = 0; while (hit == 0 && mapX > 0 && mapX < num && mapY > 0 && mapY < num) { if (sideDistX < sideDistY) { sideDistX += deltaDistX; mapX += stepX; side = 0; } else { sideDistY += deltaDistY; mapY += stepY; side = 1; } hitType = getDoomMapCell(mapX, mapY); if (hitType != 0) hit = 1; } if (currentParticle == 7) { int buildX = mapX; int buildY = mapY; if (side == 0) buildX -= stepX; else buildY -= stepY; if (buildX >= 0 && buildX <= num && buildY >= 0 && buildY <= num) { if (!(buildX == (int)posX && buildY == (int)posY)) gridData[buildX][buildY][level][3] = 7; } doomFlash = 100; doomFlashColor = colorThemes[currentTheme][7]; } else if (currentParticle == 8) { if (hitType == 7) { int targetX = mapX; int targetY = mapY; if (side == 0) targetX -= stepX; else targetY -= stepY; if (getDoomMapCell(targetX, targetY) == 0) { posX = targetX + 0.5f; posY = targetY + 0.5f; doomFlash = 200; doomFlashColor = colorThemes[currentTheme][8]; } } } return; } float spd = doomParticleSpeeds[currentParticle]; doomProjectiles.add(new DoomProjectile(posX, posY, dirX * spd, dirY * spd, currentParticle)); } void updateDoomProjectiles() { for (int i = doomProjectiles.size() - 1; i >= 0; i--) { DoomProjectile q = doomProjectiles.get(i); float nextX = q.x + q.vx; float nextY = q.y + q.vy; if (nextX < 0) nextX += (num + 1); else if (nextX >= num + 1) nextX -= (num + 1); if (nextY < 0) nextY += (num + 1); else if (nextY >= num + 1) nextY -= (num + 1); int nextCx = (int)nextX; int nextCy = (int)nextY; int hitType = getDoomMapCell(nextCx, nextCy); if (q.life <= 0 || hitType != 0) { if (hitType > 0) { int currCx = (int)q.x; int currCy = (int)q.y; if (currCx >= 0 && currCx <= num && currCy >= 0 && currCy <= num) { if (!(currCx == (int)posX && currCy == (int)posY)) gridData[currCx][currCy][level][3] = q.type; } } doomProjectiles.remove(i); } else { q.x = nextX; q.y = nextY; q.life--; } } } void renderDoomProjectiles3D() { int viewW = 800; int viewH = height; int startX = 400; for (DoomProjectile q : doomProjectiles) { float spriteX = q.x - posX; float spriteY = q.y - posY; float invDet = 1.0f / (planeX * dirY - dirX * planeY); float transformX = invDet * (dirY * spriteX - dirX * spriteY); float transformY = invDet * (-planeY * spriteX + planeX * spriteY); if (transformY <= 0) continue; int spriteScreenX = (int)((viewW / 2) * (1 + transformX / transformY)); int spriteSize = abs((int)(viewH / transformY)) / 2; int drawStartY = max(0, -spriteSize / 2 + viewH / 2); int drawEndY = min(viewH - 1, spriteSize / 2 + viewH / 2); int drawStartX = max(0, -spriteSize / 2 + spriteScreenX); int drawEndX = min(viewW - 1, spriteSize / 2 + spriteScreenX); for (int stripe = drawStartX; stripe < drawEndX; stripe++) { if (transformY < zBuffer[stripe]) { float nx = map(stripe, drawStartX, drawEndX, -1, 1); for (int y = drawStartY; y < drawEndY; y++) { float ny = map(y, drawStartY, drawEndY, -1, 1); if (nx*nx + ny*ny < 1.0f) { stroke(q.c); point(startX + stripe, y); } } } } } } void renderDoomHUD2D() { fill(5, 10, 15); noStroke(); rect(0, 0, 400, height); stroke(0, 150, 255); strokeWeight(2); line(400, 0, 400, height); fill(0, 255, 255); textSize(18); textAlign(LEFT, TOP); text("DTIM-ZEC QUANTUM TERMINAL", 20, 20); fill(100, 150, 200); textSize(12); text("Subsystem Self-Observation Framework", 20, 45); fill(255, 255, 0); text("Z-EBENE: " + level + " (Wechseln mit Q / E)", 20, 60); stroke(0, 100, 150); line(20, 75, 380, 75); float mapX = 20, mapY = 90, mapW = 360, mapH = 360; fill(0, 5, 10); stroke(0, 100, 150); rect(mapX, mapY, mapW, mapH); float tileSize = min(mapW / (num+1), mapH / (num+1)); pushMatrix(); translate(mapX, mapY); noStroke(); for (int x = 0; x <= num; x++) { for (int y = 0; y <= num; y++) { int pType = getDoomMapCell(x, y); if (pType > 0) { fill(colorThemes[currentTheme][pType]); rect(x * tileSize, y * tileSize, tileSize - 1, tileSize - 1); } else if (pType == -1) { fill(100); rect(x * tileSize, y * tileSize, tileSize - 1, tileSize - 1); } } } for (DoomProjectile q : doomProjectiles) { fill(q.c); ellipse(q.x * tileSize, q.y * tileSize, tileSize/2, tileSize/2); } // Toroidales Feld Minimap HUD if (toroidalFieldActive) { noFill(); stroke(0, 255, 255, 150 + sin(frameCount * 0.2f) * 100); strokeWeight(3); ellipse(posX * tileSize, posY * tileSize, tileSize * 4, tileSize * 4); } fill(255, 255, 0); noStroke(); ellipse(posX * tileSize, posY * tileSize, tileSize/1.5f, tileSize/1.5f); stroke(255, 0, 0); line(posX * tileSize, posY * tileSize, (posX + dirX) * tileSize, (posY + dirY) * tileSize); popMatrix(); // Toroidal Status Panel if (toroidalFieldActive) { fill(0, 50, 80); stroke(0, 255, 255); rect(20, 460, 360, 45, 6); fill(0, 255, 255); textSize(12); textAlign(CENTER, CENTER); text("TOROIDALES FELD: AKTIV\n(Trägheitslosigkeit & Phasen-Entkopplung)", 200, 482); } else { fill(20, 30, 40); stroke(100); rect(20, 460, 360, 45, 6); fill(150); textSize(12); textAlign(CENTER, CENTER); text("DRÜCKE [T] FÜR TOROIDALES FELD", 200, 482); } textAlign(LEFT, TOP); fill(0, 255, 255); textSize(13); text("EMITTER ARSENAL (Tasten 1-8)", 20, 515); for (int i = 1; i < 9; i++) { float yPos = 535 + ((i-1) * 26); if (i == currentParticle) { fill(50, 100, 150); noStroke(); rect(20, yPos - 4, 360, 24, 4); } fill(colorThemes[currentTheme][i]); stroke(255); rect(25, yPos, 16, 16); fill(i == currentParticle ? color(255) : color(150, 150, 200)); textSize(12); text("[" + i + "] " + particleNames[i % 8], 55, yPos + 1); } fill(200, 50, 50); stroke(255); rect(20, 780, 360, 40, 5); fill(255); textSize(16); textAlign(LEFT, CENTER); text("ZURÜCK ZUM EDITOR (Oder ESC drücken)", 50, 800); textAlign(LEFT, TOP); stroke(0, 255, 0); strokeWeight(2); int cx = 400 + 800/2; int cy = height/2; line(cx - 10, cy, cx + 10, cy); line(cx, cy - 10, cx, cy + 10); noFill(); ellipse(cx, cy, 30, 30); strokeWeight(1); } // ============================================================================================== // GEMEINSAME EINGABE-EVENTS // ============================================================================================== void keyPressed() { if (key == 27 || keyCode == 27) { if (doomMode) exitDoomMode(); key = 0; return; } 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 (doomMode) { if (key >= '1' && key <= '8') currentParticle = key - '0'; if (key == 'e' || key == 'E') level = min(num, level + 1); if (key == 'q' || key == 'Q') level = max(0, level - 1); if (key == 't' || key == 'T') toroidalFieldActive = !toroidalFieldActive; } } 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; } void mousePressed() { if (doomMode) { if (mouseX >= 10 && mouseX <= 390 && mouseY >= 770 && mouseY <= 830) { exitDoomMode(); return; } if (mouseX > 400 && mouseButton == LEFT) fireDoomParticle(); } else { // DOOM BUTTON CLICK: Pausiere die Simulation, starte Raycaster! if (mouseX > width - 270 && mouseX < width - 150 && mouseY > 20 && mouseY < 60) { isSimulationPaused = true; enterDoomMode(); return; } // PLAY/PAUSE BUTTON CLICK: if (mouseX > width - 140 && mouseX < width - 20 && mouseY > 20 && mouseY < 60) { isSimulationPaused = !isSimulationPaused; if (!isSimulationPaused) draggedAtom = null; return; } if (mouseX > 300 && mouseY < height - 130) { for (Atom a : activeAtoms) { if (!a.isDestroyed) { float scale = focalLength / (focalLength + a.z); float pX = gravCX + (a.x - gravCX) * scale; float pY = gravCY + (a.y - gravCY) * scale; if (dist(mouseX, mouseY, pX, pY) < 60.0f * scale) { draggedAtom = a; dragOffsetX = mouseX - pX; dragOffsetY = mouseY - pY; a.vx = 0; a.vy = 0; return; } } } } if (mouseX > 15 && mouseX < 285) { if (mouseY > 440 && mouseY < 472) currentAssemblyAtom.addParticle(1, 0); if (mouseY > 480 && mouseY < 512) currentAssemblyAtom.addParticle(2, 0); if (mouseY > 520 && mouseY < 552) currentAssemblyAtom.addParticle(3, 1); if (mouseY > 560 && mouseY < 592) { currentAssemblyAtom.addParticle(1, 0); currentAssemblyAtom.addParticle(1, 0); currentAssemblyAtom.addParticle(2, 0); currentAssemblyAtom.addParticle(2, 0); } if (mouseY > 605 && mouseY < 629) { if (mouseX > 140 && mouseX < 180) currentAssemblyAtom.hasFusionPermit = true; if (mouseX > 190 && mouseX < 230) currentAssemblyAtom.hasFusionPermit = false; } if (mouseY > 650 && mouseY < 690) { if (currentAssemblyAtom.nodes.size() > 0) { currentAssemblyAtom.isWorkbench = false; float angle = random(TWO_PI); float spawnDist = 300.0f; currentAssemblyAtom.x = gravCX + cos(angle) * spawnDist; currentAssemblyAtom.y = gravCY + sin(angle) * spawnDist; float orbAngle = angle + HALF_PI; currentAssemblyAtom.vx = cos(orbAngle) * 3.5f; currentAssemblyAtom.vy = sin(orbAngle) * 3.5f; activeAtoms.add(currentAssemblyAtom); currentAssemblyAtom = new Atom(150.0f, 180.0f, true); saveTemporalState(slotPresent); } } if (mouseY > 700 && mouseY < 732) { activeAtoms.clear(); currentAssemblyAtom = new Atom(150.0f, 180.0f, true); } } } } void mouseDragged() { if (doomMode && mouseX > 400) { float deltaX = mouseX - pmouseX; float rot = -deltaX * rotSpeed * 0.5f; 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); } else if (draggedAtom != null && !doomMode) { float scale = focalLength / (focalLength + draggedAtom.z); draggedAtom.x = gravCX + ((mouseX - dragOffsetX) - gravCX) / scale; draggedAtom.y = gravCY + ((mouseY - dragOffsetY) - gravCY) / scale; } } public void mouseWheel(MouseEvent event) { if (draggedAtom != null) { float e = event.getCount(); draggedAtom.z += e * 15.0f; draggedAtom.z = constrain(draggedAtom.z, -200.0f, 600.0f); } } public void mouseReleased() { if (draggedAtom != null) { saveTemporalState(slotPresent); draggedAtom = null; } }