LingSys
↓ 0 ดาวน์โหลดYour machine's memory, GPU, motherboard and network, drawn and played in the Ling design system: LingSys, a small build for USB liquid-cooler displays, LingNet for IPv4/IPv6, DNS and packets, and a LingOS edition. 64-bit and 32-bit Windows builds included.
คีย์เวิร์ด system-monitor, visualization, network, ipv6, gpu, lcd, lingos, ling
lingfu install LingSysโค้ด / ไฟล์ (48)
tools/gen_glyphs.py
#!/usr/bin/env python3
"""Refresh the glyph data inside hatchmem.ling from the Ling design system bundle.
Reads GLYPHS out of ling_bundle.js (../../ling_hatch/ling_bundle.js by default),
simplifies each outline with Douglas-Peucker, and rewrites the block between
"# ---- BEGIN GLYPHS ----" and "# ---- END GLYPHS ----" in hatchmem.ling:
DAEMON_CH / CHESILIN_CH alphabet strings (index = glyph number)
DAEMON / CHESILIN lists of [width, height, [[x, y, x, y, ...], ...]]
Glyph boxes are in design units, y down. Everything is inlined because the Ling JIT
does not see top-level bindings of `use`d modules.
"""
import json, re, sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
SRC = Path(sys.argv[1]) if len(sys.argv) > 1 else HERE.parent.parent / 'ling_hatch' / 'ling_bundle.js'
OUT = HERE.parent / 'hatchmem.ling'
BEGIN, END = '# ---- BEGIN GLYPHS ----', '# ---- END GLYPHS ----'
TOL = {'daemon': 4.0, 'chesilin': 5.0}
def dp(pts, tol):
if len(pts) < 3: return pts
(x0, y0), (x1, y1) = pts[0], pts[-1]
dx, dy = x1 - x0, y1 - y0; L = (dx * dx + dy * dy) ** .5 or 1e-9
best, bi = -1, 0
for i in range(1, len(pts) - 1):
d = abs(dy * (pts[i][0] - x0) - dx * (pts[i][1] - y0)) / L
if d > best: best, bi = d, i
if best <= tol: return [pts[0], pts[-1]]
return dp(pts[:bi + 1], tol)[:-1] + dp(pts[bi:], tol)
def simplify(flat, tol):
pts = [(flat[i], flat[i + 1]) for i in range(0, len(flat), 2)]
closed = len(pts) > 2 and pts[0] == pts[-1]
if closed: pts = pts[:-1]
out = dp(pts + [pts[0]], tol)[:-1] if closed and len(pts) > 3 else dp(pts, tol)
return [v for p in out for v in p]
src = SRC.read_text(encoding='utf8')
G = json.loads(re.search(r'var GLYPHS = (\{.*?\});\n', src, re.S).group(1))
lines = ['# generated by tools/gen_glyphs.py from the Ling design system bundle; do not edit by hand']
for face in ('daemon', 'chesilin'):
keys = [k for k in G[face] if k not in ("\"", chr(92))]
lines.append('bind %s_CH = "%s"' % (face.upper(), ''.join(keys)))
rows = []
for k in keys:
w, h, polys = G[face][k]
ps = ','.join('[' + ','.join(str(int(round(v))) for v in simplify(p, TOL[face])) + ']' for p in polys)
rows.append('[%d,%d,[%s]]' % (w, h, ps))
lines.append('bind %s = [\n%s\n]' % (face.upper(), ',\n'.join(rows)))
text = OUT.read_text(encoding='utf8')
if BEGIN not in text or END not in text:
sys.exit('markers missing in %s; nothing written' % OUT)
a, b = text.index(BEGIN) + len(BEGIN), text.index(END)
OUT.write_text(text[:a] + '\n' + '\n'.join(lines) + '\n' + text[b:], encoding='utf8')
print('updated', OUT, OUT.stat().st_size, 'bytes')