CyberCity/tools/metrics.py
MiguelCarino 91e13f5d8a Twenty swatches, a frontier that fills at noon, and no roads on the Moon
THE PALETTE COULD NOT SPELL A MATERIAL. Twelve swatches with no brown,
no neutral grey and no tan in them, so every wall the map could name
fell through surf_west's `hue === P.warm || P.white || P.ember ? hue :
P.amber` and printed as sodium. Eight are appended — stone, timber,
sand, jade, rose, gold, moss, indigo — each with a night rung and a day
rung, fitted by measuring printed ceilings rather than by eye. The
ladder rule holds: the brightest new ceiling is gold at 157, still 22
under amber's pillar at 179. rose carries the lowest gain in either
table, so its knee crushes everything under lum 96 and "signage only,
never a field" is arithmetic instead of a note. Slots 0-11 do not move
and every frame in every world renders byte-identical against a
twelve-swatch revert; PALETTE is append-only now and CONTRACT says why.

THE FRONTIER WAS A HOLE AT NOON. board() painted the lap lines and left
the wall between them blank, which is the right answer for a night
frame and the wrong one for a lit wall — a 24 m false front is blank
boarded wall by construction, so the tallest things in that world were
the emptiest. 42% of the noon frame was blank. It now fills by day and
only by day, in the material the map hands it: measured at noon, blank
10.6% and the lit energy sand 35 / white 32 / stone 13 / timber 5.6.
Dusk is untouched, because dusk is what that world is for.

NO STRAIGHT ROADS ON THE MOON. Two parallel dashed rover rails 2.06 m
apart with a churned strip down the middle, drawn continuous to the
vanishing point — the comment defended them as the world's only supply
of lines that CONVERGE, and it was right about the problem and wrong
about the answer, because that is a road. The convergence comes off the
terrain instead: rolling relief in the heightmap so the horizon
undulates, crater chains and doublets, ejecta rays, rilles. What is
left of the crew is a track that meanders and prints that wander.
Rendered at three yaws looking for an axis-aligned edge and there is
none. The Moon holds the night muddy target at every hour and both
seeds, 5.0-11.8%.

THE CITY HAS COLOUR AND THE CROWD HAS PEOPLE IN IT. Nine districts
instead of six, with jade, gold, moss and indigo carrying them and rose
as a narrow accent that is never a district hue; stone and sand take
the day, because at noon a city is a grey concrete canyon. The crowd
goes 15 costumes to 23 — child, cycle, carry, flare, vendor, bedroll,
wheels, runner — every one of them distinguishable as a silhouette at
eight rows, with the near-field detail gated on height so it costs
nothing in the middle distance. The sci-fi half stays gated on the
frontier and the hash draws are still taken, so no downstream stream
moves between worlds.

THE BUDGET HELD AND THE LINE DID NOT MOVE. Fourth pass at 560 KB, first
time it has held under pressure: the colour work landed at 575.5 KB and
build.js failed, which is the gate working. The essay there says cut
before you move the number and names indentation as the thing it will
not strip, on figures of "~6 KB" and "about 25 KB" that nobody had
re-measured — it is 84,232 bytes, 14.3% of the bundle. Halved rather
than stripped, one space per level, so View Source is still a nested
document: 42,134 bytes, and the build is 534.4 KB with 25.6 KB spare.
The whitespace is spent; whoever lands here next has one fewer option.

TWO DEFECTS IN THE PHOTOSENSITIVITY TOOL, NEITHER IN THE CITY.
flicker-rate.cjs crashed outright on a bare window argument, because
positional 0 is the source path. And it judged the 3-20 Hz rule at any
window when the 2% limit was fitted at one: the metric is a peak DFT
bin, so it falls as 1/sqrt(T) for ever on the same signal — 8.07% at
2 s down to 0.94% at 120 s on a broadband personality with no line in
it, identical on the tree before this pass. It now measures at any
window and judges only at the 60 s default. The limit is not touched;
normalising by sqrt(T/60) would shrink a real 5 Hz tube fourfold at a
short window, which is a safety regression dressed as a fix.

Elements 51 -> 70; city 42, frontier 33, Moon 16. README carries the
full eighteen-frame census instead of six numbers that had gone stale,
and all eight screenshots are regenerated from this tree.

domshim 288/288, all three photosensitivity gates pass, renders are
byte-identical on a re-run, and an instrumented put/poke found no NaN
lum and no out-of-range swatch across 54 frames and every weather
preset in every world.
2026-08-20 09:00:11 -06:00

98 lines
5 KiB
Python

#!/usr/bin/env python3
"""Measure a CyberCity CCFRAME dump: exposure and colour-energy split.
A cell is classified by what it ACTUALLY prints — max(r,g,b) scaled by lum — not by lum
alone, because lum lies: P.shadow at lum 255 is still only (40,50,66) while P.pure at lum
40 is (40,40,40). "black" therefore means a cell no eye would call lit.
Reads CCFRAME 1 (glyph,colour,lum) and CCFRAME 2 (glyph,colour,lum,KIND) alike. The v2
kind byte was added when the harness started dumping it and this file was not updated, so
it unpacked three fields from a four-field cell and died with a ValueError on every dump
the current tools/headless.cjs writes. Two agents worked around it with throwaway scripts
rather than fixing it; the fix is the two lines below and a kind breakdown for free.
python3 tools/metrics.py f.txt [more.txt ...]
"""
import sys, json
# Must stay in step with core.js's PALETTE, in order and in length. The energy split indexes
# `ci % len(NAMES)` and the pigment lookup indexes `ci % len(pal)`, so a NAMES list shorter than
# the palette does not raise -- it wraps, and every stone cell in the frame is reported as amber.
# Eight swatches were appended to the palette (12..19) and this line is the whole of what that
# cost the census.
NAMES = ['amber','azure','ember','spring','violet','white','red','slate','warm','ice','pure','shadow',
'stone','timber','sand','jade','rose','gold','moss','indigo']
KINDS = ['sky', 'facade', 'floor', 'element']
def load(src):
lines = open(src).read().split('\n')
cols, rows = map(int, lines[1].split())
pal = [tuple(map(int, c.split(','))) for c in lines[2].split(' ', 1)[1].split()]
glyphs = json.loads(lines[3].split(' ', 1)[1])
cells = []
for y in range(rows):
parts = lines[4 + y].split(' ')
cells.append([tuple(int(v) for v in p.split(',')) for p in parts[:cols]])
return cols, rows, pal, glyphs, cells
def main(srcs):
tot_cell = 0; blank = 0; dead = 0; mid = 0; litcell = 0
energy = [0.0]*len(NAMES); litE = [0.0]*len(NAMES)
kinds = [0]*len(KINDS); kindLit = [0]*len(KINDS)
# The two numbers core.js's EXPOSURE comment tells the reader to measure, which this file
# could not see: the muddy band v=9-119 (target under 30%) and the hot tail v>=170 (target
# 3.5-5%). They are deliberately NOT the same cut as the mid(9-59)/lit(v>=60) split above --
# that split answers "is the cell visible", these answer "is the print curve in calibration"
# -- so both are reported rather than one replacing the other. black% is kept because it is
# in every historical report, but it is pinned by `blank` and cannot detect a curve change.
muddy = 0; hot = 0; litv = []
for src in srcs:
cols, rows, pal, glyphs, cells = load(src)
for y in range(rows):
for x in range(cols):
cell = cells[y][x]
# v1 carries three fields per cell, v2 four; the fourth is the kind byte.
ch, ci, lu = cell[0], cell[1], cell[2]
kd = cell[3] if len(cell) > 3 else -1
tot_cell += 1
if 0 <= kd < len(KINDS): kinds[kd] += 1
if ch == 0 or lu == 0:
blank += 1; dead += 1
continue
if 0 <= kd < len(KINDS): kindLit[kd] += 1
r, g, b = pal[ci % len(pal)]
k = lu/255.0
# what the pixel ACTUALLY renders at — lum alone lies, because P.shadow at
# lum 255 is still only (26,30,38) while P.pure at lum 40 is (40,40,40).
v = max(r, g, b) * k
e = (r+g+b)/3.0 * k
if 9 <= v < 120: muddy += 1
if v >= 170: hot += 1
if v >= 9: litv.append(v)
if v < 9: dead += 1
elif v < 60: mid += 1
else:
litcell += 1
litE[ci % len(NAMES)] += e
energy[ci % len(NAMES)] += e
es = sum(energy) or 1.0
ls = sum(litE) or 1.0
print(f"files={len(srcs)} cells={tot_cell}")
print(f" blank {blank/tot_cell*100:.1f}% black(v<9) {dead/tot_cell*100:.1f}%"
f" mid(9-59) {mid/tot_cell*100:.1f}% lit(v>=60) {litcell/tot_cell*100:.1f}%")
litv.sort()
p90 = litv[int(0.90 * (len(litv) - 1))] if litv else 0.0
print(f" CURVE: muddy(9-119) {muddy/tot_cell*100:.1f}% [target <30]"
f" hot(v>=170) {hot/tot_cell*100:.2f}% [target 3.5-5]"
f" lit p90 {p90:.0f}")
order = sorted(range(len(NAMES)), key=lambda i: -litE[i])
print(" LIT energy: " + " ".join(f"{NAMES[i]} {litE[i]/ls*100:.1f}%" for i in order if litE[i]/ls > 0.0005))
order = sorted(range(len(NAMES)), key=lambda i: -energy[i])
print(" all energy: " + " ".join(f"{NAMES[i]} {energy[i]/es*100:.1f}%" for i in order if energy[i]/es > 0.0005))
if sum(kinds):
print(" by kind: " + " ".join(
f"{KINDS[i]} {kinds[i]/tot_cell*100:.1f}% (lit {kindLit[i]/tot_cell*100:.1f}%)"
for i in range(len(KINDS))))
if __name__ == '__main__':
main(sys.argv[1:])