juegos

Juegos de terminal de Pancho: Catan (TUI, GUI, web, servidor, PicoCalc), ajedrez, calculadora y minijuegos
git clone https://git.lu3dhn.xyz/juegos.git
Log | Files | Refs

mkicon.py (1561B)


      1 #!/usr/bin/env python3
      2 """Genera los iconos de la PWA (icon-192.png, icon-512.png): un hexagono de mar con
      3 las cinco fichas de CATAN como el fondo de los menus (catan_form_backdrop).
      4     python3 web/mkicon.py            (necesita Pillow)"""
      5 import math, os, sys
      6 from PIL import Image, ImageDraw
      7 
      8 SEA, SAND = (28, 86, 150), (226, 206, 160)
      9 TERRAIN = [(190, 92, 48), (38, 122, 54), (134, 200, 84), (232, 192, 64), (142, 142, 152)]   # cerro, bosque, pasto, campo, montana (TERRAIN_COLOR)
     10 HERE = os.path.dirname(os.path.abspath(__file__))
     11 
     12 
     13 def hexagon(cx, cy, r):
     14     return [(cx + r * math.cos(math.radians(60 * k - 90)), cy + r * math.sin(math.radians(60 * k - 90))) for k in range(6)]
     15 
     16 
     17 def icon(size):
     18     s = 4                                     # se dibuja grande y se achica (antialias)
     19     im = Image.new("RGBA", (size * s, size * s), (0, 0, 0, 0))
     20     d = ImageDraw.Draw(im)
     21     W = size * s
     22     d.rounded_rectangle([0, 0, W - 1, W - 1], radius=W // 6, fill=SEA)
     23     # cinco hexagonos en dos filas, como fichas sobre el mar
     24     r = W * 0.17
     25     rows = [(2, W * 0.36), (3, W * 0.64)]
     26     i = 0
     27     for n, cy in rows:
     28         step = r * 1.85
     29         x0 = W / 2 - step * (n - 1) / 2
     30         for k in range(n):
     31             cx = x0 + k * step
     32             d.polygon(hexagon(cx, cy, r * 1.08), fill=SAND)
     33             d.polygon(hexagon(cx, cy, r * 0.92), fill=TERRAIN[i % 5])
     34             i += 1
     35     return im.resize((size, size), Image.LANCZOS)
     36 
     37 
     38 for size in (192, 512):
     39     icon(size).save(os.path.join(HERE, f"icon-{size}.png"))
     40     print(f"icon-{size}.png")