Skip to content

The ultimate harness for coding agents and beyond. All your agents. All your machines. One command center. Start with code, then follow your curiosity and build across disciplines: CAD, circuits, robots, games and music.

3.4 KB
Raw Blame
#!/usr/bin/env python3
"""Bakes the round dial's sending sparkle (its ht_spark glyph, 40x48, 2 bpp, copied below) at the Pro's
scale 720/466 (62x74) into main/pod/home/ph_spark.h: one 8-bit coverage per pixel, bilinear like the mockup's CSS mask.
Copy the bytes again only if the round's glyph changes: python3 scripts/gen_ph_spark.py [--check]"""
import os, sys

HERE = os.path.dirname(os.path.abspath(__file__))
OUT = os.path.join(HERE, '../main/pod/home/ph_spark.h')
W, H, OW, OH = 40, 48, 62, 74
SPARK = [  # ht_spark's pixels: 4 px a byte, high bits first
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 2, 64, 0, 0, 0, 0, 0, 0, 0, 0, 2, 128, 0, 0, 0, 0,
    0, 0, 0, 0, 7, 128, 0, 0, 0, 0, 0, 0, 0, 0, 7, 208, 0, 0, 0, 0,
    0, 0, 0, 0, 11, 208, 0, 0, 0, 0, 0, 0, 0, 0, 27, 224, 0, 0, 0, 0,
    0, 0, 0, 0, 31, 244, 0, 0, 0, 0, 0, 0, 0, 0, 47, 244, 0, 0, 0, 0,
    0, 0, 0, 0, 47, 248, 0, 0, 0, 0, 0, 0, 0, 0, 127, 248, 0, 0, 0, 0,
    0, 0, 0, 0, 191, 253, 0, 0, 0, 0, 0, 0, 0, 0, 191, 254, 0, 0, 0, 0,
    0, 0, 0, 1, 255, 254, 0, 0, 0, 0, 0, 0, 0, 6, 255, 255, 144, 0, 0, 0,
    0, 0, 1, 175, 255, 255, 233, 64, 0, 0, 0, 1, 107, 255, 255, 255, 255, 233, 0, 0,
    0, 90, 255, 255, 255, 255, 255, 255, 165, 0, 26, 255, 255, 255, 255, 255, 255, 255, 255, 160,
    6, 191, 255, 255, 255, 255, 255, 255, 254, 144, 0, 22, 255, 255, 255, 255, 255, 255, 148, 0,
    0, 0, 90, 255, 255, 255, 255, 165, 0, 0, 0, 0, 0, 91, 255, 255, 229, 0, 0, 0,
    0, 0, 0, 2, 255, 255, 64, 0, 0, 0, 0, 0, 0, 0, 191, 254, 0, 0, 0, 0,
    0, 0, 0, 0, 191, 253, 0, 0, 0, 0, 0, 0, 0, 0, 127, 253, 0, 0, 0, 0,
    0, 0, 0, 0, 127, 248, 0, 0, 0, 0, 0, 0, 0, 0, 47, 248, 0, 0, 0, 0,
    0, 0, 0, 0, 47, 244, 0, 0, 0, 0, 0, 0, 0, 0, 31, 244, 0, 0, 0, 0,
    0, 0, 0, 0, 11, 224, 0, 0, 0, 0, 0, 0, 0, 0, 11, 208, 0, 0, 0, 0,
    0, 0, 0, 0, 7, 208, 0, 0, 0, 0, 0, 0, 0, 0, 7, 128, 0, 0, 0, 0,
    0, 0, 0, 0, 2, 128, 0, 0, 0, 0, 0, 0, 0, 0, 2, 64, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
]

def bake():
    lv = [(b >> k) & 3 for b in SPARK for k in (6, 4, 2, 0)]
    a = lambda x, y: lv[y * W + x] * 85 if 0 <= x < W and 0 <= y < H else 0
    out = []
    for oy in range(OH):
        for ox in range(OW):
            fx, fy = (ox + .5) * W / OW - .5, (oy + .5) * H / OH - .5
            x0, y0 = int(fx // 1), int(fy // 1)
            tx, ty = fx - x0, fy - y0
            v = (a(x0, y0) * (1 - tx) + a(x0 + 1, y0) * tx) * (1 - ty) + (a(x0, y0 + 1) * (1 - tx) + a(x0 + 1, y0 + 1) * tx) * ty
            out.append(min(255, int(v + .5)))
    rows = [', '.join(f'{v:3d}' for v in out[y * OW:(y + 1) * OW]) for y in range(OH)]
    return ('// Generated by scripts/gen_ph_spark.py from the round\'s ht_spark: do not edit.\n#pragma once\n#include <stdint.h>\n\n'
            f'enum {{ PH_SPARK_W = {OW}, PH_SPARK_H = {OH} }};\nstatic const uint8_t PH_SPARK_ALPHA[PH_SPARK_W * PH_SPARK_H] = {{\n'
            + ''.join(f'    {r},\n' for r in rows) + '};\n')

text = bake()
if '--check' in sys.argv:
    sys.exit(0 if os.path.exists(OUT) and open(OUT).read() == text else 'ph_spark.h is stale: run scripts/gen_ph_spark.py')
open(OUT, 'w').write(text)