#!/usr/bin/env python3 """Generate Getǣl's Astrolabe app and tray/menubar icons with zero dependencies. Draws Getǣl's Astrolabe mark (matching `AstrolabeMark` in `web/src/components/Bezel.tsx`) using analytical signed-distance-field anti-aliasing and writes: - icons/icon.svg - icons/32x32.png - icons/128x128.png - icons/128x128@2x.png (256x256) - icons/icon.png (512x512) - icons/icon.ico (16, 32, 48, 256 PNG-in-ICO) - icons/icon.icns (macOS, via `iconutil`) - icons/tray-template.png (44x44 monochrome black+alpha template for macOS menubar) - icons/tray-color.png (44x44 colored Astrolabe for Windows/Linux system trays) Run from the repository root: python3 scripts/make_icons.py """ from __future__ import annotations import math import os import shutil import struct import subprocess import sys import zlib # DESIGN.md palette BG = (10, 11, 13) # #0A0B0D obsidian ground BEZEL = (36, 41, 51) # #242933 subtle bezel border FG = (236, 238, 242) # #ECEEF2 instrument ivory AMBER = (229, 154, 43) # #E59A2B Kaprekar amber BLACK = (0, 0, 0) ICON_SVG = """ """ def clamp(v: float, lo: float = 0.0, hi: float = 1.0) -> float: return lo if v < lo else hi if v > hi else v def sdf_rounded_rect(x: float, y: float, x0: float, y0: float, x1: float, y1: float, r: float) -> float: cx = (x0 + x1) * 0.5 cy = (y0 + y1) * 0.5 hx = (x1 - x0) * 0.5 - r hy = (y1 - y0) * 0.5 - r qx = abs(x - cx) - hx qy = abs(y - cy) - hy return math.hypot(max(qx, 0.0), max(qy, 0.0)) + min(max(qx, qy), 0.0) - r def sdf_segment(x: float, y: float, ax: float, ay: float, bx: float, by: float) -> float: dx = bx - ax dy = by - ay denom = dx * dx + dy * dy t = clamp(((x - ax) * dx + (y - ay) * dy) / denom) if denom > 0.0 else 0.0 return math.hypot(x - (ax + t * dx), y - (ay + t * dy)) def over( dst_r: float, dst_g: float, dst_b: float, dst_a: float, src_rgb: tuple[int, int, int], src_a: float, ) -> tuple[float, float, float, float]: if src_a <= 0.0: return dst_r, dst_g, dst_b, dst_a out_a = src_a + dst_a * (1.0 - src_a) if out_a <= 0.0: return 0.0, 0.0, 0.0, 0.0 inv = (1.0 - src_a) * dst_a out_r = (src_rgb[0] * src_a + dst_r * inv) / out_a out_g = (src_rgb[1] * src_a + dst_g * inv) / out_a out_b = (src_rgb[2] * src_a + dst_b * inv) / out_a return out_r, out_g, out_b, out_a def draw_app_icon(size: int) -> bytes: """Render the full Astrolabe app icon on a rounded obsidian tile.""" # Coordinate space: 64x64 tile, with the 24x24 Astrolabe centered in [8..56]. scale = 64.0 / size aa = scale * 1.15 # Astrolabe coordinates mapped from 24x24 -> 64x64 via (v * 2 + 8) stroke_half = 1.5 # 1.5 in 24px space * 2 / 2 = 1.5 in 64px space center = 32.0 outer_r = 19.0 inner_r = 11.0 dot_r = 3.2 ticks = ( (32.0, 13.0, 32.0, 19.0), (32.0, 45.0, 32.0, 51.0), (13.0, 32.0, 19.0, 32.0), (45.0, 32.0, 51.0, 32.0), ) needle = (39.6, 24.4, 34.8, 29.2) rows: list[bytes] = [] for py in range(size): row = bytearray([0]) # PNG filter byte = None y = (py + 0.5) * scale for px in range(size): x = (px + 0.5) * scale r = g = b = a = 0.0 # Rounded obsidian background tile d_tile = sdf_rounded_rect(x, y, 2.0, 2.0, 62.0, 62.0, 14.0) tile_cov = clamp(0.5 - d_tile / aa) if tile_cov > 0.0: r, g, b, a = over(r, g, b, a, BG, tile_cov) # Subtle bezel stroke along the tile rim d_rim = abs(d_tile + 0.75) - 0.75 rim_cov = clamp(0.5 - d_rim / aa) if rim_cov > 0.0: r, g, b, a = over(r, g, b, a, BEZEL, rim_cov * 0.9) dist_c = math.hypot(x - center, y - center) # Outer ring (85% opacity) cov = clamp(0.5 - (abs(dist_c - outer_r) - stroke_half) / aa) if cov > 0.0: r, g, b, a = over(r, g, b, a, FG, cov * 0.85) # Inner ring (50% opacity) cov = clamp(0.5 - (abs(dist_c - inner_r) - stroke_half) / aa) if cov > 0.0: r, g, b, a = over(r, g, b, a, FG, cov * 0.50) # Cardinal ticks (60% opacity) d_tick = min(sdf_segment(x, y, ax, ay, bx, by) for ax, ay, bx, by in ticks) cov = clamp(0.5 - (d_tick - stroke_half) / aa) if cov > 0.0: r, g, b, a = over(r, g, b, a, FG, cov * 0.60) # Amber needle d_needle = sdf_segment(x, y, *needle) cov = clamp(0.5 - (d_needle - stroke_half) / aa) if cov > 0.0: r, g, b, a = over(r, g, b, a, AMBER, cov) # Amber center dot cov = clamp(0.5 - (dist_c - dot_r) / aa) if cov > 0.0: r, g, b, a = over(r, g, b, a, AMBER, cov) row.append(int(round(r))) row.append(int(round(g))) row.append(int(round(b))) row.append(int(round(a * 255.0))) rows.append(bytes(row)) return b"".join(rows) def draw_tray_icon(size: int, template: bool) -> bytes: """Render the transparent-background Astrolabe icon for menubar / system tray. When `template=True`, draws in black + alpha only so macOS tints the menubar icon automatically for light and dark menu bars. """ scale = 24.0 / size aa = scale * 1.15 stroke_half = 0.95 # Slightly bolder than 0.75 so it stays crisp at 22pt center = 12.0 outer_r = 9.3 inner_r = 5.4 dot_r = 1.75 ticks = ( (12.0, 2.7, 12.0, 5.6), (12.0, 18.4, 12.0, 21.3), (2.7, 12.0, 5.6, 12.0), (18.4, 12.0, 21.3, 12.0), ) needle = (15.8, 8.2, 13.4, 10.6) ring_rgb = BLACK if template else FG accent_rgb = BLACK if template else AMBER rows: list[bytes] = [] for py in range(size): row = bytearray([0]) y = (py + 0.5) * scale for px in range(size): x = (px + 0.5) * scale r = g = b = a = 0.0 dist_c = math.hypot(x - center, y - center) cov = clamp(0.5 - (abs(dist_c - outer_r) - stroke_half) / aa) if cov > 0.0: r, g, b, a = over(r, g, b, a, ring_rgb, cov * (0.95 if template else 0.90)) cov = clamp(0.5 - (abs(dist_c - inner_r) - stroke_half * 0.85) / aa) if cov > 0.0: r, g, b, a = over(r, g, b, a, ring_rgb, cov * (0.55 if template else 0.60)) d_tick = min(sdf_segment(x, y, ax, ay, bx, by) for ax, ay, bx, by in ticks) cov = clamp(0.5 - (d_tick - stroke_half * 0.85) / aa) if cov > 0.0: r, g, b, a = over(r, g, b, a, ring_rgb, cov * (0.75 if template else 0.70)) d_needle = sdf_segment(x, y, *needle) cov = clamp(0.5 - (d_needle - stroke_half) / aa) if cov > 0.0: r, g, b, a = over(r, g, b, a, accent_rgb, cov) cov = clamp(0.5 - (dist_c - dot_r) / aa) if cov > 0.0: r, g, b, a = over(r, g, b, a, accent_rgb, cov) row.append(int(round(r))) row.append(int(round(g))) row.append(int(round(b))) row.append(int(round(a * 255.0))) rows.append(bytes(row)) return b"".join(rows) def png_chunk(kind: bytes, data: bytes) -> bytes: body = kind + data return struct.pack(">I", len(data)) + body + struct.pack(">I", zlib.crc32(body) & 0xFFFFFFFF) def encode_png(size: int, raw_scanlines: bytes) -> bytes: ihdr = struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0) return ( b"\x89PNG\r\n\x1a\n" + png_chunk(b"IHDR", ihdr) + png_chunk(b"IDAT", zlib.compress(raw_scanlines, 9)) + png_chunk(b"IEND", b"") ) def encode_ico(images: list[tuple[int, bytes]]) -> bytes: """ICO container holding PNG-compressed images: [(size, png_bytes)].""" out = struct.pack("= 256 else size out += struct.pack(" None: os.makedirs("icons", exist_ok=True) cache: dict[int, bytes] = {} def app_png(size: int) -> bytes: if size not in cache: cache[size] = encode_png(size, draw_app_icon(size)) return cache[size] with open("icons/icon.svg", "w", encoding="utf-8") as f: f.write(ICON_SVG) for name, size in [ ("32x32.png", 32), ("128x128.png", 128), ("128x128@2x.png", 256), ("icon.png", 512), ]: with open(os.path.join("icons", name), "wb") as f: f.write(app_png(size)) with open("icons/icon.ico", "wb") as f: f.write(encode_ico([(s, app_png(s)) for s in (16, 32, 48, 256)])) # Menubar / system tray icons (44x44 = 22pt @2x) with open("icons/tray-template.png", "wb") as f: f.write(encode_png(44, draw_tray_icon(44, template=True))) with open("icons/tray-color.png", "wb") as f: f.write(encode_png(44, draw_tray_icon(44, template=False))) if sys.platform == "darwin" and shutil.which("iconutil"): iconset = "icons/icon.iconset" if os.path.exists(iconset): shutil.rmtree(iconset) os.makedirs(iconset, exist_ok=True) for pts in (16, 32, 128, 256, 512): for scale in (1, 2): suffix = "" if scale == 1 else "@2x" with open(f"{iconset}/icon_{pts}x{pts}{suffix}.png", "wb") as f: f.write(app_png(pts * scale)) subprocess.run( ["iconutil", "-c", "icns", iconset, "-o", "icons/icon.icns"], check=True, ) shutil.rmtree(iconset) if __name__ == "__main__": main()