#!/usr/bin/env python3 """Draws Incari's icon: a snow-white pine with a comet circling up it, its tail fading below. python3 tools/icon/make_icon.py Writes tools/icon/incari-icon.svg (the source art, 512 units square, transparent), and with rsvg-convert on the path, the PNGs the client reads: the window icon's sizes and the 256-pixel image the GUI draws the mark from (incari.client.ui.Logo), under the Incari pack; the 32-pixel badge glyph the incari:badge font shows before Incari players' name tags; and the page's favicon, the 48-pixel PNG written into app-web's index.html (so the one-file build has it too). Standard library only. The trail is a cone-shaped helix around the tree, cut in short quads: SVG has no gradient along a path, so each quad takes its own colour, and a mask of grey quads (opaque in the mask, so neighbours overlap without seams) fades the tail out. Quads behind the tree are drawn before it, quads in front after it, over a faint dark edge so they part from the white. """ import base64 import math import re import shutil import subprocess from pathlib import Path HERE = Path(__file__).resolve().parent PACK = HERE.parents[1] / "client/src/main/resources/incari-pack/assets/incari/textures/gui" PAGE = HERE.parents[1] / "app-web/src/main/web/index.html" SIZES = (16, 32, 48, 128, 256) FAVICON = 48 BADGE = HERE.parents[1] / "client/src/main/resources/incari-pack/assets/incari/textures/font/badge.png" CX = 256 TIP = 50 # Each tier: its apex, its bottom and its half width. TIERS = [(50, 160, 66), (100, 236, 102), (160, 316, 136), (226, 392, 168)] # The comet: its head's height, how far the trail drops, how many turns it makes, the head's angle, # how flat the orbit looks (the ellipse's minor axis over its major), and the trail's quads. HEAD_Y = 118 DROP = 290 TURNS = 2.31 HEAD_ANGLE = math.radians(22) TILT = 0.28 QUADS = 900 EDGE = "#1d3f5c" def half_width(y): """The tree's half width at a height: the cone its tiers' tips lie on.""" return max(0, (y - TIP) / (392 - TIP) * 168) def tier_path(apex, bottom, half): """A tier: flanks curving in, a bottom of drooping points.""" d = f"M{CX},{apex} Q{CX - half * 0.28:.1f},{apex + (bottom - apex) * 0.62:.1f} {CX - half:.1f},{bottom:.1f} " tips = [-1, -0.5, 0, 0.5, 1] for x0, x1 in zip(tips, tips[1:]): notch = (x0 + x1) / 2 drop = 0 if abs(x1) == 1 else 5 d += f"L{CX + half * notch:.1f},{bottom - 20:.1f} L{CX + half * x1:.1f},{bottom + drop:.1f} " d += f"Q{CX + half * 0.28:.1f},{apex + (bottom - apex) * 0.62:.1f} {CX},{apex} Z" return d TRUNK_BOTTOM = 452 TRUNK = f"M{CX - 20},380 L{CX + 20},380 L{CX + 24},446 Q{CX},{TRUNK_BOTTOM} {CX - 24},446 Z" def position(s): """The trail at s, 0 at the tail and 1 at the head: x, y, and how far in front of the tree.""" centre = HEAD_Y + (1 - s) * DROP angle = HEAD_ANGLE - (1 - s) * TURNS * 2 * math.pi radius = half_width(centre) * 0.88 + 58 return CX + radius * math.cos(angle), centre + TILT * radius * math.sin(angle), math.sin(angle) def width(s): return 11 * s**1.5 def opacity(s): t = min(1, s / 0.38) return t * t * (3 - 2 * t) def colour(s): stops = [(0, (178, 204, 230)), (0.55, (206, 224, 242)), (0.85, (230, 240, 250)), (1, (255, 255, 255))] for (s0, c0), (s1, c1) in zip(stops, stops[1:]): if s <= s1: t = (s - s0) / (s1 - s0) return "#%02x%02x%02x" % tuple(round(a + (b - a) * t) for a, b in zip(c0, c1)) return "#ffffff" POINTS = [position(i / QUADS) for i in range(QUADS + 1)] def quads(pad, fill, front): """The trail's quads on one side of the tree, widened by pad, each filled by fill(s).""" out = [] for i in range(QUADS): x0, y0, f0 = POINTS[i] x1, y1, f1 = POINTS[i + 1] if (f0 + f1 > 0) != front: continue dx, dy = x1 - x0, y1 - y0 length = math.hypot(dx, dy) ux, uy = dx / length, dy / length # Each quad a little longer than its step, so neighbours overlap. x0, y0, x1, y1 = x0 - ux * 0.6, y0 - uy * 0.6, x1 + ux * 0.6, y1 + uy * 0.6 w0 = width(i / QUADS) / 2 + pad w1 = width((i + 1) / QUADS) / 2 + pad nx, ny = -uy, ux corners = [(x0 + nx * w0, y0 + ny * w0), (x1 + nx * w1, y1 + ny * w1), (x1 - nx * w1, y1 - ny * w1), (x0 - nx * w0, y0 - ny * w0)] path = "L".join(f"{a:.2f},{b:.2f}" for a, b in corners) out.append(f'') return "".join(out) def grey(s): return "#%02x%02x%02x" % ((round(255 * opacity(s)),) * 3) def trail(front): """The mask, the trail and (in front only) the dark edge under it.""" tag = "front" if front else "back" mask = f'{quads(4, grey, front)}' body = f'{quads(0, colour, front)}' edge = (f'' f'{quads(2.5, lambda s: EDGE, front)}') return mask, body, edge def svg(): paths = [tier_path(*tier) for tier in TIERS] silhouette = "".join(f'' for p in reversed(paths)) back_mask, back, _ = trail(False) front_mask, front, edge = trail(True) head_x, head_y, _ = POINTS[-1] # Each tier shaded like a cone (cooler on the left, white right of the ridge), lit at its top, # and casting a soft shadow on the tier below it. tree = [f'', f'', f''] for i in reversed(range(len(TIERS))): tree.append(f'') tree.append(f'') tree.append(f'') if i > 0: tree.append(f'') tier_clips = "".join(f'' for i, p in enumerate(paths)) lights = "".join( f'' f'' f'' f'' for i, (apex, bottom, _) in enumerate(TIERS)) return f""" {lights} {silhouette} {tier_clips} {back_mask}{front_mask} {back} {"".join(tree)} {edge}{front} """ def main(): source = HERE / "incari-icon.svg" source.write_text(svg()) print(f"Wrote {source}") if shutil.which("rsvg-convert") is None: print("rsvg-convert isn't on the path: the PNGs weren't made") return PACK.mkdir(parents=True, exist_ok=True) for size in SIZES: png = PACK / f"icon_{size}.png" subprocess.run(["rsvg-convert", "-w", str(size), "-h", str(size), str(source), "-o", str(png)], check=True) print(f"Wrote {png}") # The badge, cropped so the tree runs from the glyph's top to its baseline: incari:badge's glyph # is 9 units with 8 above the baseline, as tall as the name tag's capitals. side = (TRUNK_BOTTOM - TIP) * 9 / 8 cropped = HERE / "badge.svg" cropped.write_text(svg().replace('viewBox="0 0 512 512" width="512" height="512"', f'viewBox="{CX - side / 2:.2f} {TIP} {side:.2f} {side:.2f}" width="32" height="32"', 1)) subprocess.run(["rsvg-convert", "-w", "32", "-h", "32", str(cropped), "-o", str(BADGE)], check=True) cropped.unlink() print(f"Wrote {BADGE}") favicon = base64.b64encode((PACK / f"icon_{FAVICON}.png").read_bytes()).decode() page = re.sub(r'', f'', PAGE.read_text(), count=1) PAGE.write_text(page) print(f"Wrote the favicon into {PAGE}") if __name__ == "__main__": main()