LingSys
↓ 0 downloadsYour 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.
Keywords system-monitor, visualization, network, ipv6, gpu, lcd, lingos, ling
lingfu install LingSysCode / Files (48)
src/20_helpers.ling
# ───────────────────────────── small helpers ─────────────────────────────────
fn mix(a, b, k) { return a + (b - a) * k }
fn pos_mod(a, m) {
bind r = a % m
if r < 0.0 { bind r = r + m }
return r
}
# set the pen to Ling hue k; shift is the global hue drift in degrees
fn col(k, sat, lit, shift) {
set_color_hsl(pos_mod(HUE[k] + shift, 360.0), clamp(sat, 0.0, 100.0), clamp(lit, 0.0, 100.0))
}
fn ink(lit) { set_color_hsl(214.0, 14.0, clamp(lit, 0.0, 100.0)) }
fn px(cx, r, a) { return cx + r * sin(a) }
fn py(cy, r, a) { return cy - r * cos(a) }
fn pline(cx, cy, r0, a0, r1, a1) {
draw_line(px(cx, r0, a0), py(cy, r0, a0), px(cx, r1, a1), py(cy, r1, a1))
}
# square of half-size h centred on (x, y), turned by a
fn square(x, y, h, a) {
bind c = cos(a)
bind s = sin(a)
bind x0 = x - h * c + h * s
bind y0 = y - h * s - h * c
bind x1 = x + h * c + h * s
bind y1 = y + h * s - h * c
bind x2 = x + h * c - h * s
bind y2 = y + h * s + h * c
bind x3 = x - h * c - h * s
bind y3 = y - h * s + h * c
draw_line(x0, y0, x1, y1)
draw_line(x1, y1, x2, y2)
draw_line(x2, y2, x3, y3)
draw_line(x3, y3, x0, y0)
}
# hatch inside a circle: parallel chords at angle a, spacing sp
fn hatch_disc(cx, cy, r, a, sp) {
bind nx = cos(a + 1.5708)
bind ny = sin(a + 1.5708)
bind tx = cos(a)
bind ty = sin(a)
bind d = 0.0 - r + sp * 0.5
while d < r {
bind h = sqrt(max(r * r - d * d, 0.0))
draw_line(cx + nx * d - tx * h, cy + ny * d - ty * h, cx + nx * d + tx * h, cy + ny * d + ty * h)
bind d = d + sp
}
}
# hatch inside an axis-aligned square [x, x+s] x [y, y+s], lines at 45 degrees
fn hatch_box(x, y, s, sp) {
bind d = sp
while d < 2.0 * s {
bind ax = x
bind ay = y + d
bind bx = x + d
bind by = y
if d > s {
bind ax = x + d - s
bind ay = y + s
bind bx = x + s
bind by = y + d - s
}
draw_line(ax, ay, bx, by)
bind d = d + sp
}
}
fn fmt_mb(v) {
if v >= 1024.0 { return num_str(round(v / 102.4) / 10.0) + "G" }
return num_str(round(v)) + "M"
}
fn fmt_rate(v) {
if v >= 10000.0 { return num_str(round(v / 1000.0)) + "K" }
if v >= 1000.0 { return num_str(round(v / 100.0) / 10.0) + "K" }
return num_str(round(v))
}
# ───────────────────────────── glyph drawing ─────────────────────────────────
# Outlines come from the Ling bundle. Contours are closed, y runs down.
# Daemon glyph fitted into a bw x bh box centred on (x, y), turned by a
fn daemon_glyph(ch, x, y, bw, bh, a) {
bind i = str_find(DAEMON_CH, ch)
if i < 0 { return 0 }
bind g = DAEMON[i]
bind sc = min(bw / g[0], bh / g[1])
bind gw = g[0] * sc
bind gh = g[1] * sc
bind c = cos(a)
bind s = sin(a)
bind polys = g[2]
bind p = 0
while p < len(polys) {
bind pts = polys[p]
bind n = len(pts) / 2
bind j = 0
while j < n {
bind k = (j + 1) % n
bind ux = pts[j * 2] * sc - gw / 2.0
bind uy = pts[j * 2 + 1] * sc - gh / 2.0
bind vx = pts[k * 2] * sc - gw / 2.0
bind vy = pts[k * 2 + 1] * sc - gh / 2.0
draw_line(x + ux * c - uy * s, y + ux * s + uy * c, x + vx * c - vy * s, y + vx * s + vy * c)
bind j = j + 1
}
bind p = p + 1
}
return 1
}
# a run of Daemon letters, h tall, left-aligned at (x, y) where y is the vertical centre
fn daemon_text(str, x, y, h) {
bind n = str_len(str)
bind i = 0
while i < n {
bind ch = str_slice(str, i, 1)
if ch != " " { daemon_glyph(ch, x + i * h * 0.74 + h * 0.3, y, h * 0.62, h, 0.0) }
bind i = i + 1
}
}
fn text_w(str, h) { return str_len(str) * h * 0.74 }
# Chesilin glyph bent round a ring: radius rm, centred on angle ac (radians, clockwise from up)
fn chesilin_glyph(ch, cx, cy, rm, ac, bw, bh) {
bind i = str_find(CHESILIN_CH, ch)
if i < 0 { return 0 }
bind g = CHESILIN[i]
bind sc = min(bw / g[0], bh / g[1])
bind gw = g[0] * sc
bind gh = g[1] * sc
bind polys = g[2]
bind p = 0
while p < len(polys) {
bind pts = polys[p]
bind n = len(pts) / 2
bind j = 0
while j < n {
bind k = (j + 1) % n
bind ux = pts[j * 2] * sc - gw / 2.0
bind uy = pts[j * 2 + 1] * sc - gh / 2.0
bind vx = pts[k * 2] * sc - gw / 2.0
bind vy = pts[k * 2 + 1] * sc - gh / 2.0
bind m = 1 + floor(abs(vx - ux) / (rm * 0.05))
bind q = 0
while q < m {
bind f0 = q / m
bind f1 = (q + 1) / m
pline(cx, cy, rm - mix(uy, vy, f0), ac + mix(ux, vx, f0) / rm, rm - mix(uy, vy, f1), ac + mix(ux, vx, f1) / rm)
bind q = q + 1
}
bind j = j + 1
}
bind p = p + 1
}
return 1
}
# ring text: the string repeats round the whole ring in n cells, turned by spin
fn ring_text(str, cx, cy, r0, r1, spin, lit, k, sat, hs) {
bind band = r1 - r0
bind rm = (r0 + r1) / 2.0
bind sl = str_len(str)
bind n = floor(TAU * rm / (band * 0.62))
bind da = TAU / n
col(k, sat, lit, hs)
bind i = 0
while i < n {
bind ch = str_slice(str, i % sl, 1)
if ch != " " { chesilin_glyph(ch, cx, cy, rm, spin + (i + 0.5) * da, rm * da * 0.72, band * 0.62) }
bind i = i + 1
}
}
# a Daemon tile: frame, corner brackets, letter, optional hatch
fn tile(ch, x, y, s, lit, k, sat, hs, fillk) {
col(k, sat, lit, hs)
draw_line(x, y, x + s, y)
draw_line(x + s, y, x + s, y + s)
draw_line(x + s, y + s, x, y + s)
draw_line(x, y + s, x, y)
bind a = s * 0.055
bind b = s * 0.21
draw_line(x + a, y + a + b, x + a, y + a)
draw_line(x + a, y + a, x + a + b, y + a)
draw_line(x + s - a - b, y + a, x + s - a, y + a)
draw_line(x + s - a, y + a, x + s - a, y + a + b)
draw_line(x + s - a, y + s - a - b, x + s - a, y + s - a)
draw_line(x + s - a, y + s - a, x + s - a - b, y + s - a)
draw_line(x + a + b, y + s - a, x + a, y + s - a)
draw_line(x + a, y + s - a, x + a, y + s - a - b)
if fillk > 0.0 {
col(k, sat * 0.8, lit * 0.45, hs)
hatch_box(x + a, y + a, s - 2.0 * a, max(2.5, s * 0.07) / fillk)
}
col(k, sat, min(lit + 16.0, 92.0), hs)
daemon_glyph(ch, x + s / 2.0, y + s / 2.0, s * 0.6, s * 0.6, 0.0)
}