81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
#!/usr/bin/env python3
|
|
"""Genera le icone di harbour-aira (86/108/128/172 px) in icons/<size>/.
|
|
|
|
Disegno scelto: **casa con l'onda calda dentro** — la proposta A di
|
|
scripts/icon_proposals.py, dove restano le altre direzioni provate. E' un
|
|
disegno originale: nessun logo di terzi, visto che il permesso per nome e logo
|
|
Aira non e' ancora arrivato.
|
|
|
|
Uso: python3 scripts/make_icons.py
|
|
"""
|
|
import math
|
|
import pathlib
|
|
|
|
from PIL import Image, ImageDraw
|
|
|
|
SIZES = [86, 108, 128, 172]
|
|
BASE = 344 # si disegna grande e si ridimensiona: bordi puliti a ogni taglia
|
|
|
|
TOP = (12, 62, 130) # blu profondo
|
|
BOTTOM = (24, 148, 190) # azzurro
|
|
WARM = (255, 138, 46) # arancione
|
|
WHITE = (255, 255, 255, 240)
|
|
|
|
|
|
def rounded_mask(size, radius):
|
|
m = Image.new("L", (size, size), 0)
|
|
ImageDraw.Draw(m).rounded_rectangle([0, 0, size - 1, size - 1], radius=radius, fill=255)
|
|
return m
|
|
|
|
|
|
def gradient(size):
|
|
img = Image.new("RGB", (1, size))
|
|
d = ImageDraw.Draw(img)
|
|
for y in range(size):
|
|
t = y / max(1, size - 1)
|
|
d.point((0, y), tuple(int(TOP[i] + (BOTTOM[i] - TOP[i]) * t) for i in range(3)))
|
|
return img.resize((size, size))
|
|
|
|
|
|
def onda(d, x0, x1, y, ampiezza, spessore, fill, creste=2):
|
|
"""L'onda calda: due creste dentro il corpo della casa."""
|
|
punti = []
|
|
passi = 120
|
|
for i in range(passi + 1):
|
|
t = i / passi
|
|
x = x0 + (x1 - x0) * t
|
|
punti.append((x, y + ampiezza * math.sin(2 * math.pi * creste * t)))
|
|
d.line(punti, fill=fill, width=int(spessore), joint="curve")
|
|
|
|
|
|
def draw_icon(size):
|
|
img = gradient(size).convert("RGBA")
|
|
d = ImageDraw.Draw(img)
|
|
|
|
# tetto e corpo della casa
|
|
d.polygon([(size * 0.16, size * 0.50), (size * 0.50, size * 0.24),
|
|
(size * 0.84, size * 0.50)], fill=WHITE)
|
|
d.rectangle([size * 0.24, size * 0.50, size * 0.76, size * 0.78], fill=WHITE)
|
|
|
|
# onda calda dentro il corpo: sta sotto il tetto, altrimenti a 86 px si fonde
|
|
onda(d, size * 0.26, size * 0.74, size * 0.665, size * 0.040, size * 0.078,
|
|
WARM + (255,), creste=2)
|
|
return img
|
|
|
|
|
|
def main():
|
|
master = draw_icon(BASE)
|
|
master.putalpha(rounded_mask(BASE, int(BASE * 0.22)))
|
|
|
|
for s in SIZES:
|
|
out = master.resize((s, s), Image.LANCZOS)
|
|
outdir = pathlib.Path(f"icons/{s}x{s}")
|
|
outdir.mkdir(parents=True, exist_ok=True)
|
|
path = outdir / "harbour-aira.png"
|
|
out.save(path)
|
|
print("scritto", path)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|