Created
July 3, 2025 08:06
-
-
Save PhoenixGameDevelopment/086729be89c7ba861c026ca7edde24f2 to your computer and use it in GitHub Desktop.
Simple AI-Generated Program to Display a Rotating "Tesseract" (4D cube) on the Screen.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Drawing; | |
using System.Windows.Forms; | |
class Tesseract : Form | |
{ | |
// Tesseract vertices (4D) | |
readonly double[,] vertices4D = new double[16, 4]; | |
double[,] projected3D = new double[16, 3]; | |
PointF[] vertices2D = new PointF[16]; | |
// Animation angles | |
double angleXY, angleXZ, angleXW, angleYW, angleZW; | |
public Tesseract() | |
{ | |
Text = "Rotating Tesseract (4D Cube)"; | |
ClientSize = new Size(600, 600); | |
DoubleBuffered = true; | |
// Initialize 4D vertices | |
for (int i = 0; i < 16; i++) | |
{ | |
vertices4D[i, 0] = (i & 1) != 0 ? 1 : -1; | |
vertices4D[i, 1] = (i & 2) != 0 ? 1 : -1; | |
vertices4D[i, 2] = (i & 4) != 0 ? 1 : -1; | |
vertices4D[i, 3] = (i & 8) != 0 ? 1 : -1; | |
} | |
// Animation timer | |
var timer = new Timer { Interval = 50 }; | |
timer.Tick += (s, e) => | |
{ | |
angleXY += 0.01; | |
angleXW += 0.02; | |
angleZW += 0.015; | |
Invalidate(); | |
}; | |
timer.Start(); | |
Paint += (s, e) => | |
{ | |
// Project 4D→3D→2D | |
ProjectTo3D(); | |
ProjectTo2D(); | |
// Draw edges (hard-coded tesseract connections) | |
int[,] edges = { | |
{0,1}, {0,2}, {0,4}, {0,8}, {1,3}, {1,5}, {1,9}, | |
{2,3}, {2,6}, {2,10}, {3,7}, {3,11}, {4,5}, {4,6}, | |
{4,12}, {5,7}, {5,13}, {6,7}, {6,14}, {7,15}, {8,9}, | |
{8,10}, {8,12}, {9,11}, {9,13}, {10,11}, {10,14}, | |
{11,15}, {12,13}, {12,14}, {13,15}, {14,15} | |
}; | |
for (int i = 0; i < edges.GetLength(0); i++) | |
{ | |
e.Graphics.DrawLine(Pens.Cyan, | |
vertices2D[edges[i, 0]], | |
vertices2D[edges[i, 1]]); | |
} | |
}; | |
} | |
void ProjectTo3D() | |
{ | |
// Apply 4D rotation matrices | |
for (int i = 0; i < 16; i++) | |
{ | |
double x = vertices4D[i, 0], y = vertices4D[i, 1], | |
z = vertices4D[i, 2], w = vertices4D[i, 3]; | |
// Rotate in XY plane | |
double xy = x; | |
x = xy * Math.Cos(angleXY) - y * Math.Sin(angleXY); | |
y = xy * Math.Sin(angleXY) + y * Math.Cos(angleXY); | |
// Rotate in XW plane | |
double xw = x; | |
x = xw * Math.Cos(angleXW) - w * Math.Sin(angleXW); | |
w = xw * Math.Sin(angleXW) + w * Math.Cos(angleXW); | |
// Rotate in ZW plane | |
double zw = z; | |
z = zw * Math.Cos(angleZW) - w * Math.Sin(angleZW); | |
w = zw * Math.Sin(angleZW) + w * Math.Cos(angleZW); | |
// Project 4D → 3D (perspective projection) | |
double scale = 1 / (w + 4); | |
projected3D[i, 0] = x * scale; | |
projected3D[i, 1] = y * scale; | |
projected3D[i, 2] = z * scale; | |
} | |
} | |
void ProjectTo2D() | |
{ | |
// Project 3D → 2D (orthographic) | |
for (int i = 0; i < 16; i++) | |
{ | |
vertices2D[i] = new PointF( | |
(float)(projected3D[i, 0] * 100 + Width / 2), | |
(float)(projected3D[i, 1] * 100 + Height / 2) | |
); | |
} | |
} | |
/* | |
static void Main() | |
{ | |
Application.Run(new Tesseract()); | |
} | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment