SPB Git

Repository Public License

make-icon.py 15.5 KB 399 lines python

1#!/usr/bin/env python32# ORIX Audio3# File: Scripts/make-icon.py4# Description: Generates the five ORIX Audio icon concepts as vector SVG, the contact sheet,5#              the production app-icon set (default / dark / tinted) and the repository brand assets.6#7# Author: Simon-Pierre Boucher8# Contact: contact@spboucher.ai9#10# Usage:  python3 Scripts/make-icon.py            (from the repository root; needs rsvg-convert + Pillow)11#         python3 Scripts/make-icon.py --winner 1 (choose which concept becomes the production icon)12"""All geometry is defined on a 1024 x 1024 canvas, centre (512, 512)."""1314import argparse15import json16import math17import subprocess18import sys19from pathlib import Path2021from PIL import Image, ImageDraw, ImageFont2223ROOT = Path(__file__).resolve().parent.parent24BUILD = ROOT / "build" / "icon"25ASSETS = ROOT / "ORIXAudio" / "Resources" / "Assets.xcassets"26DOCS = ROOT / "docs" / "assets"2728# ---- ORIX palette -----------------------------------------------------------------------------29INK_DEEP, INK, SURFACE, HAIRLINE, TEXT = "#07080D", "#0B0D14", "#12141D", "#232735", "#F4F6FB"30BANDS = ["#7C3AED", "#3B82F6", "#06B6D4", "#22C55E", "#EAB308", "#F97316", "#F43F5E"]  # low -> high31BAND_NAMES = ["Sub-bass", "Bass", "Low-mid", "Mid", "Upper-mid", "Presence", "Brilliance"]32CYAN, VIOLET = "#22D3EE", "#8B5CF6"3334CONCEPTS = {35    1: "Spectral O",36    2: "Wave Monogram",37    3: "Frequency Symbol",38    4: "Audio Aperture",39    5: "Spectral Ribbon",40}414243def _rgb(hexcolor):44    h = hexcolor.lstrip("#")45    return tuple(int(h[i:i + 2], 16) for i in (0, 2, 4))464748def _gray(hexcolor):49    """Tinted appearance: luminance mapped into a bright gray range so every element keeps its shape."""50    r, g, b = _rgb(hexcolor)51    lum = (0.2126 * r + 0.7152 * g + 0.0722 * b) / 255.052    v = int(round(255 * (0.62 + 0.38 * lum)))53    return f"#{v:02X}{v:02X}{v:02X}"545556class Ctx:57    """mode: 'default' (opaque ink background), 'dark' (transparent background), 'tinted' (grayscale on58    black), 'mark' (transparent, no background, for in-app / logo use)."""5960    def __init__(self, mode="default"):61        self.mode = mode6263    def c(self, hexcolor):64        return _gray(hexcolor) if self.mode == "tinted" else hexcolor6566    def background(self):67        if self.mode in ("dark", "mark"):68            return ""69        if self.mode == "tinted":70            return '<rect width="1024" height="1024" fill="#000000"/>'71        return (72            '<defs><radialGradient id="bg" cx="50%" cy="42%" r="75%">'73            f'<stop offset="0" stop-color="{SURFACE}"/><stop offset="0.55" stop-color="{INK}"/>'74            f'<stop offset="1" stop-color="{INK_DEEP}"/></radialGradient></defs>'75            '<rect width="1024" height="1024" fill="url(#bg)"/>'76        )7778    def glow(self, body, std=26, opacity=0.55):79        """Soft halo behind the artwork; only on the opaque default icon (keeps dark/tinted crisp)."""80        if self.mode != "default":81            return ""82        return (83            f'<defs><filter id="glow" x="-30%" y="-30%" width="160%" height="160%">'84            f'<feGaussianBlur stdDeviation="{std}"/></filter></defs>'85            f'<g filter="url(#glow)" opacity="{opacity}">{body}</g>'86        )878889def svg(ctx, body):90    return (91        '<svg xmlns="http://www.w3.org/2000/svg" width="1024" height="1024" viewBox="0 0 1024 1024">'92        f"{ctx.background()}{body}</svg>\n"93    )949596def brand_gradient(ctx, gid="brand", x1=0.15, y1=0.1, x2=0.85, y2=0.9):97    return (98        f'<defs><linearGradient id="{gid}" x1="{x1}" y1="{y1}" x2="{x2}" y2="{y2}">'99        f'<stop offset="0" stop-color="{ctx.c(CYAN)}"/><stop offset="1" stop-color="{ctx.c(VIOLET)}"/>'100        "</linearGradient></defs>"101    )102103104# ---- Concept 1: the ORIX "O" containing a seven-band spectral waveform -------------------------105# Ring: centre (512,512), centreline radius 318, stroke 68 (outer 352, inner 284).106# Seven bars, one per frequency band, 46 wide on a 64 pitch, vertically centred, fully rounded.107C1_RING_R, C1_RING_W = 318, 68108C1_BAR_W, C1_PITCH = 46, 64109C1_HALF_HEIGHTS = [64, 128, 204, 150, 216, 112, 58]110111112def concept1(ctx):113    bars = ""114    for i, (hh, col) in enumerate(zip(C1_HALF_HEIGHTS, BANDS)):115        cx = 512 + (i - 3) * C1_PITCH116        bars += (117            f'<rect x="{cx - C1_BAR_W / 2}" y="{512 - hh}" width="{C1_BAR_W}" height="{2 * hh}" '118            f'rx="{C1_BAR_W / 2}" fill="{ctx.c(col)}"/>'119        )120    ring = (121        f'<circle cx="512" cy="512" r="{C1_RING_R}" fill="none" stroke="url(#brand)" '122        f'stroke-width="{C1_RING_W}"/>'123    )124    return brand_gradient(ctx) + ctx.glow(ring + bars, 30, 0.5) + ring + bars125126127# ---- Concept 2: a circular waveform that forms the O monogram ----------------------------------128def concept2(ctx):129    n, r0 = 36, 250130    body = ""131    for k in range(n):132        a = 2 * math.pi * k / n - math.pi / 2133        t = k / n134        # deterministic "waveform" envelope: sum of two sines, always positive135        amp = 0.55 + 0.30 * math.sin(2 * math.pi * 3 * t + 0.6) + 0.15 * math.sin(2 * math.pi * 7 * t)136        length = 46 + 92 * max(0.08, amp)137        # colour runs around the ring through the seven bands and back (mirror) so the seam is clean138        pos = 1 - abs(2 * t - 1)139        col = BANDS[min(6, int(pos * 7))]140        x1, y1 = 512 + (r0 - length * 0.35) * math.cos(a), 512 + (r0 - length * 0.35) * math.sin(a)141        x2, y2 = 512 + (r0 + length * 0.65) * math.cos(a), 512 + (r0 + length * 0.65) * math.sin(a)142        body += (143            f'<line x1="{x1:.1f}" y1="{y1:.1f}" x2="{x2:.1f}" y2="{y2:.1f}" stroke="{ctx.c(col)}" '144            'stroke-width="24" stroke-linecap="round"/>'145        )146    return ctx.glow(body, 22, 0.45) + body147148149# ---- Concept 3: minimalist acoustic frequency symbol -------------------------------------------150def concept3(ctx):151    # one bold period-and-a-half of a sine with a decaying envelope, crossing a hairline axis152    pts = []153    for s in range(0, 201):154        t = s / 200155        x = 200 + 624 * t156        env = math.sin(math.pi * t) ** 0.8157        y = 512 - 250 * env * math.sin(2 * math.pi * 2.0 * t)158        pts.append(f"{x:.1f},{y:.1f}")159    wave = (160        f'<polyline points="{" ".join(pts)}" fill="none" stroke="url(#brand3)" stroke-width="64" '161        'stroke-linecap="round" stroke-linejoin="round"/>'162    )163    axis = (164        f'<line x1="170" y1="512" x2="854" y2="512" stroke="{ctx.c(HAIRLINE) if ctx.mode == "default" else ctx.c("#5B6478")}" '165        'stroke-width="10" stroke-linecap="round"/>'166    )167    dots = "".join(168        f'<circle cx="{x}" cy="512" r="20" fill="{ctx.c(TEXT)}"/>' for x in (200, 824)169    )170    grad = (171        '<defs><linearGradient id="brand3" x1="0" y1="0" x2="1" y2="0">'172        f'<stop offset="0" stop-color="{ctx.c(VIOLET)}"/><stop offset="0.5" stop-color="{ctx.c(CYAN)}"/>'173        f'<stop offset="1" stop-color="{ctx.c(BANDS[3])}"/></linearGradient></defs>'174    )175    return grad + axis + ctx.glow(wave, 24, 0.5) + wave + dots176177178# ---- Concept 4: precision audio aperture (seven blades = seven bands) --------------------------179def concept4(ctx):180    body = ""181    R, r = 340, 118182    n = 7183    for k in range(n):184        a0 = 2 * math.pi * k / n - math.pi / 2185        a1 = a0 + 2 * math.pi / n186        # blade: outer arc from a0 to a1, then swept in to the inner heptagon vertex (iris twist)187        twist = 2 * math.pi / n * 1.25188        ox0, oy0 = 512 + R * math.cos(a0), 512 + R * math.sin(a0)189        ox1, oy1 = 512 + R * math.cos(a1), 512 + R * math.sin(a1)190        ix1, iy1 = 512 + r * math.cos(a1 + twist), 512 + r * math.sin(a1 + twist)191        ix0, iy0 = 512 + r * math.cos(a0 + twist), 512 + r * math.sin(a0 + twist)192        body += (193            f'<path d="M{ox0:.1f},{oy0:.1f} A{R},{R} 0 0 1 {ox1:.1f},{oy1:.1f} L{ix1:.1f},{iy1:.1f} '194            f'L{ix0:.1f},{iy0:.1f} Z" fill="{ctx.c(BANDS[k])}" stroke="{"#000000" if ctx.mode == "tinted" else INK_DEEP}" '195            'stroke-width="12" stroke-linejoin="round"/>'196        )197    centre = f'<circle cx="512" cy="512" r="34" fill="{ctx.c(TEXT)}"/>'198    return ctx.glow(body, 26, 0.4) + body + centre199200201# ---- Concept 5: spectral ribbon ---------------------------------------------------------------202def concept5(ctx):203    body = ""204    for i, col in enumerate(BANDS):205        off = (i - 3) * 40206        # the strands converge at the two ends and fan out through the crest and the trough207        d = (208            f"M150,{512 + off * 0.25:.1f} "209            f"C300,{120 + off * 1.9:.1f} 420,{160 + off * 1.9:.1f} 512,{512 + off * 0.1:.1f} "210            f"S724,{904 - off * 1.9:.1f} 874,{512 - off * 0.25:.1f}"211        )212        body += (213            f'<path d="{d}" fill="none" stroke="{ctx.c(col)}" stroke-width="30" stroke-linecap="round"/>'214        )215    return ctx.glow(body, 22, 0.45) + body216217218DRAW = {1: concept1, 2: concept2, 3: concept3, 4: concept4, 5: concept5}219220221def concept_svg(n, mode="default"):222    ctx = Ctx(mode)223    return svg(ctx, DRAW[n](ctx))224225226# ---- rendering helpers -------------------------------------------------------------------------227def render(svg_path, png_path, size):228    subprocess.run(229        ["rsvg-convert", "-w", str(size), "-h", str(size), str(svg_path), "-o", str(png_path)],230        check=True,231    )232233234def rounded(img, radius_ratio=0.2237):235    """Presentation-only rounded corners (the shipped icon stays square; iOS applies its own mask)."""236    size = img.size[0]237    scale = 4238    mask = Image.new("L", (size * scale, size * scale), 0)239    ImageDraw.Draw(mask).rounded_rectangle(240        [0, 0, size * scale - 1, size * scale - 1], radius=int(size * scale * radius_ratio), fill=255241    )242    mask = mask.resize((size, size), Image.LANCZOS)243    out = Image.new("RGBA", (size, size), (0, 0, 0, 0))244    out.paste(img.convert("RGBA"), (0, 0), mask)245    return out246247248def font(size):249    for name in ("/System/Library/Fonts/SFNS.ttf", "/System/Library/Fonts/Helvetica.ttc"):250        try:251            return ImageFont.truetype(name, size)252        except OSError:253            continue254    return ImageFont.load_default()255256257def contact_sheet():258    big, small, pad = 320, 60, 40259    width = pad + 5 * (big + pad)260    height = pad + 44 + big + 30 + small + 56261    sheet = Image.new("RGB", (width, height), _rgb("#1B1E2A"))262    draw = ImageDraw.Draw(sheet)263    for n in range(1, 6):264        x = pad + (n - 1) * (big + pad)265        draw.text((x, pad - 6), f"{n}  {CONCEPTS[n]}", fill=_rgb(TEXT), font=font(24))266        b = rounded(Image.open(BUILD / f"concept-{n}-1024.png").resize((big, big), Image.LANCZOS))267        sheet.paste(b, (x, pad + 44), b)268        s = rounded(Image.open(BUILD / f"concept-{n}-60.png"))269        sheet.paste(s, (x, pad + 44 + big + 30), s)270        draw.text((x + small + 14, pad + 44 + big + 30 + 20), "60 px", fill=_rgb("#8B93A7"), font=font(18))271    DOCS.mkdir(parents=True, exist_ok=True)272    sheet.save(DOCS / "icon-concepts.png")273274275def write_json(path, obj):276    path.write_text(json.dumps(obj, indent=2) + "\n")277278279def production(winner):280    icon_dir = ASSETS / "AppIcon.appiconset"281    icon_dir.mkdir(parents=True, exist_ok=True)282    write_json(ASSETS / "Contents.json", {"info": {"author": "xcode", "version": 1}})283284    for mode, name in (("default", "AppIcon"), ("dark", "AppIcon-Dark"), ("tinted", "AppIcon-Tinted")):285        src = BUILD / f"winner-{mode}.svg"286        src.write_text(concept_svg(winner, mode))287        out = icon_dir / f"{name}.png"288        render(src, out, 1024)289        img = Image.open(out)290        if mode == "dark":291            img.convert("RGBA").save(out)  # transparent background: the system supplies the dark fill292        elif mode == "tinted":293            img.convert("L").convert("RGB").save(out)  # opaque grayscale, no alpha294        else:295            img.convert("RGB").save(out)  # opaque, no alpha channel (App Store requirement)296297    def entry(filename, appearance=None):298        e = {"filename": filename, "idiom": "universal", "platform": "ios", "size": "1024x1024"}299        if appearance:300            e["appearances"] = [{"appearance": "luminosity", "value": appearance}]301        return e302303    write_json(304        icon_dir / "Contents.json",305        {306            "images": [307                entry("AppIcon.png"),308                entry("AppIcon-Dark.png", "dark"),309                entry("AppIcon-Tinted.png", "tinted"),310            ],311            "info": {"author": "xcode", "version": 1},312        },313    )314315    accent = ASSETS / "AccentColor.colorset"316    accent.mkdir(exist_ok=True)317318    def colour(hexcolor, dark=False):319        r, g, b = _rgb(hexcolor)320        c = {321            "color": {322                "color-space": "srgb",323                "components": {324                    "alpha": "1.000",325                    "red": f"0x{r:02X}",326                    "green": f"0x{g:02X}",327                    "blue": f"0x{b:02X}",328                },329            },330            "idiom": "universal",331        }332        if dark:333            c["appearances"] = [{"appearance": "luminosity", "value": "dark"}]334        return c335336    write_json(337        accent / "Contents.json",338        {"colors": [colour("#0891B2"), colour(CYAN, dark=True)], "info": {"author": "xcode", "version": 1}},339    )340341    mark = ASSETS / "BrandMark.imageset"342    mark.mkdir(exist_ok=True)343    (mark / "BrandMark.svg").write_text(concept_svg(winner, "mark"))344    write_json(345        mark / "Contents.json",346        {347            "images": [{"filename": "BrandMark.svg", "idiom": "universal"}],348            "info": {"author": "xcode", "version": 1},349            "properties": {"preserves-vector-representation": True},350        },351    )352353    # repository branding354    DOCS.mkdir(parents=True, exist_ok=True)355    (DOCS / "orix-audio-icon.svg").write_text(concept_svg(winner, "default"))356    full = Image.open(icon_dir / "AppIcon.png")357    rounded(full).save(DOCS / "orix-audio-icon-1024.png")358    rounded(full.resize((256, 256), Image.LANCZOS)).save(DOCS / "orix-audio-icon-256.png")359    (DOCS / "orix-audio-logo.svg").write_text(logo_svg(winner))360361362def logo_svg(winner):363    """Mark on its ink tile + wordmark. The wordmark uses the brand gradient and a mid gray, both of which364    hold their contrast on light and on dark repository themes."""365    ctx = Ctx("default")366    inner = DRAW[winner](ctx)367    return (368        '<svg xmlns="http://www.w3.org/2000/svg" width="720" height="200" viewBox="0 0 720 200" role="img" '369        'aria-label="ORIX Audio">'370        '<defs><clipPath id="tile"><rect width="1024" height="1024" rx="229" ry="229"/></clipPath>'371        '<linearGradient id="word" x1="0" y1="0" x2="1" y2="0">'372        f'<stop offset="0" stop-color="#0891B2"/><stop offset="1" stop-color="{VIOLET}"/></linearGradient></defs>'373        '<g transform="translate(20,20) scale(0.15625)"><g clip-path="url(#tile)">'374        f"{ctx.background()}{inner}</g></g>"375        '<text x="212" y="128" font-family="-apple-system, \'SF Pro Display\', \'Helvetica Neue\', Helvetica, Arial, sans-serif" '376        'font-size="84" font-weight="700" letter-spacing="2" fill="url(#word)">ORIX'377        '<tspan font-weight="300" fill="#7C8499" dx="18" letter-spacing="0">Audio</tspan></text>'378        "</svg>\n"379    )380381382def main():383    parser = argparse.ArgumentParser()384    parser.add_argument("--winner", type=int, default=1, choices=sorted(CONCEPTS))385    args = parser.parse_args()386    BUILD.mkdir(parents=True, exist_ok=True)387    for n in CONCEPTS:388        path = BUILD / f"concept-{n}.svg"389        path.write_text(concept_svg(n))390        render(path, BUILD / f"concept-{n}-1024.png", 1024)391        render(path, BUILD / f"concept-{n}-60.png", 60)392    contact_sheet()393    production(args.winner)394    print(f"concepts: {BUILD}\ncontact sheet: {DOCS / 'icon-concepts.png'}\nproduction icon: concept {args.winner} ({CONCEPTS[args.winner]})")395396397if __name__ == "__main__":398    sys.exit(main())399
Files main
Menu

Theme