Thumbnail.

Faux Amplituhedron

Description

I’m not a physicist or mathematician by any stretch of the imagination, but I always enjoy watching lectures of Nima Arkani-Hamed on things like qft online. One concept he works on that I find particularly fascinating (although I won’t claim to understand it) is the amplituhedron, so I asked Chatgpt to visualize it in 24-bit rgb.

As you can read in one of the code comments, the script uses a placeholder curve for the amplituhedron evaluation (more on that in a later entry). However, the resulting image was interesting and pretty, and frankly, that’s enough reason to publish it here.

import numpy as np
from PIL import Image
from matplotlib.colors import rgb_to_hsv
from hilbertcurve.hilbertcurve import HilbertCurve

# 1) Parameters
W = H = 4096
N = W * H
γ = 0.6           # gamma for midtone boost (0<γ<1)
alpha = 1e-6      # weight for spatial locality

# 2) Your amplituhedron “height” function on [0,1]^2
def amplituhedron_value(u, v):
    # —REPLACE— with a true amplituhedron evaluation
    return np.sin(10*u)*np.cos(12*v) + 0.5*np.exp(-((u-0.5)**2 + (v-0.5)**2)*30)

# 3) Sample the field
ys = np.linspace(0, 1, H)
xs = np.linspace(0, 1, W)
U, V = np.meshgrid(xs, ys)
F = amplituhedron_value(U, V).ravel()

# 4) Normalize + gamma-correct
Fmin, Fmax = F.min(), F.max()
Fnorm = (F - Fmin) / (Fmax - Fmin)
Fγ = Fnorm ** γ

# 5) Compute 2D Hilbert indices for pixels
hc2 = HilbertCurve(p=12, n=2)  # 2^12 = 4096
# build list of integer (x,y) pairs
coords2d = np.column_stack((
    np.floor(U.ravel() * (W-1)).astype(int),
    np.floor(V.ravel() * (H-1)).astype(int),
))
# use distances_from_points to get all distances at once
hil2 = np.array(
    hc2.distances_from_points(coords2d.tolist()),
    dtype=float
)
hil2 /= (N - 1)  # normalize to [0,1]

# 6) Composite score and pixel ordering
composite = Fγ + alpha * hil2
pixel_order = np.argsort(-composite, kind='mergesort')

# 7) Build the full 24-bit palette
all_idxs = np.arange(256**3, dtype=np.uint32)
palette = np.empty((all_idxs.size, 3), dtype=np.uint8)
palette[:,0] = (all_idxs >> 16) & 0xFF
palette[:,1] = (all_idxs >>  8) & 0xFF
palette[:,2] =  all_idxs        & 0xFF

# 8) Sort palette by HSV for a rainbow sweep
hsv = rgb_to_hsv(palette.astype(float) / 255.0)
color_order = np.lexsort((hsv[:,2], hsv[:,1], hsv[:,0]))  # H→S→V

# 9) Map each pixel to its unique color
img_flat = np.empty((N, 3), dtype=np.uint8)
img_flat[pixel_order] = palette[color_order]

# 10) Reshape and save
img = img_flat.reshape((H, W, 3))
Image.fromarray(img).save('amplituhedron_visually_enhanced.png')
print("Done! Saved as amplituhedron_visually_enhanced.png")

Author

ACJ
53 entries

Stats

Date
Colors16,777,216
Pixels16,777,216
Dimensions4,096 × 4,096
Bytes49,828,290