openhop

srcSource code

Source code

Every file of openhop's latest version, exactly as published. Read anything, or download it all as a zip.

Commit
c8cfb4c
Date
16 Nov 2026
Files
62 files
Download the source (zip)

zip · 758 KB · SHA-256 6ce65b028777bf92…

make_brand.py

138 lines · 5.9 KB · Python

"""Generate the openhop brand: app icon (.ico, multi-size), PNGs and SVGs.
Logo = "Tag": a stencil lowercase 'h' (the arch has hopped off the stem) on an amber equipment tag
with chamfered corners. Chosen by the user on 2026-11-15 (see assets/brand/options/option3-tag.png).
Usage: python tools/make_brand.py
Writes src/assets/openhop.ico, assets/brand/*.png|svg and assets/brand/_preview.png (review only, not committed).
"""
import pathlib
import sys
from PIL import Image, ImageDraw
ROOT = pathlib.Path(sys.argv[1]) if len(sys.argv) > 1 else pathlib.Path(__file__).resolve().parent.parent
BRAND = ROOT / "assets" / "brand"
BRAND.mkdir(parents=True, exist_ok=True)
# Brand colours (also used by the UI: --brand / --ink / --paper)
AMBER = "#f2b318"
GRAPHITE = "#1f2125"
PAPER = "#efede6"
def _rgb(h):
return tuple(int(h[i:i + 2], 16) for i in (1, 3, 5))
def plate_pts(inset, chamfer):
a, b, c = inset, 100 - inset, chamfer
return [(a + c, a), (b - c, a), (b, a + c), (b, b - c), (b - c, b), (a + c, b), (a, b - c), (a, a + c)]
def plate_path(inset, chamfer):
p = plate_pts(inset, chamfer)
return "M" + " L".join(f"{x:g} {y:g}" for x, y in p) + " Z"
# Geometry in a 100x100 box. Small sizes drop the rim + hang hole and use a tighter plate.
DETAIL = dict(inset=3, chamfer=9)
SMALL = dict(inset=1, chamfer=7)
STEM = (22, 17, 37, 83) # x0, y0, x1, y1
ARCH_W = 15 # stroke width of the shoulder
# centre-line of the shoulder: M41 41.5 H51 Q68.5 41.5 68.5 59 V83 (butt ends)
def arch_centerline(steps=600):
pts = [(41 + (51 - 41) * i / 60, 41.5) for i in range(61)]
for i in range(steps + 1):
t = i / steps
u = 1 - t
pts.append((u * u * 51 + 2 * u * t * 68.5 + t * t * 68.5, u * u * 41.5 + 2 * u * t * 41.5 + t * t * 59))
pts += [(68.5, 59 + (83 - 59) * i / 60) for i in range(61)]
return pts
ARCH = arch_centerline()
def render(px: int) -> Image.Image:
detail = px > 32
ss = 8 if px <= 64 else 4
S = px * ss
k = S / 100.0
img = Image.new("RGBA", (S, S), (0, 0, 0, 0))
d = ImageDraw.Draw(img)
geo = DETAIL if detail else SMALL
d.polygon([(x * k, y * k) for x, y in plate_pts(**geo)], fill=_rgb(AMBER))
ink = _rgb(GRAPHITE)
if detail:
rim = Image.new("L", (S, S), 0)
ImageDraw.Draw(rim).polygon([(x * k, y * k) for x, y in plate_pts(7, 7)], outline=255, width=max(1, round(1.4 * k)))
img.paste(ink + (46,), (0, 0), rim.point(lambda v: v * 46 // 255))
hole = Image.new("L", (S, S), 0)
hr, hw = 4.2 * k, 2 * k
ImageDraw.Draw(hole).ellipse((84 * k - hr - hw / 2, 16 * k - hr - hw / 2, 84 * k + hr + hw / 2, 16 * k + hr + hw / 2), fill=255)
ImageDraw.Draw(hole).ellipse((84 * k - hr + hw / 2, 16 * k - hr + hw / 2, 84 * k + hr - hw / 2, 16 * k + hr - hw / 2), fill=0)
img.paste(ink, (0, 0), hole.point(lambda v: v * 115 // 255))
x0, y0, x1, y1 = STEM
d.rectangle((x0 * k, y0 * k, x1 * k, y1 * k), fill=ink)
# shoulder: stamp round dabs along the centre-line, then cut butt ends (x<41, y>83)
arch = Image.new("L", (S, S), 0)
ad = ImageDraw.Draw(arch)
r = ARCH_W / 2 * k
for x, y in ARCH:
ad.ellipse((x * k - r, y * k - r, x * k + r, y * k + r), fill=255)
ad.rectangle((0, 0, 41 * k, S), fill=0)
ad.rectangle((0, 83 * k, S, S), fill=0)
img.paste(ink, (0, 0), arch)
return img.resize((px, px), Image.LANCZOS)
GLYPH_SVG = (f'<rect x="22" y="17" width="15" height="66" fill="{GRAPHITE}"/>'
f'<path d="M41 41.5 H51 Q68.5 41.5 68.5 59 V83" fill="none" stroke="{GRAPHITE}" stroke-width="15"/>')
def icon_svg(detail=True):
geo = DETAIL if detail else SMALL
extra = (f'<path d="{plate_path(7, 7)}" fill="none" stroke="{GRAPHITE}" stroke-opacity=".18" stroke-width="1.4"/>'
f'<circle cx="84" cy="16" r="4.2" fill="none" stroke="{GRAPHITE}" stroke-opacity=".45" stroke-width="2"/>'
if detail else "")
return (f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">'
f'<path d="{plate_path(**geo)}" fill="{AMBER}"/>{extra}{GLYPH_SVG}</svg>\n')
def main():
sizes = [16, 24, 32, 48, 64, 128, 256]
frames = {s: render(s) for s in sizes}
(ROOT / "src" / "assets").mkdir(parents=True, exist_ok=True)
frames[256].save(ROOT / "src" / "assets" / "openhop.ico", format="ICO", sizes=[(s, s) for s in sizes],
append_images=[frames[s] for s in sizes if s != 256])
for s in (1024, 512, 256):
render(s).save(BRAND / f"openhop-icon-{s}.png")
(BRAND / "openhop-icon.svg").write_text(icon_svg(True), encoding="utf-8")
(BRAND / "openhop-icon-small.svg").write_text(icon_svg(False), encoding="utf-8")
(BRAND / "openhop-mark.svg").write_text(
f'<svg xmlns="http://www.w3.org/2000/svg" viewBox="18 13 58 74">{GLYPH_SVG}</svg>\n', encoding="utf-8")
for name, word in (("openhop-wordmark.svg", GRAPHITE), ("openhop-wordmark-dark.svg", PAPER)):
(BRAND / name).write_text(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 100">'
+ icon_svg(True).replace('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100">', '<svg x="0" y="0" width="100" height="100" viewBox="0 0 100 100">')
+ f'<text x="118" y="70" font-family="Bahnschrift, \'DIN Alternate\', sans-serif" font-size="60" fill="{word}">'
'<tspan font-weight="300">open</tspan><tspan font-weight="700">hop</tspan></text></svg>\n',
encoding="utf-8")
# review sheet
W = 40 + sum(s + 28 for s in sizes)
sheet = Image.new("RGBA", (W, 600), (17, 18, 20, 255))
sheet.paste(Image.new("RGBA", (W, 300), _rgb(PAPER) + (255,)), (0, 300))
x = 20
for s in sizes:
for row in (0, 300):
sheet.alpha_composite(frames[s], (x, row + 150 - s // 2))
x += s + 28
sheet.save(BRAND / "_preview.png")
print("ok", sorted(p.name for p in BRAND.iterdir() if p.is_file()))
if __name__ == "__main__":
main()