#!/usr/bin/env python3 """Generate Android launcher icons from the original "Cycle-Step" mark. Renders the same geometry as tools/gen-icon.py (gapped ring + step polyline + origin/terminal dots), full-bleed (no transparent inset) so the tile fills the icon, at every Android launcher density. Outputs: android/app/src/main/res/mipmap-*/ic_launcher.png """ import math import os from PIL import Image, ImageDraw ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) RES = os.path.join(ROOT, "android", "app", "src", "main", "res") 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 STEP = (255, 209, 102, 255) # #FFD166 ORIGIN = (255, 255, 255, 255) END = (52, 211, 153, 255) # #34D399 DENSITIES = { "mdpi": 48, "hdpi": 72, "xhdpi": 96, "xxhdpi": 144, "xxxhdpi": 192, } 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)) def draw_ring(img, cx, cy, r_ring, ring_w, gap_deg, color, s): 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; polar() already offsets -90). # The wedge must reach well past the ring so its chord clears the band, # otherwise a thin sliver of ring is left spanning the gap. cut = outer * 1.35 a0 = polar(cx, cy, cut, -gap_deg / 2) a1 = polar(cx, cy, cut, gap_deg / 2) md.polygon([(cx, cy), a0, a1], fill=0) for deg in (-gap_deg / 2, 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): 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(s): img = Image.new("RGBA", (s, s), (0, 0, 0, 0)) 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))) mask = Image.new("L", (s, s), 0) ImageDraw.Draw(mask).rounded_rectangle([0, 0, s - 1, s - 1], radius=int(0.27 * s), fill=255) img.paste(body, (0, 0), mask) ImageDraw.Draw(img).rounded_rectangle([0, 0, s - 1, s - 1], radius=int(0.27 * s), outline=EDGE, width=max(1, round(0.018 * s))) cx = cy = s / 2.0 r_ring = 0.293 * s ring_w = (0.075 if s <= 48 else 0.062) * s draw_ring(img, cx, cy, r_ring, ring_w, 68, RING, s) d = ImageDraw.Draw(img) od = 0.045 * s op = (cx, cy - r_ring) d.ellipse([op[0] - od, op[1] - od, op[0] + od, op[1] + od], fill=ORIGIN) sw = (0.075 if s <= 48 else 0.057) * s p1 = (cx - 0.146 * s, cy + 0.088 * s) p2 = (cx - 0.010 * s, cy + 0.088 * s) p3 = (cx - 0.010 * s, cy - 0.059 * s) p4 = (cx + 0.166 * s, cy - 0.059 * s) draw_steps(img, [p1, p2, p3, p4], int(sw), STEP) ed = (0.050 if s <= 48 else 0.037) * s d.ellipse([p4[0] - ed, p4[1] - ed, p4[0] + ed, p4[1] + ed], fill=END) return img def main(): for density, size in DENSITIES.items(): out_dir = os.path.join(RES, "mipmap-%s" % density) os.makedirs(out_dir, exist_ok=True) out = os.path.join(out_dir, "ic_launcher.png") build(size).save(out) print("wrote", out) if __name__ == "__main__": main()