EMI buttons: each button rebuilt within its own rectangle (the bigger ones on the right were cut apart by a 12 px grid); the face told from the symbol by colour

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Fulldroper
2026-10-14 14:12:34 +03:00
co-authored by Claude Opus 5.5
parent 6d3a4b03b1
commit 5203335655
2 changed files with 57 additions and 43 deletions
Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

+42 -28
View File
@@ -474,50 +474,64 @@ def casingify(sheet: Image.Image, wood: np.ndarray, frame, face=None) -> Image.I
return Image.fromarray(np.clip(out, 0, 255).astype(np.uint8), 'RGBA') return Image.fromarray(np.clip(out, 0, 255).astype(np.uint8), 'RGBA')
def casing_buttons(sheet: Image.Image, wood: np.ndarray, brass_wood: np.ndarray, frame, tiles, cell: int = 12) -> Image.Image: # EMI's buttons.png (EMI 1.1): where each button is, as (x, y, width, height). EMI draws them from these rectangles,
"""EMI's buttons: a grid of 12 x 12 cells, each a black ring, a one-pixel bevel and a flat face with a symbol. # so each one is rebuilt inside its own bounds — a grid over the whole sheet cut the bigger ones apart.
The ring stays (a white ring — the highlighted state — turns brass), the bevel becomes the casing's metal frame, EMI_BUTTON_CELLS = (
a grey face becomes wood (brass casing's darker wood when highlighted, dimmed when disabled); a coloured face (EMI's [(x, y, 12, 12) for y in range(0, 84, 12) for x in range(0, 84, 12)] # small buttons, 3 states each
green "switched on") keeps its colour. Symbols are kept, grey ones in cream.""" + [(x, y, 20, 20) for x in (164, 184, 204) for y in (0, 20)] # config, tree, "EMI"
+ [(164, 40, 20, 20), (164, 60, 20, 20)] # the globe button
+ [(x, y, 16, 16) for x in (224, 240) for y in (0, 16, 32)] # page arrows
+ [(x, y, 12, 10) for x in (232, 244) for y in (48, 58)] # small up / down
)
def casing_buttons(sheet: Image.Image, wood: np.ndarray, brass_wood: np.ndarray, frame, tiles, cells=EMI_BUTTON_CELLS) -> Image.Image:
"""EMI's buttons rebuilt like ours. Each cell is a 1 px ring, a 1 px bevel and a flat face with a symbol. The ring
stays (a white ring — the highlighted state — turns brass), the bevel takes the casing's metal from the block's own
edge, a grey face becomes wood (brass casing's wood when highlighted, dimmed when disabled), a coloured face (EMI's
green "on") keeps its colour; symbols are kept, grey ones in cream, their dark shadows in dark wood."""
px = np.asarray(sheet.convert('RGBA')).astype(np.float32) px = np.asarray(sheet.convert('RGBA')).astype(np.float32)
out = px.copy() out = px.copy()
for cy in range(0, px.shape[0], cell): for cx, cy, w, h in cells:
for cx in range(0, px.shape[1], cell): c = px[cy:cy + h, cx:cx + w]
c = px[cy:cy + cell, cx:cx + cell] if c.shape[:2] != (h, w) or (c[..., 3] > 0).sum() < w * h * 0.9:
if c.shape[:2] != (cell, cell) or (c[..., 3] > 0).sum() < cell * cell * 0.9: continue # an empty place in the grid
continue
lum = c[..., :3].mean(axis=2) lum = c[..., :3].mean(axis=2)
ring = np.zeros((cell, cell), bool) ring = np.zeros((h, w), bool)
ring[0, :] = ring[-1, :] = ring[:, 0] = ring[:, -1] = True ring[0, :] = ring[-1, :] = ring[:, 0] = ring[:, -1] = True
bevel = np.zeros((cell, cell), bool) bevel = np.zeros((h, w), bool)
bevel[1, 1:-1] = bevel[-2, 1:-1] = bevel[1:-1, 1] = bevel[1:-1, -2] = True bevel[1, 1:-1] = bevel[-2, 1:-1] = bevel[1:-1, 1] = bevel[1:-1, -2] = True
inside = ~ring & ~bevel inside = ~ring & ~bevel
if lum[ring].mean() > 90 and lum[ring].mean() < 200: ring_lum = lum[ring].mean()
continue # not a button cell if 90 < ring_lum < 200:
hot = lum[ring].mean() >= 200 continue # not a button
face = np.median(c[inside][:, :3], axis=0) # the face is textured; the symbol covers less of it hot = ring_lum >= 200
band = inside.copy() # the face just inside the bevel: no symbol reaches there
band[3:-3, 3:-3] = False # inside is [2:-2]; keep only its outermost pixels
face = np.median(c[band][:, :3], axis=0)
face_lum = face.mean() face_lum = face.mean()
coloured = face.max() - face.min() > 30 coloured = face.max() - face.min() > 30
dim = face_lum < 70 and not coloured dim = face_lum < 70 and not coloured
light, dark = (BRASS[3], BRASS[0]) if hot else frame tile = tiles[1] if hot else tiles[0]
o = out[cy:cy + cell, cx:cx + cell] grain = brass_wood if hot else wood
o = out[cy:cy + h, cx:cx + w]
if hot: if hot:
o[ring, :3] = BRASS[1] o[ring, :3] = BRASS[1]
for y in range(cell): for y in range(h):
for x in range(cell): for x in range(w):
if bevel[y, x]: # the casing's metal, from the block's own edge if bevel[y, x]: # the casing's metal, from the block's own edge
tile = tiles[1] if hot else tiles[0] o[y, x, :3] = (tile[1, 3 + x % 10] if y == 1 else tile[14, 3 + x % 10] if y == h - 2
o[y, x, :3] = (tile[1, 3 + x % 10] if y == 1 else tile[14, 3 + x % 10] if y == cell - 2
else tile[3 + y % 10, 1] if x == 1 else tile[3 + y % 10, 14]) else tile[3 + y % 10, 1] if x == 1 else tile[3 + y % 10, 14])
elif inside[y, x]: elif inside[y, x]:
p = c[y, x, :3] p = c[y, x, :3]
if abs(p.mean() - face_lum) <= 28: # the face if np.abs(p - face).max() <= 28: # the face (by colour: a blue globe is as bright as grey)
if not coloured: if not coloured:
grain = (brass_wood if hot else wood)[(cy + y) % 16, (cx + x) % 16] o[y, x, :3] = grain[(cy + y) % 16, (cx + x) % 16] * (0.5 if dim else 1.0)
o[y, x, :3] = grain * (0.5 if dim else 1.0) elif p.max() - p.min() >= 24: # a coloured symbol (the globe, EMI's letters): as it is
elif p.mean() < face_lum: # the symbol's shadow continue
o[y, x, :3] = (brass_wood if hot else wood)[(cy + y) % 16, (cx + x) % 16] * 0.4 elif p.mean() < face_lum: # a symbol's shadow
elif p.max() - p.min() < 24: # a grey symbol o[y, x, :3] = grain[(cy + y) % 16, (cx + x) % 16] * 0.4
else: # a grey symbol
o[y, x, :3] = np.array(CREAM, np.float32) * (0.55 if dim else 1.0) o[y, x, :3] = np.array(CREAM, np.float32) * (0.55 if dim else 1.0)
return Image.fromarray(np.clip(out, 0, 255).astype(np.uint8), 'RGBA') return Image.fromarray(np.clip(out, 0, 255).astype(np.uint8), 'RGBA')