#!/usr/bin/gawk -f # reinhard@finalmedia.de # Thu May 14 11:06:17 AM CEST 2026 # Public Domain # Beispiel: gawk -v width=1920 -v height=1080 -f torus.awk > /dev/shm/videocmd BEGIN { if (!width) width = 1920; if (!height) height = 1080; cx = width / 2; cy = height / 2; # Radien des Torus (R1 = Schlauchradius, R2 = Abstand zum Zentrum) R1 = 150; R2 = 320; # Rotationswinkel (starten bei 0) A = 0; B = 0; # Hauptschleife für die Animation while (1) { # Bildschirm leeren für das neue Frame print "c 0 0 0"; print "m 0 0"; print "r " width " " height; # Rotationsgeschwindigkeiten erhöhen A += 0.05; B += 0.03; cosA = cos(A); sinA = sin(A); cosB = cos(B); sinB = sin(B); # Gitternetz des Torus abtasten (Schritte steuern Punktdichte) for (theta = 0; theta < 6.28; theta += 0.15) { costheta = cos(theta); sintheta = sin(theta); for (phi = 0; phi < 6.28; phi += 0.05) { cosphi = cos(phi); sinphi = sin(phi); # 1. 3D-Koordinaten auf der Torus-Oberfläche berechnen circle_x = R2 + R1 * costheta; circle_y = R1 * sintheta; # 2. Rotation im 3D-Raum anwenden x3d = circle_x * (cosB * cosphi + sinA * sinB * sinphi) - circle_y * cosA * sinB; y3d = circle_x * (sinB * cosphi - sinA * cosB * sinphi) + circle_y * cosA * cosB; z3d = 1000 + circle_x * cosA * sinphi + circle_y * sinA; # 1000 verschiebt das Objekt in die Tiefe # 3. Perspektivische Projektion auf den 2D-Bildschirm # K1 ist der Skalierungsfaktor für das Sichtfeld K1 = width * 1.2; sx = int(x3d * K1 / z3d + cx); sy = int(-y3d * K1 / z3d + cy); # Negativ für mathematisch korrektes Y # 4. Prüfen, ob der Punkt sichtbar ist if (sx >= 0 && sx < width && sy >= 0 && sy < height) { # Tiefen-Shading: Vorderseite hell, Rückseite dunkel # Z-Werte liegen hier etwa zwischen 600 und 1400 brightness = int((1400 - z3d) / 800 * 215) + 40; if (brightness < 40) brightness = 40; if (brightness > 255) brightness = 255; # Wir nutzen ein sattes Retro-Cyan für das Drahtgittermodell # Rot ist abgedunkelt, Grün und Blau steuern die Helligkeit r = int(brightness * 0.2); g = brightness; b = brightness; print "p " sx " " sy " " r " " g " " b; } } } # Frame-Timing für flüssige 60 FPS (~16.6ms) print "s 16666"; fflush(); } }