parsimony/assets/make-logo.py
tgiachi 5f5deb3e30 feat(assets): the Parsimony logo
- Add the mark (an envelope in a rounded square) and the wordmark, drawn with monoline strokes so no font is needed
- Add light and dark versions, and the generator script
- Embed them in a Go package and ship the same files with the admin UI
- Test that the SVGs are well formed, need nothing from outside, stay in sync with the admin copies and have enough contrast
2026-11-10 12:13:17 +01:00

85 lines
3.9 KiB
Python

# Generates the Parsimony logo files: python3 assets/make-logo.py assets
# The wordmark is drawn with monoline strokes, not typeset: it needs no font and looks the same everywhere.
# The mark is an envelope in a rounded square; the dot of the i echoes it in the accent colour.
import math, sys
INK, TEAL, WHITE = "#0f172a", "#0f766e", "#ffffff"
SW = 4.4 # stroke width of the letters
H = 24 # x-height
B = 40 # baseline y in the wordmark box
T = B - H
GAP = 8.5
def circle(cx, cy, r): return f'<circle cx="{cx}" cy="{cy}" r="{r}"/>'
def path(d): return f'<path d="{d}"/>'
def letter(ch):
"""returns (svg elements, advance width) with x from 0"""
if ch == "o": return circle(12, B-12, 12), 24
if ch == "a": return circle(12, B-12, 12) + path(f"M24 {T}V{B}"), 24
if ch == "p": return path(f"M0 {T}V{B+14}") + circle(12, B-12, 12), 24
if ch == "n": return path(f"M0 {T}V{B}") + path(f"M0 {T+12}A12 12 0 0 1 24 {T+12}V{B}"), 24
if ch == "m": return path(f"M0 {T}V{B}") + path(f"M0 {T+10}A10 10 0 0 1 20 {T+10}V{B}") + path(f"M20 {T+10}A10 10 0 0 1 40 {T+10}V{B}"), 40
if ch == "r": return path(f"M0 {T}V{B}") + path(f"M0 {T+13}A13 13 0 0 1 13 {T}"), 13
if ch == "i": return path(f"M0 {T}V{B}") + f'<path class="dot" d="M0 {T-10}v0.01"/>', 0
if ch == "y": return path(f"M0 {T}L12.6 {B}") + path(f"M24 {T}L6 {B+14}"), 24
if ch == "s":
d = (f"M18 {T+5}C15 {T+1} 11 {T} 9 {T}C4 {T} 2 {T+3.5} 2 {T+6.5}C2 {T+11} 7 {T+12} 10.5 {T+13}"
f"C15 {T+14} 18 {T+16} 18 {T+19}C18 {T+22.5} 14 {B} 9 {B}C5 {B} 2 {B-1.5} 1 {B-5}")
return path(d), 18
raise ValueError(ch)
def wordmark(text="parsimony"):
kern = {("r", "s"): -4.0, ("p", "a"): -0.5}
x = 0; out = []; prev = None
for ch in text:
x += kern.get((prev, ch), 0)
svg, w = letter(ch)
out.append(f'<g transform="translate({x:.1f} 0)">{svg}</g>')
x += w + GAP
prev = ch
return "".join(out), x - GAP
def envelope(cx, cy, w=30, h=22, sw=4):
"""envelope outline with its flap, centred on cx,cy"""
x0, y0, x1, y1 = cx-w/2, cy-h/2, cx+w/2, cy+h/2
f = lambda v: f"{v:g}"
return (f'<path d="M{f(x0)} {f(y0)}H{f(x1)}V{f(y1)}H{f(x0)}Z"/>'
f'<path d="M{f(x0)} {f(y0)}L{f(cx)} {f(cy+h*0.18)}L{f(x1)} {f(y0)}"/>')
def mark_svg(bg=True, fg=WHITE, bgc=TEAL):
s = f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" role="img" aria-label="Parsimony">'
if bg: s += f'<rect width="64" height="64" rx="15" fill="{bgc}"/>'
s += f'<g fill="none" stroke="{fg}" stroke-width="4.2" stroke-linecap="round" stroke-linejoin="round">{envelope(32, 33, 32, 24)}</g>'
s += '</svg>'
return s
def logo_svg(dark=False):
ink = WHITE if dark else INK
teal = "#2dd4bf" if dark else TEAL
wm, ww = wordmark()
gap = 22
scale = 1.0
mark = 56
total_w = mark + gap + ww + 4
# vertical: mark centred on the x-height band of the wordmark
top = T - 14 - 2.2 # i-dot top
bottom = B + 14 + 2.2 # descenders
h = bottom - top
my = (h - mark) / 2
tx = mark + gap + 2.2
ty = -top
s = (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {total_w+2.2:.1f} {h:.1f}" role="img" aria-label="Parsimony">'
f'<g transform="translate(0 {my:.1f})">'
f'<g transform="scale({mark/64})"><rect width="64" height="64" rx="15" fill="{teal}"/>'
f'<g fill="none" stroke="#fff" stroke-width="4.2" stroke-linecap="round" stroke-linejoin="round">{envelope(32,33,32,24)}</g></g></g>'
f'<g transform="translate({tx:.1f} {ty:.1f})" fill="none" stroke="{ink}" stroke-width="{SW}" stroke-linecap="round" stroke-linejoin="round">{wm}</g>'
f'</svg>')
s = s.replace('class="dot"', f'stroke="{teal}"')
return s
if __name__ == "__main__":
out = sys.argv[1]
open(f"{out}/logo.svg","w").write(logo_svg(False))
open(f"{out}/logo-dark.svg","w").write(logo_svg(True))
open(f"{out}/logo-mark.svg","w").write(mark_svg())