Files
EasyDesignCollection/tools/gen-icon.py
T

161 lines
5.2 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.
Original mark, designed for this product ("Cycle-Step" / 环序):
2026-09-18 16:50:12 +08:00
1. A rounded square tile with a deep navy gradient — a neutral stage that
stays legible on both light and dark Windows taskbars.
2. A **gapped ring**: one turn = one cycle = 360 deg; the gap at the top
marks the 0 deg origin (12 o'clock).
3. A **step-function polyline**: the sequence of actions advancing in time
(a timing/step chart, which is exactly what this tool draws).
4. An **origin dot** sitting in the ring gap, plus a terminal node dot.
Everything is composed from primitive geometry (ring, polyline, circles) and
does not reproduce, trace, or approximate any existing brand mark.
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
INSET = 56 # transparent margin around the tile
TILE = S - 2 * INSET
TILE_TOP = (24, 33, 61, 255) # #18213D
TILE_BOT = (12, 18, 38, 255) # #0C1226
EDGE = (255, 255, 255, 38)
RING = (76, 201, 240, 255) # #4CC9F0 accent cyan
STEP = (255, 209, 102, 255) # #FFD166 amber
ORIGIN = (255, 255, 255, 255)
END = (52, 211, 153, 255) # #34D399
CX = CY = S // 2
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 polar(cx, cy, r, deg):
t = math.radians(deg - 90)
return (cx + r * math.cos(t), cy + r * math.sin(t))
2026-09-18 16:50:12 +08:00
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 draw_ring(img, r_ring, ring_w, gap_deg, color):
"""Draw a circular arc with a gap centred at 12 o'clock and round caps."""
outer = r_ring + ring_w / 2
inner = r_ring - ring_w / 2
mask = Image.new("L", (S, S), 0)
md = ImageDraw.Draw(mask)
md.ellipse([CX - outer, CY - outer, CX + outer, CY + outer], fill=255)
md.ellipse([CX - inner, CY - inner, CX + inner, CY + inner], fill=0)
# Cut the gap wedge (centred on the top, i.e. -90 deg).
a0 = polar(CX, CY, outer + 8, -90 - gap_deg / 2)
a1 = polar(CX, CY, outer + 8, -90 + gap_deg / 2)
md.polygon([(CX, CY), a0, a1], fill=0)
# Round caps at both arc ends.
for deg in (-90 + gap_deg / 2, -90 - gap_deg / 2):
p = polar(CX, CY, r_ring, deg)
md.ellipse([p[0] - ring_w / 2, p[1] - ring_w / 2,
p[0] + ring_w / 2, p[1] + ring_w / 2], fill=255)
img.paste(color, (0, 0), mask)
def draw_steps(img, pts, width, color):
"""Draw a step polyline with rounded joins and caps."""
d = ImageDraw.Draw(img)
d.line(pts, fill=color, width=width, joint="curve")
for p in pts:
d.ellipse([p[0] - width / 2, p[1] - width / 2,
p[0] + width / 2, p[1] + width / 2], fill=color)
def build_master(simplified=False):
2026-09-18 16:50:12 +08:00
img = Image.new("RGBA", (S, S), (0, 0, 0, 0))
# --- tile with a vertical navy gradient ---
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(TILE_TOP, TILE_BOT, y / (S - 1)))
img.paste(body, (0, 0), rounded_mask(S, int(0.27 * TILE), inset=INSET))
ImageDraw.Draw(img).rounded_rectangle(
[INSET, INSET, S - 1 - INSET, S - 1 - INSET],
radius=int(0.27 * TILE),
outline=EDGE,
width=5,
2026-09-18 16:50:12 +08:00
)
# --- mark ---
r_ring = 0.293 * TILE
ring_w = (0.085 if simplified else 0.062) * TILE
draw_ring(img, r_ring, ring_w, 68, RING)
# origin dot in the ring gap (0 deg / 12 o'clock)
d = ImageDraw.Draw(img)
od = (0.050 if simplified else 0.042) * TILE
op = (CX, CY - r_ring)
d.ellipse([op[0] - od, op[1] - od, op[0] + od, op[1] + od], fill=ORIGIN)
# step-function polyline (sequence of actions)
sw = (0.085 if simplified else 0.057) * TILE
p1 = (CX - 0.146 * TILE, CY + 0.088 * TILE)
p2 = (CX - 0.010 * TILE, CY + 0.088 * TILE)
p3 = (CX - 0.010 * TILE, CY - 0.059 * TILE)
p4 = (CX + 0.166 * TILE, CY - 0.059 * TILE)
draw_steps(img, [p1, p2, p3, p4], int(sw), STEP)
# terminal node dot
ed = (0.050 if simplified else 0.037) * TILE
d.ellipse([p4[0] - ed, p4[1] - ed, p4[0] + ed, p4[1] + ed], fill=END)
2026-09-18 16:50:12 +08:00
return img
def main():
master = build_master(False)
small = build_master(True)
2026-09-18 16:50:12 +08:00
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 = []
for s in sizes:
src = small if s <= 32 else master
frames.append(src.resize((s, s), Image.LANCZOS))
2026-09-18 16:50:12 +08:00
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()