Il palio nella cornice dorata disegnata da Codex (tools/incornicia.py); tools/griglia.py per le coordinate delle scene

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01ApqNBvNbNCwXqR2RLo8QJh
This commit is contained in:
2026-10-24 22:46:18 +02:00
co-authored by Claude Opus 5.5
parent 39c17a1d0c
commit 9cb026074b
3 changed files with 59 additions and 7 deletions
+17
View File
@@ -0,0 +1,17 @@
"""Uno sfondo del gioco ingrandito due volte con sopra la griglia delle coordinate di scena (640x360): serve per
piazzare hotspot, candele ed effetti nel punto giusto.
python3 tools/griglia.py assets/scenes/scuola.png /tmp/griglia-scuola.png"""
import sys
from PIL import Image, ImageDraw
src, out = sys.argv[1], sys.argv[2]
im = Image.open(src).convert('RGB').resize((1280, 720), Image.NEAREST)
d = ImageDraw.Draw(im, 'RGBA')
for x in range(0, 640, 20):
d.line([(x * 2, 0), (x * 2, 720)], fill=(255, 0, 255, 140 if x % 100 == 0 else 50))
for y in range(0, 360, 20):
d.line([(0, y * 2), (1280, y * 2)], fill=(255, 0, 255, 140 if y % 100 == 0 else 50))
for x in range(0, 640, 100):
for y in range(0, 360, 100):
d.text((x * 2 + 3, y * 2 + 2), f'{x},{y}', fill=(255, 255, 0, 255))
im.save(out)
+37
View File
@@ -0,0 +1,37 @@
"""Mette un quadro dentro una cornice disegnata col centro e il fuori in magenta pieno (#ff00ff): il magenta diventa
trasparente e il quadro riempie l'apertura senza deformarsi (si taglia quel che avanza). Così la tela resta
identica, e la cornice si può rifare a parte (prompt in prompts/personaggi/cornice-palio.txt).
python3 tools/incornicia.py assets/generated/cornice-palio.png assets/generated/palio-quadro.png assets/generated/palio-incorniciato.png"""
import sys
from PIL import Image
cornice, quadro, out = sys.argv[1:4]
f = Image.open(cornice).convert('RGBA')
W, H = f.size
px = f.load()
def magenta(p):
return p[0] > 200 and p[1] < 80 and p[2] > 200
# L'apertura: dal centro si va nei quattro versi finché c'è magenta.
cx, cy = W // 2, H // 2
l, r, t, b = cx, cx, cy, cy
while l > 0 and magenta(px[l - 1, cy]): l -= 1
while r < W - 1 and magenta(px[r + 1, cy]): r += 1
while t > 0 and magenta(px[cx, t - 1]): t -= 1
while b < H - 1 and magenta(px[cx, b + 1]): b += 1
for y in range(H):
for x in range(W):
if magenta(px[x, y]): px[x, y] = (0, 0, 0, 0)
p = Image.open(quadro).convert('RGBA')
ow, oh = r - l + 3, b - t + 3
k = max(ow / p.width, oh / p.height)
p = p.resize((round(p.width * k), round(p.height * k)), Image.LANCZOS)
x0, y0 = (p.width - ow) // 2, (p.height - oh) // 2
p = p.crop((x0, y0, x0 + ow, y0 + oh))
res = Image.new('RGBA', (W, H), (0, 0, 0, 0))
res.paste(p, (l - 1, t - 1))
res.alpha_composite(f)
res.crop(res.getbbox()).save(out)