neuronal / scripts /genera_icona.py
amogaddy's picture
amogaddyofficial
claude sonnet 4.6
Neuronal
d601f7c
Raw History Blame Contribute Delete
4.92 kB
"""Disegna l'icona di Neuronal (un neurone con le sue sinapsi e il tricolore) senza librerie esterne.
Scrive web/icona.svg, web/icona.png (256 px) e windows/neuronal.ico (256, 64, 48, 32, 16)."""
import math, os, struct, zlib
ROOT = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..")
CYAN, WHITE = (92, 225, 230), (235, 250, 255)
GREEN, RED = (0, 146, 70), (206, 43, 55)
# geometria su una tela 256x256
CENTER = (128, 112)
ARMS = [(-150, 64), (-90, 50), (-30, 66), (30, 58), (90, 66), (150, 52)] # (angolo, lunghezza)
NODES = [(CENTER[0] + l * math.cos(math.radians(a)), CENTER[1] + l * math.sin(math.radians(a))) for a, l in ARMS]
def svg():
lines = "".join(f'<line x1="{CENTER[0]}" y1="{CENTER[1]}" x2="{x:.1f}" y2="{y:.1f}"/>' for x, y in NODES)
dots = "".join(f'<circle cx="{x:.1f}" cy="{y:.1f}" r="9"/>' for x, y in NODES)
return f'''<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 256 256">
<defs><radialGradient id="bg" cx="50%" cy="42%" r="70%"><stop offset="0" stop-color="#0f2530"/><stop offset="1" stop-color="#05070b"/></radialGradient>
<radialGradient id="glow"><stop offset="0" stop-color="#ebfaff"/><stop offset=".45" stop-color="#5ce1e6"/><stop offset="1" stop-color="#5ce1e6" stop-opacity="0"/></radialGradient></defs>
<rect width="256" height="256" rx="52" fill="url(#bg)"/>
<g stroke="#5ce1e6" stroke-width="6" stroke-linecap="round" opacity=".85">{lines}</g>
<g fill="#5ce1e6">{dots}</g>
<circle cx="{CENTER[0]}" cy="{CENTER[1]}" r="46" fill="url(#glow)"/>
<circle cx="{CENTER[0]}" cy="{CENTER[1]}" r="20" fill="#ebfaff"/>
<rect x="74" y="206" width="36" height="14" rx="3" fill="#009246"/><rect x="110" y="206" width="36" height="14" fill="#f4f5f0"/><rect x="146" y="206" width="36" height="14" rx="3" fill="#ce2b37"/>
</svg>
'''
def seg_dist(px, py, ax, ay, bx, by):
dx, dy = bx - ax, by - ay
t = max(0.0, min(1.0, ((px - ax) * dx + (py - ay) * dy) / (dx * dx + dy * dy)))
return math.hypot(px - ax - t * dx, py - ay - t * dy)
def render(size):
ss = 3 # sovracampionamento per bordi morbidi
n = size * ss
k = 256 / n
img = bytearray()
for j in range(size):
row = []
for i in range(size):
acc = [0.0, 0.0, 0.0, 0.0]
for sj in range(ss):
for si in range(ss):
x, y = (i * ss + si + 0.5) * k, (j * ss + sj + 0.5) * k
# angoli arrotondati
cx, cy = min(max(x, 52), 204), min(max(y, 52), 204)
if math.hypot(x - cx, y - cy) > 52:
continue
d = math.hypot(x - 128, y - 108) / 180
c = [15 * (1 - d) + 5 * d, 37 * (1 - d) + 7 * d, 48 * (1 - d) + 11 * d]
def mix(col, a):
for q in range(3):
c[q] = c[q] * (1 - a) + col[q] * a
for nx, ny in NODES: # sinapsi
dd = seg_dist(x, y, CENTER[0], CENTER[1], nx, ny)
if dd < 4: mix(CYAN, 0.85)
for nx, ny in NODES: # neuroni vicini
if math.hypot(x - nx, y - ny) < 9: mix(CYAN, 1)
r = math.hypot(x - CENTER[0], y - CENTER[1]) # il neurone che si accende
if r < 46: mix(CYAN, 0.9 * (1 - r / 46) ** 1.5)
if r < 20: mix(WHITE, 1)
if 206 <= y < 220 and 74 <= x < 182: # tricolore
mix(GREEN if x < 110 else (244, 245, 240) if x < 146 else RED, 1)
acc[0] += c[0]; acc[1] += c[1]; acc[2] += c[2]; acc[3] += 255
m = ss * ss
row.append(bytes(int(v / m) for v in acc))
img += b"\0" + b"".join(row)
return img
def png(size):
raw = render(size)
def chunk(t, d):
return struct.pack(">I", len(d)) + t + d + struct.pack(">I", zlib.crc32(t + d) & 0xFFFFFFFF)
return b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0)) \
+ chunk(b"IDAT", zlib.compress(bytes(raw), 9)) + chunk(b"IEND", b"")
def ico(pngs):
head = struct.pack("<HHH", 0, 1, len(pngs))
off = 6 + 16 * len(pngs)
entries, data = b"", b""
for size, p in pngs:
entries += struct.pack("<BBBBHHII", size % 256, size % 256, 0, 0, 1, 32, len(p), off + len(data))
data += p
return head + entries + data
if __name__ == "__main__":
open(os.path.join(ROOT, "web", "icona.svg"), "w", encoding="utf-8").write(svg())
big = png(256)
open(os.path.join(ROOT, "web", "icona.png"), "wb").write(big)
os.makedirs(os.path.join(ROOT, "windows"), exist_ok=True)
open(os.path.join(ROOT, "windows", "neuronal.ico"), "wb").write(ico([(256, big)] + [(s, png(s)) for s in (64, 48, 32, 16)]))
print("icone scritte")