/* ============================================================================================== VEXO CLIENT 1 - CLEAN CORE ENGINE (SOLID 3D & SHADED EDITION) Mit soliden 3D-Würfeln (gleiche Kantenlänge), Beleuchtung/Schattierung, Play-Schleife & Block-Save ============================================================================================== */ import processing.net.*; import javax.swing.JOptionPane; import java.net.HttpURLConnection; import java.net.URL; import java.io.File; // Passiver Netzwerk-Socket-Header Client myClient01, myClient0r, myClient0g, myClient0b, myClient0x, myClient0y; Server myServer01, myServer0r, myServer0g, myServer0b, myServer0x, myServer0y; // Globale Variablen für Vexo-Daten float feld = 10.0f; int num = 30; int num1 = 30; int level = 0; int ordner = 0; int iv = 1; int lastSavedFrame = 1; // 3D Voxel-Datenstruktur für alle Frames/Schichten (Cache im Speicher) int[][][] frameData = new int[105][105][105]; // Farbwerte int rc = 0, gc = 0, bc = 0; int sc = 0; int rcb = 0, gcb = 0, bcb = 0, scb = 0; // Slider Klick-Historie (Trail mit 4 Stufen / Verblassung) int[] trailR = {-1, -1, -1, -1}; int[] trailG = {-1, -1, -1, -1}; int[] trailB = {-1, -1, -1, -1}; int[] trailBW = {-1, -1, -1, -1}; // Farb-Historie (Palette) int maxHistory = 8; color[] colorHistory = new color[maxHistory]; int historyCount = 0; // Zustand & Flags int app = 1; int dom = 1; int los = 0; int start = 0; int dot = 0, dot1 = 0; // Ansichts- & Animations-Optionen boolean show3DView = true; boolean showHelperGrid = true; boolean isPlaying = false; int playTimer = 0; // Online-Modus Variablen boolean onlineActive = false; boolean remoteFrameAvailable = false; String serverBaseUrl = ""; // Visuelles Feedback (Speicher-Blitz) int saveFlashTimer = 0; // Dateischreiber / Leser PrintWriter outputr, outputg, outputb, outputbw; String[] linesr, linesg, linesb, linesbw; // Passive 3D Cursor Variablen int giv = 150; void setup() { size(1200, 850); background(255); for(int i = 0; i < maxHistory; i++) { colorHistory[i] = color(0, 0, 0); } clearMemoryGrid(); ensureDir("work0/"); ensureDir("work/"); drawBlankGrid(); } void ensureDir(String path) { File f = new File(sketchPath(path)); if (!f.exists()) f.mkdirs(); } void clearMemoryGrid() { for (int l = 0; l < 105; l++) { for (int y = 0; y < 105; y++) { for (int x = 0; x < 105; x++) { frameData[x][y][l] = color(255); } } } } boolean frameExistsLocally(int targetFrame) { String baseDir = "work" + ordner + "/"; String frameStr = nf(targetFrame, 10); File f = new File(sketchPath(baseDir + "bw/0bw" + frameStr + ".txt")); return f.exists(); } void updateRemoteStatus() { if (!onlineActive) { remoteFrameAvailable = false; return; } if (serverBaseUrl == null || serverBaseUrl.equals("")) { loadServerConfig(); } if (serverBaseUrl != null && !serverBaseUrl.equals("")) { String frameStr = nf(iv, 10); String testUrl = serverBaseUrl + "/smile/work" + ordner + "/bw/0bw" + frameStr + ".txt"; remoteFrameAvailable = checkUrlExists(testUrl); } else { remoteFrameAvailable = false; } } boolean checkUrlExists(String urlString) { try { URL url = new URL(urlString); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("HEAD"); connection.setConnectTimeout(2000); connection.setReadTimeout(2000); int responseCode = connection.getResponseCode(); return (responseCode == 200); } catch (Exception e) { return false; } } void loadServerConfig() { File f = new File(sketchPath("server.txt")); if (f.exists()) { String[] lines = loadStrings("server.txt"); if (lines != null && lines.length > 0) { serverBaseUrl = trim(lines[0]); } } } void addColorToHistory(color c) { if (historyCount > 0 && colorHistory[0] == c) return; int existingIndex = -1; for (int i = 0; i < historyCount; i++) { if (colorHistory[i] == c) { existingIndex = i; break; } } if (existingIndex != -1) { color temp = colorHistory[existingIndex]; for (int i = existingIndex; i > 0; i--) { colorHistory[i] = colorHistory[i - 1]; } colorHistory[0] = temp; } else { for (int i = maxHistory - 1; i > 0; i--) { colorHistory[i] = colorHistory[i - 1]; } colorHistory[0] = c; if (historyCount < maxHistory) historyCount++; } } void pushTrail(int[] arr, int val) { val = constrain(val, 0, 255); if (arr[0] != val) { arr[3] = arr[2]; arr[2] = arr[1]; arr[1] = arr[0]; arr[0] = val; } } void drawTopBar() { fill(255); noStroke(); rect(0, 0, 1200, 30); if (saveFlashTimer > 0) { fill(100, 255, 100); rect(5, 3, 75, 24, 4); saveFlashTimer--; } else if (!frameExistsLocally(iv)) { fill(255, 255, 100); rect(5, 3, 75, 24, 4); } else { fill(245); rect(5, 3, 75, 24, 4); } if (show3DView) { fill(200, 230, 255); } else { fill(240); } stroke(150); rect(235, 3, 95, 24, 4); if (isPlaying) { fill(100, 255, 100); } else { fill(240); } stroke(150); rect(445, 3, 60, 24, 4); if (!onlineActive) { fill(255); } else if (remoteFrameAvailable) { fill(100, 255, 100); } else { fill(255, 255, 100); } stroke(150); rect(1020, 3, 70, 24, 4); if (showHelperGrid) { fill(200, 230, 255); } else { fill(240); } stroke(150); rect(1100, 3, 90, 24, 4); fill(0); textSize(18); textAlign(LEFT, CENTER); text("Datei", 10, 15); text("Frame: " + iv, 90, 15); text("3D-Modus", 242, 15); text("ClearFrame", 335, 15); text("Play", 458, 15); text("Size: " + num, 515, 15); text("Folder: " + ordner, 635, 15); text("Level: " + level, 760, 15); textAlign(CENTER, CENTER); text("Online", 1055, 15); text(showHelperGrid ? "Gitter: AN" : "Gitter: AUS", 1145, 15); textAlign(LEFT, CENTER); } void draw() { processNetworkPassive(); if (isPlaying) { playTimer++; if (playTimer > 15) { playTimer = 0; iv++; if (iv > lastSavedFrame) { iv = 1; } if (frameExistsLocally(iv)) { loadFrameData(iv); } else { clearMemoryGrid(); drawBlankGrid(); } updateRemoteStatus(); } } drawTopBar(); drawColorControls(); if (dom == 1) { dom = 0; drawBlankGrid(); } if (show3DView) { draw3DBlockArea(); } else { fill(255); stroke(180); rect(630, 30, 560, 600); } if (mouseX >= 0 && mouseX < 600 && mouseY >= 30 && mouseY < 630) { int cellX = floor(mouseX / feld); int cellY = floor((mouseY - 30) / feld); if (mousePressed && mouseButton == LEFT) { fill(rc, gc, bc); stroke(200); rect(cellX * feld, 30 + cellY * feld, feld, feld); if (cellX < 105 && cellY < 105) { frameData[cellX][cellY][level] = color(rc, gc, bc); } fill(rc, 0, 0); rect(601 + cellX, 31 + cellY, 1, 1); fill(0, gc, 0); rect(801 + cellX, 31 + cellY, 1, 1); fill(0, 0, bc); rect(601 + cellX, 231 + cellY, 1, 1); int qc = (rc + gc + bc) / 3; fill(qc); rect(801 + cellX, 231 + cellY, 1, 1); fill(rc, gc, bc); rect(601 + cellX, 631 + cellY, 1, 1); addColorToHistory(color(rc, gc, bc)); } if (mousePressed && mouseButton == RIGHT) { color picked = get(mouseX, mouseY); rc = (int)red(picked); gc = (int)green(picked); bc = (int)blue(picked); pushTrail(trailR, rc); pushTrail(trailG, gc); pushTrail(trailB, bc); addColorToHistory(color(rc, gc, bc)); } } if (app == 7) { renderIso3DPassive(); } } void loadLevelToScreen() { fill(220); stroke(180); rect(0, 30, 600, 600); feld = 600.0f / (num + 1); for (int y = 0; y <= num; y++) { for (int x = 0; x <= num; x++) { fill(frameData[x][y][level]); stroke(200); rect(x * feld, 30 + y * feld, feld, feld); } } } void drawBlankGrid() { drawBlankGridWithColor(color(255)); } void drawBlankGridWithColor(color fillColor) { fill(220); stroke(180); rect(0, 30, 600, 600); feld = 600.0f / (num + 1); for (int y = 0; y <= num; y++) { for (int x = 0; x <= num; x++) { fill(fillColor); stroke(200); rect(x * feld, 30 + y * feld, feld, feld); if (x < 105 && y < 105) { frameData[x][y][level] = fillColor; } } } } // ================================================================= // 3D ANSICHT: SOLIDE WÜRFEL MIT BELEUCHTUNG & SCHATTIRUNG // ================================================================= void drawIsoCube(float sx, float sy, float S, color c) { // Oberseite (Licht von oben -> am hellsten) fill(c); stroke(40, 60); beginShape(); vertex(sx, sy); vertex(sx + S, sy + S * 0.5f); vertex(sx, sy + S); vertex(sx - S, sy + S * 0.5f); endShape(CLOSE); // Linke Seite (Mittlerer Schatten) fill(red(c) * 0.75f, green(c) * 0.75f, blue(c) * 0.75f); stroke(40, 60); beginShape(); vertex(sx - S, sy + S * 0.5f); vertex(sx, sy + S); vertex(sx, sy + S + S); vertex(sx - S, sy + S * 0.5f + S); endShape(CLOSE); // Rechte Seite (Dunklerer Schatten, abgewandt) fill(red(c) * 0.55f, green(c) * 0.55f, blue(c) * 0.55f); stroke(40, 60); beginShape(); vertex(sx, sy + S); vertex(sx + S, sy + S * 0.5f); vertex(sx + S, sy + S * 0.5f + S); vertex(sx, sy + S + S); endShape(CLOSE); } void draw3DBlockArea() { fill(245); stroke(180); rect(630, 30, 560, 600); fill(0); textSize(14); textAlign(LEFT, CENTER); text("3D Ansicht (Frame " + iv + " - Solide Würfel mit Beleuchtung)", 645, 48); float originX = 910; float originY = 220; float S = 10.0f; // Exakte Kantenlänge (Länge = Breite = Höhe) if (showHelperGrid) { stroke(180, 120); noFill(); for (int y = 0; y <= num; y++) { float x1 = originX + (0 - y) * S; float y1 = originY + (0 + y) * (S * 0.5f); float x2 = originX + (num - y) * S; float y2 = originY + (num + y) * (S * 0.5f); line(x1, y1, x2, y2); } for (int x = 0; x <= num; x++) { float x1 = originX + (x - 0) * S; float y1 = originY + (x + 0) * (S * 0.5f); float x2 = originX + (x - num) * S; float y2 = originY + (x + num) * (S * 0.5f); line(x1, y1, x2, y2); } } // Solide Würfel (Länge = Höhe = Breite) mit Schattierung rendern for (int l = 0; l <= num; l++) { for (int y = 0; y <= num; y++) { for (int x = 0; x <= num; x++) { color c = frameData[x][y][l]; if (red(c) < 250 || green(c) < 250 || blue(c) < 250) { float sx = originX + (x - y) * S; float sy = originY + (x + y) * (S * 0.5f) - (l * S * 1.0f); drawIsoCube(sx, sy, S, c); } } } } } // ================================================================= // UI & FARB-FUNKTIONEN // ================================================================= void drawColorControls() { noStroke(); for (int i = 0; i <= 255; i++) { stroke(i, 0, 0); line(i, 680, i, 700); stroke(0, i, 0); line(i, 710, i, 730); stroke(0, 0, i); line(i, 740, i, 760); } for (int i = 0; i <= 255; i++) { stroke(i); line(i, 800, i, 820); } for (int i = 0; i < 4; i++) { float alpha = 255 - (i * 60); if (trailR[i] != -1) { stroke(255, 0, 0, alpha); strokeWeight(2); line(trailR[i], 678, trailR[i], 702); } if (trailG[i] != -1) { stroke(0, 255, 0, alpha); strokeWeight(2); line(trailG[i], 708, trailG[i], 732); } if (trailB[i] != -1) { stroke(0, 0, 255, alpha); strokeWeight(2); line(trailB[i], 738, trailB[i], 762); } if (trailBW[i] != -1) { stroke(255, 0, 255, alpha); strokeWeight(2); line(trailBW[i], 798, trailBW[i], 822); } } strokeWeight(1); fill(255); noStroke(); rect(258, 678, 120, 92); fill(255); rect(258, 798, 100, 24); fill(0); textSize(14); textAlign(LEFT, CENTER); text("R: " + rc, 265, 695); text("G: " + gc, 265, 725); text("B: " + bc, 265, 755); text("BW: " + sc, 265, 810); fill(rc, gc, bc); stroke(0); rect(0, 770, 255, 25); fill(240); stroke(180); rect(400, 680, 500, 140, 6); fill(0); textSize(14); text("Farb-Historie:", 415, 700); for (int i = 0; i < maxHistory; i++) { float hx = 415 + (i * 55); float hy = 715; fill(colorHistory[i]); stroke(0); rect(hx, hy, 45, 45, 4); if (i == 0) { noFill(); stroke(0, 255, 0); strokeWeight(2); rect(hx - 2, hy - 2, 49, 49, 6); strokeWeight(1); } } } void mousePressed() { if (mouseX >= 0 && mouseX <= 255) { if (mouseY >= 680 && mouseY <= 700) { rc = mouseX; pushTrail(trailR, rc); return; } if (mouseY >= 710 && mouseY <= 730) { gc = mouseX; pushTrail(trailG, gc); return; } if (mouseY >= 740 && mouseY <= 760) { bc = mouseX; pushTrail(trailB, bc); return; } if (mouseY >= 800 && mouseY <= 820) { int clickedGray = mouseX; int shift = clickedGray - sc; rc = constrain(rc + shift, 0, 255); gc = constrain(gc + shift, 0, 255); bc = constrain(bc + shift, 0, 255); pushTrail(trailBW, clickedGray); pushTrail(trailR, rc); pushTrail(trailG, gc); pushTrail(trailB, bc); return; } } if (mouseX >= 260 && mouseX <= 350) { int fineStep = (mouseButton == LEFT) ? 1 : -1; if (mouseY >= 680 && mouseY <= 710) { rc = constrain(rc + fineStep, 0, 255); pushTrail(trailR, rc); return; } if (mouseY >= 710 && mouseY <= 740) { gc = constrain(gc + fineStep, 0, 255); pushTrail(trailG, gc); return; } if (mouseY >= 740 && mouseY <= 770) { bc = constrain(bc + fineStep, 0, 255); pushTrail(trailB, bc); return; } } if (mouseY >= 715 && mouseY <= 760 && mouseX >= 415 && mouseX <= 415 + (maxHistory * 55)) { int clickedIdx = floor((mouseX - 415) / 55.0f); if (clickedIdx >= 0 && clickedIdx < maxHistory) { color selectedCol = colorHistory[clickedIdx]; rc = (int)red(selectedCol); gc = (int)green(selectedCol); bc = (int)blue(selectedCol); pushTrail(trailR, rc); pushTrail(trailG, gc); pushTrail(trailB, bc); return; } } // Top-Bar Button Klicks if (mouseY >= 0 && mouseY <= 30) { // 3D-Modus Klick (An / Aus) if (mouseX >= 235 && mouseX <= 330) { show3DView = !show3DView; return; } // Play Button Klick if (mouseX >= 445 && mouseX <= 510) { isPlaying = !isPlaying; return; } // Gitter-Button Klick (Hilfsgitter an/aus) if (mouseX >= 1100 && mouseX <= 1190) { showHelperGrid = !showHelperGrid; return; } // Online-Button Klick (Toggle) if (mouseX >= 1020 && mouseX <= 1090) { if (!onlineActive) { File consentFile = new File(sketchPath("online_zugriff.txt")); if (!consentFile.exists()) { int choice = JOptionPane.showConfirmDialog(null, "DISCLAMER: Kosten, Warnungen, Urheberrechte...\n" + "Das Löschen der Datei 'online_zugriff.txt' führt dazu, dass dieses Programm\n" + "nicht auf die Online-Download-Funktion zugreifen kann.\n\n" + "Möchten Sie den Online-Modus aktivieren und die Bedingungen akzeptieren?", "Online-Zugriff Bestätigung", JOptionPane.YES_NO_OPTION); if (choice == JOptionPane.YES_OPTION) { try { PrintWriter pw = createWriter("online_zugriff.txt"); pw.println("Löschen dieser Datei führt dazu, dass dieses Programm smile nicht auf die online download funktion zugreifen kann."); pw.flush(); pw.close(); } catch (Exception e) {} } else { return; } } File serverFile = new File(sketchPath("server.txt")); if (!serverFile.exists()) { String inputUrl = JOptionPane.showInputDialog(null, "Auf welchem Server befindet sich der 'smile'-Ordner?\n(Bitte vollständige URL eingeben, z.B. https://example.com)", "Server-Adresse eingeben", JOptionPane.QUESTION_MESSAGE); if (inputUrl != null && !inputUrl.trim().equals("")) { inputUrl = trim(inputUrl); boolean allowed = checkUrlExists(inputUrl + "/smile/smile_pde_erlaubt.txt"); if (allowed) { try { PrintWriter pw = createWriter("server.txt"); pw.println(inputUrl); pw.flush(); pw.close(); serverBaseUrl = inputUrl; } catch (Exception e) {} } else { JOptionPane.showMessageDialog(null, "Fehler: Unter dieser Adresse wurde kein 'smile'-Ordner oder keine gültige 'smile_pde_erlaubt.txt' gefunden!", "Verbindung fehlgeschlagen", JOptionPane.ERROR_MESSAGE); return; } } else { return; } } else { loadServerConfig(); } onlineActive = true; updateRemoteStatus(); } else { onlineActive = false; remoteFrameAvailable = false; } return; } // Frame Navigation (Links = Zurück, Rechts = Vor) if (mouseX >= 90 && mouseX <= 220) { if (mouseButton == LEFT) iv = max(1, iv - 1); if (mouseButton == RIGHT) iv++; if (frameExistsLocally(iv)) { loadFrameData(iv); } else { clearMemoryGrid(); drawBlankGrid(); } updateRemoteStatus(); } // Size Adjustment if (mouseX >= 515 && mouseX <= 625) { if (mouseButton == LEFT) num = min(100, num + 1); if (mouseButton == RIGHT) num = max(2, num - 1); num1 = num; drawBlankGrid(); } // Clear Frame (Links = Mit Weiß löschen, Rechts = Mit aktueller Farbe füllen) if (mouseX >= 335 && mouseX <= 440) { if (mouseButton == LEFT) { drawBlankGridWithColor(color(255)); } else if (mouseButton == RIGHT) { drawBlankGridWithColor(color(rc, gc, bc)); addColorToHistory(color(rc, gc, bc)); } } // Folder Auswahl (Links = rauf, Rechts = runter) if (mouseX >= 630 && mouseX <= 750) { if (mouseButton == LEFT) ordner++; if (mouseButton == RIGHT) ordner = max(0, ordner - 1); if (frameExistsLocally(iv)) { loadFrameData(iv); } else { clearMemoryGrid(); drawBlankGrid(); } updateRemoteStatus(); } // Level Auswahl if (mouseX >= 760 && mouseX <= 870) { if (mouseButton == LEFT) level = min(num - 1, level + 1); if (mouseButton == RIGHT) level = max(0, level - 1); loadLevelToScreen(); updateRemoteStatus(); } // Klicks auf "Datei" if (mouseX >= 0 && mouseX <= 80) { if (mouseButton == RIGHT) { saveFrameData(); saveFlashTimer = 20; iv++; } else if (mouseButton == LEFT) { iv = lastSavedFrame; loadFrameData(iv); println("Zuletzt gespeichertes Bild geladen: Frame " + iv); } } } } // ================================================================= // DATEI EXPORT ENGINE // ================================================================= void saveFrameData() { String baseDir = "work" + ordner + "/"; ensureDir(baseDir + "r/"); ensureDir(baseDir + "g/"); ensureDir(baseDir + "b/"); ensureDir(baseDir + "bw/"); String generalDir = "work/"; ensureDir(generalDir); String frameStr = nf(iv, 10); for (int l = 0; l < num; l++) { PrintWriter outR1 = createWriter(baseDir + "r/" + l + "r" + frameStr + ".txt"); PrintWriter outG1 = createWriter(baseDir + "g/" + l + "g" + frameStr + ".txt"); PrintWriter outB1 = createWriter(baseDir + "b/" + l + "b" + frameStr + ".txt"); PrintWriter outBW1 = createWriter(baseDir + "bw/" + l + "bw" + frameStr + ".txt"); PrintWriter outR2 = createWriter(generalDir + l + "r" + frameStr + ".txt"); PrintWriter outG2 = createWriter(generalDir + l + "g" + frameStr + ".txt"); PrintWriter outB2 = createWriter(generalDir + l + "b" + frameStr + ".txt"); PrintWriter outBW2 = createWriter(generalDir + l + "bw" + frameStr + ".txt"); for (int y = 0; y <= num; y++) { for (int x = 0; x <= num; x++) { color c = frameData[x][y][l]; int rVal = (int)red(c); int gVal = (int)green(c); int bVal = (int)blue(c); int bwVal = (int)((red(c) + green(c) + blue(c)) / 3); outR1.println(rVal); outG1.println(gVal); outB1.println(bVal); outBW1.println(bwVal); outR2.println(rVal); outG2.println(gVal); outB2.println(bVal); outBW2.println(bwVal); } outR1.println("eol"); outG1.println("eol"); outB1.println("eol"); outBW1.println("eol"); outR2.println("eol"); outG2.println("eol"); outB2.println("eol"); outBW2.println("eol"); } outR1.println("eof"); outG1.println("eof"); outB1.println("eof"); outBW1.println("eof"); outR2.println("eof"); outG2.println("eof"); outB2.println("eof"); outBW2.println("eof"); outR1.flush(); outR1.close(); outG1.flush(); outG1.close(); outB1.flush(); outB1.close(); outBW1.flush(); outBW1.close(); outR2.flush(); outR2.close(); outG2.flush(); outG2.close(); outB2.flush(); outB2.close(); outBW2.flush(); outBW2.close(); } lastSavedFrame = max(lastSavedFrame, iv); println("Kompletter Block (Schichten 0 bis " + (num-1) + ") gespeichert in " + baseDir + " | Frame " + frameStr); } void loadFrameData(int targetFrame) { String baseDir = "work" + ordner + "/"; String frameStr = nf(targetFrame, 10); clearMemoryGrid(); for (int l = 0; l < num; l++) { String[] linesbw = loadStrings(baseDir + "bw/" + l + "bw" + frameStr + ".txt"); String[] linesr = loadStrings(baseDir + "r/" + l + "r" + frameStr + ".txt"); String[] linesg = loadStrings(baseDir + "g/" + l + "g" + frameStr + ".txt"); String[] linesb = loadStrings(baseDir + "b/" + l + "b" + frameStr + ".txt"); if (linesbw != null && linesbw.length > 0) { int rowLength = 0; for (int i = 0; i < linesbw.length; i++) { if (linesbw[i].equals("eol") || linesbw[i].equals("eof")) { rowLength = i; break; } } if (rowLength > 0) { num = rowLength - 1; num1 = num; } } if (linesbw != null && linesr != null && linesg != null && linesb != null) { int idx = 0; int lx = 0, ly = 0; while (idx < linesbw.length && !linesbw[idx].equals("eof")) { if (linesbw[idx].equals("eol")) { ly++; lx = 0; } else { if (lx < 105 && ly < 105 && l < 105) { int vr = int(linesr[idx]); int vg = int(linesg[idx]); int vb = int(linesb[idx]); frameData[lx][ly][l] = color(vr, vg, vb); } lx++; } idx++; } } } loadLevelToScreen(); } // ================================================================= // PASSIVE SYSTEME (Netzwerk & 3D) // ================================================================= void processNetworkPassive() { try { if (myServer0r != null) myServer0r.write(rc); if (myServer0g != null) myServer0g.write(gc); if (myServer0b != null) myServer0b.write(bc); } catch (Exception e) {} } void renderIso3DPassive() { // Passiver Hook }