Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them.
Page: /drakestapleton/aienos.com/blob/main/scripts/test-hive-cosmic.py
# aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
Sign in to star 0 stars 0 watching
About Files History Releases Proposed changes Issues For developers
branch `main` Branches Tags History
`aienos.com / scripts / test-hive-cosmic.py`
329 lines ยท 16952 bytes Raw Blame History
1 """Static presentation checks. Does not substitute for a Rust build or browser QA.
2
3 The scene behind the /hive/ masthead is Allen's two black holes: om/hive-page/hive.om
4 computes the inspiral (native/kernel/ui/night.c orbit_angle and ck_night_at) and
5 writes the samples into om/hive-page/main.html as CSS keyframes. These checks
6 recompute that law here, independently, and compare every stop with it, and they
7 pin the two contracts the artifact cannot state about itself: only transform and
8 opacity are animated, and nothing animates under prefers-reduced-motion.
9 """
10 from pathlib import Path
11 import hashlib, math, re, unittest, xml.etree.ElementTree as ET
12
13 ROOT = Path(__file__).resolve().parents[1]
14 PAGE = ROOT / 'om/hive-page/main.html'
15 CSS = ROOT / 'public/assets/hive.css'
16 GUIDE = ROOT / 'AGENTS.md'
17
18 CYCLE = 19000 # ms, one pass of the sequence plus the hold in the sky
19 APPEAR = 2600 # CK_NIGHT_HOLES_MS
20 SHADOW = 4000 # the shadow starts to grow (APPEAR + 1400)
21 SPIRAL = 6000 # CK_NIGHT_SPIRAL_MS
22 MERGE = 12000 # CK_NIGHT_MERGE_MS
23 FADE = 12900 # MERGE + 900, the last hole starts to dissolve
24 GONE = 15200 # CK_NIGHT_GONE_MS
25 RIPPLE = 15600 # MERGE + CK_NIGHT_RIPPLE_MS
26 A0 = 270.0 # separation of the wide orbit, Allen units
27 ORBIT = 5200.0 # ms per turn of the wide orbit
28 SF = (SPIRAL - APPEAR) * 65536 // ORBIT # 42850, 1/65536 turns
29 TURNS = 65536 * 8 * (MERGE - SPIRAL) // (5 * ORBIT) # 120989, 1/65536 turns
30 STEP = 40 # ms between position samples
31
32
33 def phase(page):
34 m = re.search(r'', page, re.S)
35 assert m, 'the artifact no longer carries the emitted style block'
36 return m.group(1)
37
38
39 def rules(css):
40 """Top level rules of a stylesheet, comments stripped, as (header, body)."""
41 css = re.sub(r'/\*.*?\*/', '', css, flags=re.S)
42 out, i, n = [], 0, len(css)
43 while i < n:
44 open_at = css.find('{', i)
45 if open_at < 0:
46 break
47 depth, k = 1, open_at + 1
48 while k < n and depth:
49 depth += {'{': 1, '}': -1}.get(css[k], 0)
50 k += 1
51 out.append((css[i:open_at].strip(), css[open_at + 1:k - 1]))
52 i = k
53 return out
54
55
56 def keyframes(css):
57 return {h.split(None, 1)[1]: b for h, b in rules(css) if h.startswith('@keyframes')}
58
59
60 def stops(body):
61 """[(ms, declarations)] of one @keyframes body."""
62 body = re.sub(r'/\*.*?\*/', '', body, flags=re.S)
63 return [(round(float(m.group(1)) * CYCLE / 100), m.group(2).strip())
64 for m in re.finditer(r'([\d.]+)%\s*\{([^}]*)\}', body)]
65
66
67 def at(table, ms):
68 """The declaration of the stop at ms, or of the nearest stop to it."""
69 t, decl = min(table, key=lambda row: abs(row[0] - ms))
70 return decl
71
72
73 def smooth(u):
74 u = max(0, min(256, u))
75 return u * u * (768 - 2 * u) >> 16
76
77
78 def prog(t, a, b):
79 if t <= a:
80 return 0
81 if t >= b:
82 return 256
83 return (t - a) * 256 // (b - a)
84
85
86 def law(t):
87 """Separation (Allen units) and angle (turns) at t ms, from night.c."""
88 t = max(t, APPEAR)
89 if t < SPIRAL:
90 return A0, (t - APPEAR) / ORBIT
91 left = max(0.0, (MERGE - t) / (MERGE - SPIRAL))
92 r8 = left ** 0.125
93 return A0 * r8 * r8, SF / 65536 + (TURNS / 65536) * (1.0 - r8 ** 5)
94
95
96 def place(t, sign):
97 sep, turn = law(t)
98 a = 2 * math.pi * turn
99 return sign * 0.5 * sep * math.cos(a), sign * 0.25 * sep * math.sin(a)
100
101
102 def translate(decl):
103 return [float(v) for v in re.findall(r'(-?[\d.]+)em', decl)]
104
105
106 class CosmicChecks(unittest.TestCase):
107
108 def test_omega_bytes_untouched(self):
109 self.assertEqual(hashlib.sha256(PAGE.read_bytes()).hexdigest(),
110 (ROOT / 'om/hive-page/main.html.sha256').read_text().split()[0])
111
112 def test_residual_sky_asset(self):
113 p = ROOT / 'public/assets/hive-universe.svg'
114 self.assertEqual(ET.parse(p).getroot().attrib['viewBox'], '0 0 1600 900')
115 self.assertNotRegex(p.read_text(), r'