sphere.py
In web/At 0e43f89Copy the commit ID
Preview
Code1.5 KiB"""Export an alternate sphere favicon without replacing the K."""
from pathlib import Path
import sys
import subprocess
import xml.etree.ElementTree as E
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
from source.logo import render, NS
logo = E.fromstring(render(False))
scene = next(e for e in logo if e.tag == NS + 'svg')
sphere = next(e for e in scene if e.get('aria-label') == 'Sphere')
cap = next(e for e in sphere if e.tag == NS + 'path').get('d')
endpoint = '-160.8428,-181.1411'
if endpoint not in cap:
raise ValueError('Sphere seam endpoint is absent')
seam = cap.split(endpoint)[0] + endpoint
root = E.Element(NS + 'svg', {'width': '64', 'height': '64', 'viewBox': '0 0 64 64', 'role': 'img', 'aria-label': 'KIT sphere'})
E.SubElement(root, NS + 'rect', {'width': '64', 'height': '64', 'rx': '14', 'fill': '#0067ed'})
g = E.SubElement(root, NS + 'g', {'transform': 'translate(32 32) scale(0.1872340425531915) translate(265 126.75799)'})
E.SubElement(g, NS + 'circle', {'cx': '-265', 'cy': '-126.75799', 'r': '117.5', 'fill': 'white'})
E.SubElement(g, NS + 'path', {'d': seam, 'fill': 'none', 'stroke': '#0067ed', 'stroke-width': '10.68', 'stroke-linecap': 'round', 'stroke-linejoin': 'round'})
art = ROOT / 'art/favicon'
art.mkdir(parents=True, exist_ok=True)
svg = art / 'sphere.svg'
svg.write_text(E.tostring(root, encoding='unicode') + '\n')
for size in [16, 32, 48]:
subprocess.run(['rsvg-convert', '-w', str(size), '-h', str(size), '-o', str(ROOT / f'previews/favicon/sphere-{size}.png'), str(svg)], check=True)