Files
EasyDesignCollection/tools/gen-icon.py
T

129 lines
3.6 KiB
Python
Raw Normal View History

2026-09-18 16:50:12 +08:00
#!/usr/bin/env python3
"""Generate the Sequence Diagram Studio application icon.
A clock / cycle dial that reflects the product spirit: one turn = one cycle,
12 o'clock origin, clockwise phase progression.
Design note: the badge uses a **bright cyan→violet gradient** with a **white
clock** so the icon stays legible on both light and dark taskbars.
2026-09-18 16:50:12 +08:00
Outputs:
windows/runner/resources/app_icon.ico (multi-size, for the Windows build)
demo/app-icon.png (1024px preview)
"""
import math
import os
from PIL import Image, ImageDraw
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
OUT_ICO = os.path.join(ROOT, "windows", "runner", "resources", "app_icon.ico")
OUT_PNG = os.path.join(ROOT, "demo", "app-icon.png")
S = 1024
BG_TOP = (76, 201, 240, 255) # #4CC9F0 cyan
BG_BOT = (124, 92, 255, 255) # #7C5CFF violet
WHITE = (255, 255, 255, 255)
WHITE_SOFT = (255, 255, 255, 170)
NAVY = (11, 16, 24, 255) # #0B1018
EDGE = (255, 255, 255, 90)
2026-09-18 16:50:12 +08:00
def lerp(a, b, t):
return tuple(round(a[i] + (b[i] - a[i]) * t) for i in range(4))
def rounded_mask(size, radius, inset=0):
m = Image.new("L", (size, size), 0)
d = ImageDraw.Draw(m)
d.rounded_rectangle(
[inset, inset, size - 1 - inset, size - 1 - inset],
radius=radius,
fill=255,
)
return m
def polar(cx, cy, r, deg):
t = math.radians(deg - 90)
return (cx + r * math.cos(t), cy + r * math.sin(t))
def build_master():
img = Image.new("RGBA", (S, S), (0, 0, 0, 0))
# Bright gradient body.
2026-09-18 16:50:12 +08:00
body = Image.new("RGBA", (S, S), (0, 0, 0, 0))
bd = ImageDraw.Draw(body)
for y in range(S):
bd.line([(0, y), (S, y)], fill=lerp(BG_TOP, BG_BOT, y / (S - 1)))
mask = rounded_mask(S, 210, inset=48)
img.paste(body, (0, 0), mask)
draw = ImageDraw.Draw(img)
# Subtle inner edge to separate from the taskbar.
2026-09-18 16:50:12 +08:00
draw.rounded_rectangle(
[48, 48, S - 1 - 48, S - 1 - 48],
radius=210,
outline=EDGE,
width=5,
2026-09-18 16:50:12 +08:00
)
cx = cy = S // 2
r_ring = 300
ring_w = 40
2026-09-18 16:50:12 +08:00
# White outer ring (the cycle).
2026-09-18 16:50:12 +08:00
draw.ellipse(
[cx - r_ring - ring_w // 2, cy - r_ring - ring_w // 2,
cx + r_ring + ring_w // 2, cy + r_ring + ring_w // 2],
outline=WHITE,
width=ring_w,
2026-09-18 16:50:12 +08:00
)
# 12 tick marks; 12/3/6/9 are longer and thicker.
2026-09-18 16:50:12 +08:00
for d in range(0, 360, 30):
major = d % 90 == 0
r1 = r_ring - 96
r2 = r_ring - (52 if major else 74)
draw.line(
[polar(cx, cy, r1, d), polar(cx, cy, r2, d)],
fill=WHITE if major else WHITE_SOFT,
width=16 if major else 9,
)
# Clock hands: classic 10:10 pose, navy for contrast on white.
for r, deg, col, w in ((170, 305, NAVY, 34), (240, 55, NAVY, 26)):
2026-09-18 16:50:12 +08:00
hx, hy = polar(cx, cy, r, deg)
draw.line([(cx, cy), (hx, hy)], fill=col, width=w)
draw.ellipse([hx - w / 2, hy - w / 2, hx + w / 2, hy + w / 2], fill=col)
# Hub.
draw.ellipse([cx - 30, cy - 30, cx + 30, cy + 30], fill=NAVY)
draw.ellipse([cx - 12, cy - 12, cx + 12, cy + 12], fill=WHITE)
2026-09-18 16:50:12 +08:00
return img
def main():
master = build_master()
os.makedirs(os.path.dirname(OUT_ICO), exist_ok=True)
os.makedirs(os.path.dirname(OUT_PNG), exist_ok=True)
master.save(OUT_PNG)
sizes = [256, 128, 64, 48, 32, 24, 16]
frames = [master.resize((s, s), Image.LANCZOS) for s in sizes]
frames[0].save(
OUT_ICO,
format="ICO",
sizes=[(s, s) for s in sizes],
append_images=frames[1:],
)
print("wrote", OUT_ICO)
print("wrote", OUT_PNG)
if __name__ == "__main__":
main()