Elffuss BraidHub

utopia-ia/elffuss-braid public

main · 1.9 KiB · executableRawPermalink
1#!/usr/bin/env python3
2# SPDX-License-Identifier: Apache-2.0
3# Copyright (c) 2026 UtopiaIA
4"""Builds the animated braid logo for the README from the site's hero logo.
5
6usage: logo.py <site/index.html> <out.svg>
7"""
8import re
9import sys
10
11html = open(sys.argv[1]).read()
12svg = re.search(r'<div class="hero-logo">(<svg.*?</svg>)</div>', html, re.S).group(1)
13defs = re.search(r"<defs>.*?</defs>", svg, re.S).group(0).replace("hl-cut", "cut")
14strands = re.findall(r'<path d="([^"]+)"[^>]*class="(s[abc])"[^>]*mask="url\(#hl-cut(\d)\)"', svg)
15assert len(strands) == 3, strands
16
17paths = "\n".join(
18 f'<path class="s {cls}" d="{d}" mask="url(#cut{n})" pathLength="1"/>' for d, cls, n in strands
19)
20
21out = f"""<!-- SPDX-License-Identifier: Apache-2.0
22 Copyright (c) 2026 UtopiaIA -->
23<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 96" width="320" height="96" role="img" aria-label="Three strands braided together">
24<title>elffuss-braid</title>
25<style>
26.s {{ fill: none; stroke-width: 9.5; stroke-linecap: round; stroke-linejoin: round; stroke-dasharray: 1 2; stroke-dashoffset: 0; }}
27.sa {{ stroke: #c8a06a; }}
28.sb {{ stroke: #54dcc6; }}
29.sc {{ stroke: #8272ff; }}
30@media (prefers-color-scheme: light) {{
31 .sa {{ stroke: #a77a3a; }}
32 .sb {{ stroke: #13917f; }}
33 .sc {{ stroke: #5b4ae6; }}
34}}
35/* each strand draws in from the left, holds, and leaves to the right, again and again */
36@media (prefers-reduced-motion: no-preference) {{
37 .s {{ animation: weave 7s infinite both; }}
38 .sb {{ animation-delay: .16s; }}
39 .sc {{ animation-delay: .32s; }}
40}}
41@keyframes weave {{
42 0% {{ stroke-dashoffset: 1; animation-timing-function: cubic-bezier(.22, .61, .36, 1); }}
43 22% {{ stroke-dashoffset: 0; }}
44 84% {{ stroke-dashoffset: 0; animation-timing-function: cubic-bezier(.55, 0, .75, .4); }}
45 100% {{ stroke-dashoffset: -1; }}
46}}
47</style>
48{defs}
49{paths}
50</svg>
51"""
52open(sys.argv[2], "w").write(out)
53print(len(out), "bytes")