Cotton code
550 lines · 23.5 KB · PythonRaw
#!/usr/bin/env python3"""Paint the grounds the apps' decks stand on, as seamless tiles, into theLoom package's catalogue.    python3 scripts/paint-ground-tiles.py [<name> ...] [--out <directory>]Each ground is the material its app's icon stands on (Codex, 12 Nov 2026,scripts/import-app-icons.py), its colours measured off the icon's own ground,painted here procedurally so it repeats without a seam: every noise is madeperiodic over the tile (white noise filtered in the frequency domain), everypattern's pitch divides the tile, and every scattered chip is drawn wrapped.Each is a 1024 px JPEG declared 3x (2x on the Mac), as the tolex is, so onetile spans 341 points; `FaceGroundSurface` repeats it under the cards.    calendar-tile       pale blue glazed kitchen tiles, light grout, 85 pt squares    people-amethyst     a desk top painted amethyst, the wood's grain running                        across under the paint (13 Nov 2026)    messages-pegboard   yellow painted pegboard, its holes on a 21 pt pitch    email-linen         rose linen, its weave    notes-felt          burnt-orange wool felt    todos-baize         dark teal baize    money-terrazzo      pink terrazzo, white, rose, grey and cream chips    keys-teal           teal-blue dyed pebbled leather, a valet tray's (13 Nov 2026)    downloads-checker   a record shop's grey vinyl checker floor    developer-mat       a charcoal felt desk mat    podcasts-formica    pale mint boomerang formica, a kitchen windowsill counter's    photos-bench        a darkroom bench: black enamel over planks, worn,                        under the amber safelight    journal-bedside     a dark walnut bedside table top, oiled, its grain                        running across    pages-cobalt        a cobalt-blue enamel desk top, smooth, a faint                        orange peel and a slow cloud in the glaze (13 Nov 2026)    calling-desk        a writing desk's oxblood leather inlay, its fine                        hide grain, waxed, rubbed paler where hands rest    health-slate        a honed slab of blue-grey Welsh slate, its cleavage                        running across in faint laminations, a pale quartz                        thread or two, worn smooth (13 Nov 2026)and one wash, laid once over a tile rather than repeated (`FaceGround.lamp`):    formica-daylight    the window's daylight on the counter, from the upper left (PNG)    bedside-lamp        the bedside lamp's one warm pool on the table, round                        and soft, its middle over the diary (PNG)    desk-lamp           the desk lamp's warm pool on the leather, from above                        and a little left, its middle over the telephone (PNG)No word, figure or object is on any of them."""from __future__ import annotationsimport jsonimport sysfrom pathlib import Pathimport numpy as npfrom PIL import Image, ImageDraw, ImageFilterROOT = Path(__file__).resolve().parent.parentCATALOGUE = ROOT / "apps/loom/Sources/CottonPaper/Media.xcassets"N = 1024def rng(seed: int) -> np.random.Generator:    return np.random.default_rng(seed)def noise(r: np.random.Generator, sx: float, sy: float | None = None) -> np.ndarray:    """Periodic noise over the tile, features about sx by sy pixels, unit spread."""    sy = sx if sy is None else sy    white = r.standard_normal((N, N))    fy = np.fft.fftfreq(N)[:, None]    fx = np.fft.fftfreq(N)[None, :]    gain = np.exp(-2 * (np.pi ** 2) * ((fx * sx) ** 2 + (fy * sy) ** 2))    out = np.real(np.fft.ifft2(np.fft.fft2(white) * gain))    return (out - out.mean()) / (out.std() + 1e-9)def hexrgb(h: str) -> np.ndarray:    h = h.lstrip("#")    return np.array([int(h[i : i + 2], 16) for i in (0, 2, 4)], dtype=float)def shade(base: np.ndarray, light: np.ndarray) -> np.ndarray:    """The base colour lit by `light` (0 is the colour; +1 a full step lighter)."""    return base[None, None, :] * (1 + light[..., None])def worley(r: np.random.Generator, cells: int) -> tuple[np.ndarray, np.ndarray]:    """Periodic cellular noise: the nearest and second-nearest point distances."""    size = N / cells    pts = (np.arange(cells)[:, None, None] * 0 + 0.0)    jitter = r.random((cells, cells, 2))    yy, xx = np.mgrid[0:N, 0:N].astype(float)    cy = (yy // size).astype(int)    cx = (xx // size).astype(int)    f1 = np.full((N, N), 1e9)    f2 = np.full((N, N), 1e9)    for dy in (-1, 0, 1):        for dx in (-1, 0, 1):            ny = cy + dy            nx = cx + dx            j = jitter[ny % cells, nx % cells]            py = (ny + j[..., 0]) * size            px = (nx + j[..., 1]) * size            d = np.hypot(yy - py, xx - px)            f2 = np.where(d < f1, f1, np.minimum(f2, d))            f1 = np.minimum(f1, d)    del pts    return f1 / size, f2 / sizedef fibres(r: np.random.Generator, strength: float) -> np.ndarray:    """Felt: tangled short fibres, as fine noise at a few scales."""    return strength * (0.55 * noise(r, 0.8) + 0.35 * noise(r, 2.5) + 0.25 * noise(r, 9) + 0.18 * noise(r, 60))def felt(base: str, seed: int, strength: float) -> np.ndarray:    r = rng(seed)    return shade(hexrgb(base), fibres(r, strength))def calendar_tile() -> np.ndarray:    r = rng(1)    pitch, grout = 256, 12    base, grout_c = hexrgb("#A9C3CF"), hexrgb("#D9DCD8")    yy, xx = np.mgrid[0:N, 0:N].astype(float)    # distance into each tile from its nearest edge (grout centred on the seams)    u = (xx + grout / 2) % pitch    v = (yy + grout / 2) % pitch    edge = np.minimum(np.minimum(u, pitch - u), np.minimum(v, pitch - v)) - grout / 2    tint = r.normal(0, 0.035, (N // pitch, N // pitch))    ti = ((yy + grout / 2) // pitch).astype(int) % (N // pitch)    tj = ((xx + grout / 2) // pitch).astype(int) % (N // pitch)    light = tint[ti, tj]    light += 0.012 * noise(r, 40) + 0.010 * noise(r, 1.2)    # the glaze rounds over at the tile's edge, lit from the upper left    bevel = np.clip(1 - edge / 10, 0, 1)    lit = np.minimum(u, v) < np.minimum(pitch - u, pitch - v)  # nearest edge is the top or the left    side = np.where(lit, 0.10, -0.16)    light += bevel ** 2 * side    # a soft gloss across each tile    light += 0.05 * np.exp(-(((u - pitch * 0.35) / (pitch * 0.35)) ** 2 + ((v - pitch * 0.3) / (pitch * 0.4)) ** 2))    tile = shade(base, light)    g = shade(grout_c, 0.025 * noise(r, 1.5) - 0.04)    return np.where((edge <= 0)[..., None], g, tile)def people_amethyst() -> np.ndarray:    """The People icon's ground (13 Nov 2026): a desk top painted amethyst,    the wood's grain running across under the paint, softer than bare wood."""    r = rng(2)    base = hexrgb("#8D509B")    yy, xx = np.mgrid[0:N, 0:N].astype(float)    warp = 26 * noise(r, 220, 60) + 6 * noise(r, 60, 14)    rings = ((yy + warp) / (N / 22)) % 1.0    ring_shade = -0.10 * np.abs(np.sin(np.pi * rings)) ** 6 + 0.03 * np.sin(2 * np.pi * rings)    brush = 0.07 * noise(r, 22, 0.7) + 0.04 * noise(r, 3, 0.6)    figure = 0.06 * noise(r, 160, 40)    return shade(base, ring_shade + brush + figure)def messages_pegboard() -> np.ndarray:    r = rng(3)    base = hexrgb("#F6BC1C")    pitch, radius = 64, 7.5    yy, xx = np.mgrid[0:N, 0:N].astype(float)    u = (xx % pitch) - pitch / 2    v = (yy % pitch) - pitch / 2    d = np.hypot(u, v)    light = 0.010 * noise(r, 30) + 0.016 * noise(r, 1.2)    # a soft shadow below and right of each hole, a lit rim above and left    light += -0.10 * np.exp(-((d - radius) / 2.5) ** 2) * np.clip((u + v) / (radius * 1.4), 0, 1)    light += 0.08 * np.exp(-((d - radius) / 2.0) ** 2) * np.clip(-(u + v) / (radius * 1.4), 0, 1)    board = shade(base, light)    hole = shade(hexrgb("#3B2A0A"), -0.4 + 0.5 * np.clip(-v / radius, 0, 1) ** 2)    a = np.clip(radius - d + 0.5, 0, 1)[..., None]    return board * (1 - a) + hole * adef email_linen() -> np.ndarray:    r = rng(4)    base = hexrgb("#D08A80")    yy, xx = np.mgrid[0:N, 0:N].astype(float)    pitch = 4  # 256 threads each way across the tile    slub_h = 0.6 * noise(r, 40, 0.5)[:, :1] + 0.4 * noise(r, 200, 1)  # thread thickness along each row    slub_v = 0.6 * noise(r, 0.5, 40)[:1, :] + 0.4 * noise(r, 1, 200)    warp = np.sin(2 * np.pi * yy / pitch) * (1 + 0.35 * slub_h)    weft = np.sin(2 * np.pi * xx / pitch) * (1 + 0.35 * slub_v)    weave = 0.10 * (warp + weft) / 2 + 0.035 * slub_h + 0.035 * slub_v    mottle = 0.012 * noise(r, 70) + 0.02 * noise(r, 1)    return shade(base, weave + mottle)def notes_felt() -> np.ndarray:    return felt("#984E1C", 5, 0.085)def todos_baize() -> np.ndarray:    return felt("#0E4E4A", 6, 0.10)def money_terrazzo() -> np.ndarray:    r = rng(7)    base = hexrgb("#E0A398")    img = Image.fromarray(np.clip(shade(base, 0.02 * noise(r, 1.0) + 0.03 * noise(r, 50)), 0, 255).astype(np.uint8))    draw = ImageDraw.Draw(img)    palette = ["#F7EEE7", "#F2DCD3", "#C8675F", "#A9918C", "#ECC1AF", "#7D6A68", "#FFF8F2"]    weights = np.array([5, 4, 3, 2, 3, 1, 3], dtype=float)    weights /= weights.sum()    for _ in range(2600):        cx, cy = r.random(2) * N        size = r.choice([2.2, 3.5, 5, 7, 10, 14], p=[0.30, 0.26, 0.20, 0.12, 0.08, 0.04])        sides = int(r.integers(4, 8))        angles = np.sort(r.random(sides) * 2 * np.pi)        radii = size * (0.6 + 0.6 * r.random(sides))        colour = palette[int(r.choice(len(palette), p=weights))]        shape = [(np.cos(a) * q, np.sin(a) * q) for a, q in zip(angles, radii)]        for ox in (-N, 0, N):            for oy in (-N, 0, N):                x0, y0 = cx + ox, cy + oy                if -40 < x0 < N + 40 and -40 < y0 < N + 40:                    draw.polygon([(x0 + dx, y0 + dy) for dx, dy in shape], fill=colour)    img = img.filter(ImageFilter.GaussianBlur(0.5))    out = np.asarray(img).astype(float)    return out * (1 + 0.015 * noise(r, 1.0))[..., None]def keys_teal() -> np.ndarray:    """The Keys icon's ground (13 Nov 2026): a valet tray's pebbled leather    dyed a deep clear teal-blue."""    r = rng(8)    base = hexrgb("#066F87")    f1, f2 = worley(r, 64)    crease = np.exp(-((f2 - f1) / 0.22) ** 2)    pebble = -0.08 * crease + 0.12 * (0.35 - f1 ** 2)  # each pebble a low dome between soft creases    tone = 0.04 * noise(r, 90) + 0.03 * noise(r, 1.0)    return shade(base, pebble + tone)def downloads_checker() -> np.ndarray:    r = rng(9)    pitch = 256    yy, xx = np.mgrid[0:N, 0:N].astype(float)    i = (yy // pitch).astype(int)    j = (xx // pitch).astype(int)    dark = ((i + j) % 2 == 0)[..., None]    light = 0.06 * noise(r, 8) + 0.05 * noise(r, 40) + 0.025 * noise(r, 1.0)    flecks = np.where(noise(r, 1.6) > 2.4, 0.18, 0.0)    a = shade(hexrgb("#3E3C3F"), light + flecks)    b = shade(hexrgb("#666165"), light * 0.8 + flecks * 0.5)    floor = np.where(dark, a, b)    u = xx % pitch    v = yy % pitch    seam = (np.minimum(u, pitch - u) < 1.2) | (np.minimum(v, pitch - v) < 1.2)    return np.where(seam[..., None], floor * 0.78, floor)def developer_mat() -> np.ndarray:    return felt("#34302F", 10, 0.11)def boomerang(size: float, bend: float) -> list[tuple[float, float]]:    """One boomerang, its elbow at the origin pointing up: two tapering arms    swept back either side, as a closed outline."""    outer, inner = [], []    for k in range(25):        t = -1 + 2 * k / 24  # -1 the left tip, +1 the right        x = size * t        y = size * bend * abs(t) ** 1.25        half = size * 0.15 * (1 - 0.85 * abs(t)) + size * 0.015        outer.append((x, y - half))        inner.append((x, y + half))    return outer + inner[::-1]def podcasts_formica() -> np.ndarray:    """Pale mint laminate with the fifties' boomerangs and gold flecks: the    boomerangs low in contrast so a radio stands out on them, the laminate    glossy, and nothing on it lit or shaded (the daylight is its own wash)."""    r = rng(11)    base = hexrgb("#CFE5D6")    img = Image.fromarray(np.clip(shade(base, 0.012 * noise(r, 1.0) + 0.008 * noise(r, 120)), 0, 255).astype(np.uint8))    draw = ImageDraw.Draw(img)    palette = ["#F4F7F0", "#AFD2BE", "#E9BFB3", "#A5B7B3", "#F1E3B8", "#6F8F86"]    weights = np.array([5, 5, 3, 3, 2, 1], dtype=float)    weights /= weights.sum()    for _ in range(95):        cx, cy = r.random(2) * N        size = r.choice([30.0, 42.0, 56.0], p=[0.45, 0.35, 0.20])        turn = r.random() * 2 * np.pi        colour = palette[int(r.choice(len(palette), p=weights))]        outline = [(np.cos(turn) * x - np.sin(turn) * y, np.sin(turn) * x + np.cos(turn) * y) for x, y in boomerang(size, 0.75)]        for ox in (-N, 0, N):            for oy in (-N, 0, N):                x0, y0 = cx + ox, cy + oy                if -80 < x0 < N + 80 and -80 < y0 < N + 80:                    draw.polygon([(x0 + dx, y0 + dy) for dx, dy in outline], fill=colour)    for _ in range(900):  # the gold and charcoal flecks        cx, cy = r.random(2) * N        size = r.choice([1.2, 1.8, 2.6], p=[0.5, 0.35, 0.15])        colour = "#C9A44A" if r.random() < 0.7 else "#3E4B47"        for ox in (-N, 0, N):            for oy in (-N, 0, N):                x0, y0 = cx + ox, cy + oy                if -10 < x0 < N + 10 and -10 < y0 < N + 10:                    draw.ellipse([x0 - size, y0 - size, x0 + size, y0 + size], fill=colour)    img = img.filter(ImageFilter.GaussianBlur(0.6))    out = np.asarray(img).astype(float)    return out * (1 + 0.010 * noise(r, 1.0))[..., None]def formica_daylight() -> np.ndarray:    """The window's daylight on the counter: a soft white wash, strongest at    the upper left and gone by the far corner, as RGBA."""    yy, xx = np.mgrid[0:N, 0:N].astype(float)    d = np.hypot(xx, yy * 1.15) / (N * 1.05)    alpha = 0.55 * np.clip(1 - d, 0, 1) ** 1.8    rgba = np.zeros((N, N, 4))    rgba[..., :3] = hexrgb("#FFFDF4")    rgba[..., 3] = alpha * 255    return rgbadef photos_bench() -> np.ndarray:    """A darkroom bench: matte black enamel brushed over planks, the grain    showing faintly through it, worn paler where trays slid, a few dull    fixer rings dried on it, all warmed by the amber safelight."""    r = rng(11)    base = hexrgb("#2B2420")    yy, xx = np.mgrid[0:N, 0:N].astype(float)    # two broad planks across the tile, their seams dark, each a shade of its own    pitch = N / 2    v = yy % pitch    plank = (yy // pitch).astype(int) % 2    tint = np.array([0.0, 0.025])[plank]    seam = np.exp(-((np.minimum(v, pitch - v)) / 1.6) ** 2)    # the grain under the paint, running along the planks    warp = 18 * noise(r, 260, 50)    rings = ((yy + warp) / (N / 40)) % 1.0    grain = 0.015 * np.sin(2 * np.pi * rings) + 0.015 * noise(r, 90, 2.2)    # the brush's strokes and the paint's fine tooth    strokes = 0.012 * noise(r, 120, 6) + 0.04 * noise(r, 1.2) + 0.02 * noise(r, 6)    # wear: broad paler patches where trays and prints have slid    wear = 0.14 * np.clip(noise(r, 140, 90) - 0.5, 0, None)    # dried fixer rings, wrapped so they never meet a seam of the tile    rings_light = np.zeros((N, N))    for _ in range(5):        cy, cx = r.random(2) * N        radius = 20 + 30 * r.random()        dy = (yy - cy + N / 2) % N - N / 2        dx = (xx - cx + N / 2) % N - N / 2        d = np.hypot(dy, dx)        rings_light += 0.16 * np.exp(-((d - radius) / 2.4) ** 2) + 0.04 * (d < radius)    light = tint + grain + strokes + wear + rings_light - 0.30 * seam    bench = shade(base, light)    # the safelight's amber cast over everything    return bench * np.array([1.04, 0.98, 0.92])[None, None, :]def journal_bedside() -> np.ndarray:    """A bedside table top in dark walnut, oiled to a low sheen: one wide    board and the edge of the next, the grain running across in chocolate    and umber, a few darker streaks of heartwood, open pores, no wear."""    r = rng(12)    base = hexrgb("#4A2F20")    yy, xx = np.mgrid[0:N, 0:N].astype(float)    # one board seam across the tile, the boards a shade apart    pitch = N    v = (yy + N * 0.62) % pitch    board = (((yy + N * 0.62) // pitch).astype(int)) % 2    seam = np.exp(-((np.minimum(v, pitch - v)) / 1.3) ** 2)    tint = 0.02 * board    # the grain: long rings warped slowly, the walnut's cathedral figure    warp = 34 * noise(r, 300, 70) + 8 * noise(r, 80, 16)    rings = ((yy + warp) / (N / 26)) % 1.0    ring_shade = -0.20 * np.abs(np.sin(np.pi * rings)) ** 5 + 0.06 * np.sin(2 * np.pi * rings)    # heartwood streaks, darker, running with the grain    streaks = -0.12 * np.clip(noise(r, 420, 26) - 0.6, 0, None)    pores = 0.09 * noise(r, 16, 0.7) + 0.04 * noise(r, 3, 0.6)    figure = 0.07 * noise(r, 180, 46)    light = tint + ring_shade + streaks + pores + figure - 0.35 * seam    wood = shade(base, light)    # the oil warms it, a touch redder in the umber    return wood * np.array([1.03, 0.99, 0.95])[None, None, :]def bedside_lamp() -> np.ndarray:    """The bedside lamp's pool of warm light on the table, as RGBA: round,    brightest a little above its middle, falling off softly, gone well    before its edge."""    yy, xx = np.mgrid[0:N, 0:N].astype(float)    d = np.hypot(xx - N * 0.5, (yy - N * 0.46) * 1.08) / (N * 0.5)    alpha = 0.62 * np.clip(1 - d, 0, 1) ** 2.2    rgba = np.zeros((N, N, 4))    rgba[..., :3] = hexrgb("#FFC57A")    rgba[..., 3] = alpha * 255    return rgbadef pages_cobalt() -> np.ndarray:    """The Pages icon's ground (13 Nov 2026): a desk top in cobalt-blue    enamel, smooth, its glaze a little cloudy in slow drifts and dimpled    with a fine orange peel; no grain, no pattern."""    r = rng(17)    base = hexrgb("#0D429E")    cloud = 0.045 * noise(r, 150) + 0.02 * noise(r, 45)    peel = 0.018 * noise(r, 2.2) + 0.010 * noise(r, 0.8)    return shade(base, cloud + peel)def calling_desk() -> np.ndarray:    """A writing desk's leather inlay in oxblood going to dark brown: the    hide's fine grain (small soft pebbles between hairline creases, finer    than a valet tray's), the tannage's slow mottle, a waxed low sheen, the    leather rubbed a little paler and redder where hands have rested and a    few fine scuffs, each drawn wrapped. No tooled border: a border would    repeat as a grid across a screen; the leather is the inlay's middle."""    r = rng(31)    base = hexrgb("#4E1C17")    f1, f2 = worley(r, 150)    crease = np.exp(-((f2 - f1) / 0.16) ** 2)    pebble = -0.15 * crease + 0.10 * (0.3 - f1 ** 2)    # the hide's larger creases, long and wandering    g1, g2 = worley(r, 22)    wrinkle = -0.12 * np.exp(-((g2 - g1) / 0.05) ** 2) * np.clip(0.4 + noise(r, 120), 0, 1)    mottle = 0.07 * noise(r, 180) + 0.04 * noise(r, 60)    tooth = 0.025 * noise(r, 1.0) + 0.015 * noise(r, 3)    rubbed = 0.10 * np.clip(noise(r, 260, 200) - 0.3, 0, None)    # fine scuffs, short pale strokes, wrapped    img = Image.new("L", (N, N), 0)    draw = ImageDraw.Draw(img)    for _ in range(60):        cy, cx = r.random(2) * N        angle = r.normal(0.3, 0.5)        length = 10 + 40 * r.random() ** 2        dy, dx = np.sin(angle) * length / 2, np.cos(angle) * length / 2        for oy in (-N, 0, N):            for ox in (-N, 0, N):                draw.line([(cx - dx + ox, cy - dy + oy), (cx + dx + ox, cy + dy + oy)], fill=int(60 + 120 * r.random()), width=1)    scuffs = np.asarray(img.filter(ImageFilter.GaussianBlur(0.8)), dtype=float) / 255    light = pebble + wrinkle + mottle + tooth + rubbed + 0.10 * scuffs    leather = shade(base, light)    # where it is rubbed it warms toward red; the wax deepens the brown elsewhere    warm = np.clip(rubbed[..., None] * 3, 0, 1) * np.array([0.06, -0.01, -0.03])[None, None, :]    return leather * (1 + warm) * np.array([1.02, 0.98, 0.97])[None, None, :]def health_slate() -> np.ndarray:    """Cotton Health's ground (13 Nov 2026): a honed slab of blue-grey    slate, a clinic's old instrument shelf, that the brass pedometer, the    stopwatch and the weighing tags lie on. The rock's cleavage runs across    as long faint laminations (noise far longer across than down), a fine    even grain under them, a slow cloud where the honing wore it paler, and    two hair-thin quartz threads wandering across, each periodic over the    tile."""    r = rng(41)    base = hexrgb("#323B45")    yy, xx = np.mgrid[0:N, 0:N].astype(float)    laminae = 0.03 * noise(r, 700, 14) + 0.012 * noise(r, 320, 3)    grain = 0.03 * noise(r, 0.9) + 0.025 * noise(r, 3.5) + 0.02 * noise(r, 18, 12)    cloud = 0.075 * noise(r, 240, 170)    light = laminae + grain + cloud    stone = shade(base, light)    # The quartz threads: each a periodic wander across the tile, a pale    # line a pixel and a half wide, broken where the noise fades it.    for k, (row, swing, seed) in enumerate(((330.0, 38.0, 3), (780.0, 22.0, 5))):        wander = row + swing * np.sin(2 * np.pi * xx / N + seed) + 9 * np.sin(2 * np.pi * 3 * xx / N + 2 * seed)        dist = np.minimum(np.abs(yy - wander), N - np.abs(yy - wander))        fade = np.clip(0.55 + 0.6 * noise(r, 80, 40), 0, 1)        thread = np.exp(-(dist / (1.3 - 0.4 * k)) ** 2) * fade * (0.32 - 0.1 * k)        quartz = hexrgb("#B9C3CC")[None, None, :]        stone = stone * (1 - thread[..., None]) + quartz * thread[..., None]    return stonedef desk_lamp() -> np.ndarray:    """The desk lamp's pool of warm light on the leather, as RGBA: round and    soft, brightest a little above and left of its middle, gone well before    its edge."""    yy, xx = np.mgrid[0:N, 0:N].astype(float)    d = np.hypot((xx - N * 0.47) * 1.05, (yy - N * 0.44)) / (N * 0.5)    alpha = 0.42 * np.clip(1 - d, 0, 1) ** 2.0    rgba = np.zeros((N, N, 4))    rgba[..., :3] = hexrgb("#FFD7A6")    rgba[..., 3] = alpha * 255    return rgbaPAINTERS = {    "calendar-tile": calendar_tile,    "people-amethyst": people_amethyst,    "messages-pegboard": messages_pegboard,    "email-linen": email_linen,    "notes-felt": notes_felt,    "todos-baize": todos_baize,    "money-terrazzo": money_terrazzo,    "keys-teal": keys_teal,    "downloads-checker": downloads_checker,    "developer-mat": developer_mat,    "podcasts-formica": podcasts_formica,    "formica-daylight": formica_daylight,    "photos-bench": photos_bench,    "journal-bedside": journal_bedside,    "bedside-lamp": bedside_lamp,    "pages-cobalt": pages_cobalt,    "calling-desk": calling_desk,    "desk-lamp": desk_lamp,    "health-slate": health_slate,}def write(name: str, pixels: np.ndarray, out: Path) -> None:    image = Image.fromarray(np.clip(pixels, 0, 255).astype(np.uint8))    folder = out / f"{name}.imageset"    folder.mkdir(parents=True, exist_ok=True)    for old in folder.iterdir():        old.unlink()    # A wash keeps its alpha (PNG); a tile is opaque (JPEG).    extension = "png" if pixels.shape[-1] == 4 else "jpg"    if extension == "png":        image.save(folder / f"{name}.png", optimize=True)    else:        image.save(folder / f"{name}.jpg", quality=88, optimize=True)    contents = {        "images": [            {"filename": f"{name}.{extension}", "idiom": "universal", "scale": "3x"},            {"filename": f"{name}.{extension}", "idiom": "mac", "scale": "2x"},        ],        "info": {"author": "xcode", "version": 1},        "properties": {"preserves-vector-representation": False},    }    (folder / "Contents.json").write_text(json.dumps(contents, indent=2) + "\n")    mean = np.asarray(image)[..., :3].reshape(-1, 3).mean(0)    print(f"{name}: mean #{int(mean[0]):02X}{int(mean[1]):02X}{int(mean[2]):02X}")def main() -> None:    args = sys.argv[1:]    out = CATALOGUE    if "--out" in args:        k = args.index("--out")        out = Path(args[k + 1])        del args[k : k + 2]    for name in args or PAINTERS:        if name not in PAINTERS:            sys.exit(f"no ground named {name}: {', '.join(PAINTERS)}")        write(name, PAINTERS[name](), out)if __name__ == "__main__":    main()