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.6 KB
Raw Blame
#!/usr/bin/env python3
"""The asking look -> main/pod/pets_ask.c: pod_ask_bubble (the "?" bubble drawn over every pet in the Agent room) and pod_claude_ask (Claude's
raised hand, from assets/claude/ask). Pixels are composited over the room ground, alpha 255 or 0 (ALPHA_CUT), quantised with Floyd-Steinberg dither:
all of that is gen_pro_codex.py's, imported. Codex's ask scene is emitted by gen_pro_codex.py (it shares the send scene's frames).
The bubble's pixels come from assets/ask/bubble.png, drawn once by --draw-bubble: FreeType renders the "?" differently on
macOS and Linux, so drawing it at --check time made CI see the file as stale.
Usage: python3 scripts/gen_pro_ask.py [--check] [--draw-bubble]"""
import re
import sys
from pathlib import Path

from PIL import Image, ImageDraw, ImageFont

sys.path.insert(0, str(Path(__file__).resolve().parent))
import gen_pro_codex as gc

root = gc.root
OUT = root / 'main/pod/pets_ask.c'
FONT = root / 'fonts/Inter-Bold.ttf'
BUBBLE = root / 'assets/ask/bubble.png'
CREAM, INK = (0xF5, 0xF2, 0xED), gc.BG
BW, BH, TAIL = 64, 60, 14                  # the bubble, and the tail's extra rows below it
CLAUDE_MS = 120
CLAUDE_STEPS = [0] * 7 + [1] * 2 + [0] * 3  # up (hand raised) x7, down x2, up x3


def draw_bubble():
    S = gc.OS
    im = Image.new('RGBA', (BW * S, (BH + TAIL) * S), (0, 0, 0, 0))
    d = ImageDraw.Draw(im)
    d.rounded_rectangle((0, 0, BW * S - 1, BH * S - 1), radius=22 * S, fill=CREAM + (255,))
    d.polygon([(10 * S, (BH - 6) * S), (2 * S, (BH + 12) * S), (26 * S, (BH - 2) * S)], fill=CREAM + (255,))   # tail, bottom-left
    d.text((BW * S / 2, BH * S / 2 + 2 * S), '?', font=ImageFont.truetype(str(FONT), 46 * S), fill=INK + (255,), anchor='mm')
    BUBBLE.parent.mkdir(parents=True, exist_ok=True)
    im.resize((BW, BH + TAIL), Image.LANCZOS).save(BUBBLE)


def bubble():
    return gc.prep(Image.open(BUBBLE).convert('RGBA'))


def bubble_code():
    img = bubble()
    grids, palette = gc.quantise([img])
    code, _, _, _ = gc.cell_frames('ask_bubble', [(img.width, img.height, grids[0])], 'ask_bubble_pal')
    # one frame, not an array: pod_ask_bubble is the ht_cell_frame_t itself
    code[-1] = re.sub(r'static const ht_cell_frame_t ask_bubble_frames\[1\] = \{(\{.*\})\};', r'const ht_cell_frame_t pod_ask_bubble = \1;', code[-1])
    return [gc.pal_code('ask_bubble_pal', palette)] + code


def claude_code():
    imgs = [gc.prep(Image.open(root / f'assets/claude/ask/{n}.png').convert('RGBA')) for n in ('up', 'down')]
    w, h = imgs[0].size
    grids, palette = gc.quantise(imgs)
    code, order, _, _ = gc.cell_frames('ask_claude', [(w, h, g) for g in grids], 'ask_claude_pal')
    loop = [order[i] for i in CLAUDE_STEPS]
    n = len(loop)
    return ([gc.pal_code('ask_claude_pal', palette)] + code +
            [f'static const uint8_t ask_claude_loop[{n}] = {{' + ','.join(map(str, loop)) + '};\n',
             f'_Static_assert(sizeof ask_claude_loop == {n}, "pod_claude_ask: steps");\n',
             f'const ht_pet_scene_t pod_claude_ask = {{{w},{h},ask_claude_frames,ask_claude_loop,{n},{CLAUDE_MS},NULL,0,0,NULL,NULL,NULL,NULL,NULL}};\n'])


def generate():
    return ''.join(['// Generated by scripts/gen_pro_ask.py. Do not edit.\n#include "pets.h"\n'] + bubble_code() + claude_code())


def main():
    if '--draw-bubble' in sys.argv:
        draw_bubble()
    text = generate()
    if '--check' in sys.argv:
        sys.exit(0 if OUT.exists() and OUT.read_text() == text else 'main/pod/pets_ask.c is stale: run scripts/gen_pro_ask.py')
    OUT.write_text(text)
    print(f'{OUT.name}: {len(text)} bytes of source')


if __name__ == '__main__':
    main()