143 lines
3.8 KiB
Python
143 lines
3.8 KiB
Python
|
|
#!/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.
|
||
|
|
|
||
|
|
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 = (14, 21, 32, 255)
|
||
|
|
BG_BOT = (11, 16, 24, 255)
|
||
|
|
LINE = (31, 44, 64, 255)
|
||
|
|
ACCENT = (76, 201, 240, 255)
|
||
|
|
ACCENT2 = (124, 92, 255, 255)
|
||
|
|
OK = (52, 211, 153, 255)
|
||
|
|
DIAL = (12, 19, 32, 255)
|
||
|
|
TICK = (42, 58, 82, 255)
|
||
|
|
TEXT = (232, 238, 252, 255)
|
||
|
|
|
||
|
|
|
||
|
|
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 arc(draw, cx, cy, r, a0, a1, color, width):
|
||
|
|
draw.arc(
|
||
|
|
[cx - r, cy - r, cx + r, cy + r],
|
||
|
|
start=a0 - 90,
|
||
|
|
end=a1 - 90,
|
||
|
|
fill=color,
|
||
|
|
width=width,
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
def build_master():
|
||
|
|
img = Image.new("RGBA", (S, S), (0, 0, 0, 0))
|
||
|
|
draw = ImageDraw.Draw(img)
|
||
|
|
|
||
|
|
# Rounded-square body with a vertical gradient.
|
||
|
|
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)
|
||
|
|
|
||
|
|
# Inner border ring.
|
||
|
|
draw.rounded_rectangle(
|
||
|
|
[48, 48, S - 1 - 48, S - 1 - 48],
|
||
|
|
radius=210,
|
||
|
|
outline=LINE,
|
||
|
|
width=6,
|
||
|
|
)
|
||
|
|
|
||
|
|
cx = cy = S // 2
|
||
|
|
r_ring = 320
|
||
|
|
ring_w = 46
|
||
|
|
|
||
|
|
# Dial disc.
|
||
|
|
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],
|
||
|
|
fill=DIAL,
|
||
|
|
outline=LINE,
|
||
|
|
width=4,
|
||
|
|
)
|
||
|
|
|
||
|
|
# 12 / 3 / 6 / 9 major ticks.
|
||
|
|
for d in range(0, 360, 30):
|
||
|
|
major = d % 90 == 0
|
||
|
|
r1 = r_ring - 96
|
||
|
|
r2 = r_ring - (52 if major else 74)
|
||
|
|
col = ACCENT if major else TICK
|
||
|
|
w = 14 if major else 9
|
||
|
|
draw.line([polar(cx, cy, r1, d), polar(cx, cy, r2, d)], fill=col, width=w)
|
||
|
|
|
||
|
|
# Phase arcs on the outer ring: two "actions" of the cycle.
|
||
|
|
arc(draw, cx, cy, r_ring, 0, 70, ACCENT, ring_w)
|
||
|
|
arc(draw, cx, cy, r_ring, 105, 190, ACCENT2, ring_w)
|
||
|
|
arc(draw, cx, cy, r_ring, 300, 360, OK, ring_w)
|
||
|
|
|
||
|
|
# Clock hands: classic 10:10 pose.
|
||
|
|
for r, deg, col, w in ((168, 305, TEXT, 34), (238, 55, ACCENT, 26)):
|
||
|
|
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=TEXT)
|
||
|
|
draw.ellipse([cx - 13, cy - 13, cx + 13, cy + 13], fill=DIAL)
|
||
|
|
|
||
|
|
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()
|