Thumbnail.

2D Projection of A Calabi–Yau Height Map

Description

I asked Chatgpt o4-mini-high to write Python code that visualizes a Calabi–Yau manifold using all 24-bit rgb colors. I think the results look interestingly “stringy.”

#!/usr/bin/env python3
"""
Generate a 4096×4096 image of a 2D projection of a Calabi–Yau "height map",
using each of the 16,777,216 24-bit RGB colors exactly once.
"""

import numpy as np
from PIL import Image

# Image dimensions
W, H = 4096, 4096
N = W * H  # 16,777,216

# 1) Build a “height field” sampling a 2D slice of the quintic Calabi–Yau.
u = np.linspace(0, 2*np.pi, W, endpoint=False)
v = np.linspace(0, 2*np.pi, H, endpoint=False)
U, V = np.meshgrid(u, v, indexing='xy')

height = (
    np.cos(5*U) * np.cos(5*V) +
    0.5 * np.cos(3*U + 2*V) * np.cos(2*U - 4*V) +
    0.25 * np.sin(7*U + 3*V)
)
height = (height - height.min()) / (height.max() - height.min())

# 2) Sort pixels by height so we can “paint” along the surface:
flat_idx = np.arange(N, dtype=np.int32)
# Use ravel(order='C') instead of ravel(kind='C')
order = np.argsort(height.ravel(order='C'))

# 3) Generate **all** 24-bit colors in lex order (r, g, b):
colors = np.empty((N, 3), dtype=np.uint8)
vals = np.arange(N, dtype=np.int32)
colors[:, 0] = (vals >> 16) & 0xFF
colors[:, 1] = (vals >> 8) & 0xFF
colors[:, 2] = vals & 0xFF

# 4) Assign every unique color exactly once along the manifold ordering:
canvas = np.zeros((N, 3), dtype=np.uint8)
canvas[order] = colors

# 5) Reshape back to H×W×3 and save:
img = canvas.reshape((H, W, 3), order='C')
result = Image.fromarray(img, mode='RGB')
result.save('calabi_yau_full_palette.png')

print("Done: calabi_yau_full_palette.png")

Author

ACJ
44 entries

Stats

Date
Colors16,777,216
Pixels16,777,216
Dimensions4,096 × 4,096
Bytes40,755,375