#!/usr/bin/env python3 """Generates the rustscreen icon as a PNG, with no graphics dependency. An AppImage icon must exist before packaging, and the build machine has neither ImageMagick nor rsvg. Drawing the image here, in pure Python, avoids adding a system tool to the pipeline for a 256x256 file. ./scripts/make-icon.py assets/rustscreen-256.png """ import math import struct import sys import zlib SIZE = 256 BACKGROUND = (14, 17, 22) SCREEN = (79, 156, 249) WAVE = (63, 185, 80) def blend(a, b, t): return tuple(round(x + (y - x) * t) for x, y in zip(a, b)) def in_rounded_rect(x, y, x0, y0, x1, y1, radius): if not (x0 <= x <= x1 and y0 <= y <= y1): return False # The four corners are the only places where the radius matters. for cx, cy in ((x0 + radius, y0 + radius), (x1 - radius, y0 + radius), (x0 + radius, y1 - radius), (x1 - radius, y1 - radius)): if (x < x0 + radius or x > x1 - radius) and (y < y0 + radius or y > y1 - radius): if math.hypot(x - cx, y - cy) > radius: return False return True def arc(x, y, cx, cy, radius, thickness, angle_min, angle_max): d = math.hypot(x - cx, y - cy) if abs(d - radius) > thickness / 2: return False angle = math.degrees(math.atan2(y - cy, x - cx)) return angle_min <= angle <= angle_max def draw(): """Renders the image row by row: rounded background, screen, broadcast waves.""" pixels = [] for y in range(SIZE): row = [] for x in range(SIZE): if not in_rounded_rect(x, y, 2, 2, SIZE - 3, SIZE - 3, 44): row.append((0, 0, 0, 0)) continue color = BACKGROUND # Screen: light frame, dark inside, like a shared window. if in_rounded_rect(x, y, 44, 58, 168, 158, 10): inside = in_rounded_rect(x, y, 52, 66, 160, 150, 6) color = BACKGROUND if inside else SCREEN if inside and y < 96: # A lighter band at the top of the screen, to suggest an # image rather than an empty rectangle. color = blend(SCREEN, BACKGROUND, 0.55) # Screen stand. if in_rounded_rect(x, y, 96, 158, 116, 178, 3): color = SCREEN if in_rounded_rect(x, y, 74, 178, 138, 190, 5): color = SCREEN # Broadcast waves, to the right of the screen. for radius in (20, 34): if arc(x, y, 168, 108, radius, 7, -62, 62): color = WAVE row.append((*color, 255)) pixels.append(row) return pixels def write_png(path, pixels): raw = bytearray() for row in pixels: raw.append(0) # filter 0: none for r, g, b, a in row: raw += bytes((r, g, b, a)) def chunk(name, data): content = name + data return ( struct.pack(">I", len(data)) + content + struct.pack(">I", zlib.crc32(content) & 0xFFFFFFFF) ) header = struct.pack(">IIBBBBB", SIZE, SIZE, 8, 6, 0, 0, 0) png = ( b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", header) + chunk(b"IDAT", zlib.compress(bytes(raw), 9)) + chunk(b"IEND", b"") ) with open(path, "wb") as f: f.write(png) if __name__ == "__main__": output = sys.argv[1] if len(sys.argv) > 1 else "assets/rustscreen-256.png" write_png(output, draw()) print(f"icon written: {output}")