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:
co-authored by
Claude Opus 5.5
parent
6d3a4b03b1
commit
5203335655
Binary file not shown.
|
Before Width: | Height: | Size: 8.6 KiB After Width: | Height: | Size: 9.0 KiB |
+57
-43
@@ -474,51 +474,65 @@ 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((h, w), bool)
|
||||||
ring = np.zeros((cell, cell), bool)
|
ring[0, :] = ring[-1, :] = ring[:, 0] = ring[:, -1] = True
|
||||||
ring[0, :] = ring[-1, :] = ring[:, 0] = ring[:, -1] = True
|
bevel = np.zeros((h, w), bool)
|
||||||
bevel = np.zeros((cell, cell), 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
|
ring_lum = lum[ring].mean()
|
||||||
if lum[ring].mean() > 90 and lum[ring].mean() < 200:
|
if 90 < ring_lum < 200:
|
||||||
continue # not a button cell
|
continue # not a button
|
||||||
hot = lum[ring].mean() >= 200
|
hot = ring_lum >= 200
|
||||||
face = np.median(c[inside][:, :3], axis=0) # the face is textured; the symbol covers less of it
|
band = inside.copy() # the face just inside the bevel: no symbol reaches there
|
||||||
face_lum = face.mean()
|
band[3:-3, 3:-3] = False # inside is [2:-2]; keep only its outermost pixels
|
||||||
coloured = face.max() - face.min() > 30
|
face = np.median(c[band][:, :3], axis=0)
|
||||||
dim = face_lum < 70 and not coloured
|
face_lum = face.mean()
|
||||||
light, dark = (BRASS[3], BRASS[0]) if hot else frame
|
coloured = face.max() - face.min() > 30
|
||||||
o = out[cy:cy + cell, cx:cx + cell]
|
dim = face_lum < 70 and not coloured
|
||||||
if hot:
|
tile = tiles[1] if hot else tiles[0]
|
||||||
o[ring, :3] = BRASS[1]
|
grain = brass_wood if hot else wood
|
||||||
for y in range(cell):
|
o = out[cy:cy + h, cx:cx + w]
|
||||||
for x in range(cell):
|
if hot:
|
||||||
if bevel[y, x]: # the casing's metal, from the block's own edge
|
o[ring, :3] = BRASS[1]
|
||||||
tile = tiles[1] if hot else tiles[0]
|
for y in range(h):
|
||||||
o[y, x, :3] = (tile[1, 3 + x % 10] if y == 1 else tile[14, 3 + x % 10] if y == cell - 2
|
for x in range(w):
|
||||||
else tile[3 + y % 10, 1] if x == 1 else tile[3 + y % 10, 14])
|
if bevel[y, x]: # the casing's metal, from the block's own edge
|
||||||
elif inside[y, x]:
|
o[y, x, :3] = (tile[1, 3 + x % 10] if y == 1 else tile[14, 3 + x % 10] if y == h - 2
|
||||||
p = c[y, x, :3]
|
else tile[3 + y % 10, 1] if x == 1 else tile[3 + y % 10, 14])
|
||||||
if abs(p.mean() - face_lum) <= 28: # the face
|
elif inside[y, x]:
|
||||||
if not coloured:
|
p = c[y, x, :3]
|
||||||
grain = (brass_wood if hot else wood)[(cy + y) % 16, (cx + x) % 16]
|
if np.abs(p - face).max() <= 28: # the face (by colour: a blue globe is as bright as grey)
|
||||||
o[y, x, :3] = grain * (0.5 if dim else 1.0)
|
if not coloured:
|
||||||
elif p.mean() < face_lum: # the symbol's shadow
|
o[y, x, :3] = grain[(cy + y) % 16, (cx + x) % 16] * (0.5 if dim else 1.0)
|
||||||
o[y, x, :3] = (brass_wood if hot else wood)[(cy + y) % 16, (cx + x) % 16] * 0.4
|
elif p.max() - p.min() >= 24: # a coloured symbol (the globe, EMI's letters): as it is
|
||||||
elif p.max() - p.min() < 24: # a grey symbol
|
continue
|
||||||
o[y, x, :3] = np.array(CREAM, np.float32) * (0.55 if dim else 1.0)
|
elif p.mean() < face_lum: # a symbol's shadow
|
||||||
|
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)
|
||||||
return Image.fromarray(np.clip(out, 0, 255).astype(np.uint8), 'RGBA')
|
return Image.fromarray(np.clip(out, 0, 255).astype(np.uint8), 'RGBA')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user