"""Run from a venv with resvg-py and pillow: python make-icon.py OUTDIR Stemify app icon: six stem-colored capsules (the app's stem palette) glowing on a deep night background. Usage: make.py OUTDIR -> icon.png, icon-dev.png, icon-dev-dark.png, icon-dev-tinted.png""" import io, sys import resvg_py from PIL import Image S = 1024 # vocals, drums, bass, guitar, piano, other (PlaybackManager stem colors) STEMS = [0xFF7AB6, 0xFFB547, 0x7C8CFF, 0xFF8A5C, 0xB48CFF, 0x4CD07D] HEIGHTS = [300, 510, 390, 620, 455, 330] W, GAP = 78, 30 def hx(c): return f"#{c:06X}" def mix(c, t, k): a = [(c >> s) & 255 for s in (16, 8, 0)]; b = [(t >> s) & 255 for s in (16, 8, 0)] return "#" + "".join(f"{round(x + (y - x) * k):02X}" for x, y in zip(a, b)) def svg(mode="color", sash=False): tint = mode == "tinted" total = len(STEMS) * W + (len(STEMS) - 1) * GAP x0 = (S - total) / 2 cy = S / 2 + 6 defs, glow, bars, shine = [], [], [], [] for i, (c, h) in enumerate(zip(STEMS, HEIGHTS)): if tint: c = 0xFFFFFF x, y = x0 + i * (W + GAP), cy - h / 2 defs.append(f'' f'' f'' f'') r = W / 2 glow.append(f'') bars.append(f'') # glassy highlight down the left edge shine.append(f'') if tint: bg = '' aura = "" else: bg = ('' '' '' '') # soft colored light pooling behind the bars aura = ('' f'' f'' f'' f'' f'' '') vignette = ('' '' '') if not tint else "" sash_svg = "" if sash: sash_svg = ('' '' '' '' '' '' 'dev' 'dev' '') return f''' {"".join(defs)} {bg}{aura} {"".join(glow)} {"".join(g.replace('fill="#', 'fill="#000" data-c="') for g in glow)} {"".join(bars)} {"".join(shine)} {vignette}{sash_svg} ''' def png(s, path, gray=False): im = Image.open(io.BytesIO(bytes(resvg_py.svg_to_bytes(svg_string=s)))).convert("RGB") (im.convert("L") if gray else im).save(path, optimize=True) out = sys.argv[1] png(svg(), f"{out}/icon.png") png(svg(sash=True), f"{out}/icon-dev.png") png(svg(sash=True), f"{out}/icon-dev-dark.png") png(svg("tinted", sash=True), f"{out}/icon-dev-tinted.png", gray=True) open(f"{out}/icon.svg", "w").write(svg())