#!/usr/bin/env python3 """Still preview of a packed globe (pack_globe.py output, .bin or .b64.txt files) for picker cards and READMEs. Orthographic view of one layout, points coloured by group with the viewer's palette (microscape-app globe.js: the 24 PALETTE colours, then golden-angle hues), nearer points drawn over farther ones, limb darkened, transparent outside the globe. Writes a PNG or WebP (supersampled, then downscaled). usage: render_preview.py GLOBE_DIR out.png [--layout sculpt] [--lon L --lat B] [--size 640] without --lon/--lat the view faces the points' centre of mass """ import argparse, base64, colorsys, json, os import numpy as np from PIL import Image ap = argparse.ArgumentParser() ap.add_argument("globe"); ap.add_argument("out") ap.add_argument("--layout", default="sculpt"); ap.add_argument("--lon", type=float) ap.add_argument("--lat", type=float); ap.add_argument("--size", type=int, default=640) ap.add_argument("--ss", type=int, default=2, help="supersampling factor") ap.add_argument("--radius", type=float, default=1, help="point radius in output pixels (raise for sparse globes)") a = ap.parse_args() def load(name): p = os.path.join(a.globe, name) if os.path.exists(p + ".bin"): return np.fromfile(p + ".bin", np.uint8) return np.frombuffer(base64.b64decode(open(p + ".b64.txt", "rb").read()), np.uint8) meta = json.load(open(os.path.join(a.globe, "globe.json"))) N = meta["n"] pos = load("pos") grp = pos[4 * N:5 * N] ll = pos[:4 * N].view(" 0 order = np.argsort(depth[vis]) # far first, near drawn last px = (S / 2 + R * right[vis][order]).astype(int) py = (S / 2 - R * up[vis][order]).astype(int) shade = (0.45 + 0.55 * depth[vis][order])[:, None] # limb darkening c = cols[grp[vis][order]] * shade bg = np.array([2, 6, 23]) / 255 # viewer --space #020617 img = np.tile(bg, (S, S, 1)).astype(np.float32) # the sphere itself, dark blue, so gaps between points read as ocean yy, xx = np.mgrid[0:S, 0:S] rr = np.hypot(xx - S / 2, yy - S / 2) / R ocean = rr < 1 img[ocean] = (np.array([9, 22, 48]) / 255) * (0.55 + 0.45 * np.sqrt(np.clip(1 - rr[ocean] ** 2, 0, 1)))[:, None] r = max(1, round(a.radius * a.ss)) # point radius in supersampled pixels for dx in range(-r + 1, r): for dy in range(-r + 1, r): if dx * dx + dy * dy >= r * r: continue qx, qy = np.clip(px + dx, 0, S - 1), np.clip(py + dy, 0, S - 1) img[qy, qx] = c # later (nearer) points win # faint atmosphere ring ring = np.clip(1 - np.abs(rr - 1.0) * 28, 0, 1) * (rr > 0.97) img += ring[..., None] * np.array([0.22, 0.45, 0.8]) * 0.5 # transparent outside the globe and its halo, so the image sits on any background alpha = np.clip(np.maximum(ocean.astype(np.float32), ring * 1.6), 0, 1) rgba = np.dstack([np.clip(img, 0, 1), alpha]) out = Image.fromarray((rgba * 255).astype(np.uint8), "RGBA").resize((a.size, a.size), Image.LANCZOS) out.save(a.out, optimize=True) print(f"{vis.sum():,} of {N:,} points on the near side -> {a.out}")