Files
2026-09-19 07:28:18 -03:00

54 lines
1.4 KiB
Python

"""Generates the PWA icons. Run: python3 tools/make_icons.py"""
import os
from PIL import Image, ImageDraw
BG = (14, 14, 17, 255)
GREY = (139, 139, 150, 255)
RED = (255, 59, 48, 255)
WHITE = (242, 242, 245, 255)
OUT_DIR = os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "icons")
SS = 4 # supersampling factor for smooth edges
def make_icon(size, content_scale):
s = size * SS
img = Image.new("RGBA", (s, s), BG)
d = ImageDraw.Draw(img)
cx = cy = s / 2
r = s * content_scale / 2
width = int(s * 0.072)
box = [cx - r, cy - r, cx + r, cy + r]
# grey arc = pause (270 deg), red arc = training (90 deg)
d.arc(box, start=-90, end=180, fill=GREY, width=width)
d.arc(box, start=180, end=270, fill=RED, width=width)
# clock hand pointing up
hand_w = int(s * 0.05)
d.line([(cx, cy), (cx, cy - r * 0.58)], fill=WHITE, width=hand_w)
dot = hand_w * 0.9
d.ellipse([cx - dot, cy - dot, cx + dot, cy + dot], fill=WHITE)
return img.resize((size, size), Image.Resampling.LANCZOS)
def main():
os.makedirs(OUT_DIR, exist_ok=True)
targets = [
("icon-192.png", 192, 0.78),
("icon-512.png", 512, 0.78),
("icon-maskable-512.png", 512, 0.60),
]
for name, size, scale in targets:
path = os.path.join(OUT_DIR, name)
make_icon(size, scale).save(path, "PNG")
print("wrote", path)
if __name__ == "__main__":
main()