#!/usr/bin/env python3 """The app's icon, crates/ps-gui/assets/proxy-suite.ico: a shield with a check mark (the tray's shield, in the app's blue), drawn here at every size Windows asks for, antialiased, with no image library. The .ico it writes is committed; run this again only to change it. python3 -I tools/make-icon.py """ import math import pathlib import struct import zlib BLUE = (37, 99, 235) WHITE = (255, 255, 255) SIZES = [16, 20, 24, 32, 40, 48, 64, 256] SAMPLES = 4 # per axis, per pixel def cubic(p0, p1, p2, p3, steps=24): out = [] for i in range(1, steps + 1): t = i / steps u = 1 - t out.append(tuple(u**3 * a + 3 * u * u * t * b + 3 * u * t * t * c + t**3 * d for a, b, c, d in zip(p0, p1, p2, p3))) return out # Lucide's shield, on its 24-unit grid, as a polygon. SHIELD = [(12.0, 2.2)] SHIELD += cubic((12.0, 2.2), (14.6, 4.4), (17.2, 5.1), (19.8, 5.1)) SHIELD += [(19.8, 13.0)] SHIELD += cubic((19.8, 13.0), (19.8, 18.2), (16.4, 20.6), (12.0, 22.0)) SHIELD += cubic((12.0, 22.0), (7.6, 20.6), (4.2, 18.2), (4.2, 13.0)) SHIELD += [(4.2, 5.1)] SHIELD += cubic((4.2, 5.1), (6.8, 5.1), (9.4, 4.4), (12.0, 2.2)) CHECK = [(8.3, 12.3), (11.0, 15.0), (15.9, 9.6)] CHECK_HALF_WIDTH = 1.15 def inside(poly, x, y): hit = False for (x1, y1), (x2, y2) in zip(poly, poly[1:] + poly[:1]): if (y1 > y) != (y2 > y) and x < x1 + (y - y1) * (x2 - x1) / (y2 - y1): hit = not hit return hit def near_check(x, y): for (x1, y1), (x2, y2) in zip(CHECK, CHECK[1:]): dx, dy = x2 - x1, y2 - y1 t = max(0.0, min(1.0, ((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy))) if math.hypot(x - (x1 + t * dx), y - (y1 + t * dy)) <= CHECK_HALF_WIDTH: return True return False def render(size): """RGBA rows, top first.""" rows = [] scale = 24 / size for py in range(size): row = bytearray() for px in range(size): shield = check = 0 for sy in range(SAMPLES): for sx in range(SAMPLES): x = (px + (sx + 0.5) / SAMPLES) * scale y = (py + (sy + 0.5) / SAMPLES) * scale if inside(SHIELD, x, y): shield += 1 check += near_check(x, y) n = SAMPLES * SAMPLES alpha = shield / n if shield: w = check / shield colour = [round(b * (1 - w) + f * w) for b, f in zip(BLUE, WHITE)] else: colour = [0, 0, 0] row += bytes(colour + [round(alpha * 255)]) rows.append(bytes(row)) return rows def png(size, rows): def chunk(kind, data): return struct.pack(">I", len(data)) + kind + data + struct.pack(">I", zlib.crc32(kind + data)) raw = b"".join(b"\x00" + r for r in rows) ihdr = struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0) return b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", ihdr) + chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b"") def main(): images = [png(s, render(s)) for s in SIZES] header = struct.pack("