灵符lingfu

LingSys

↓ 0 downloads

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.

Keywords system-monitor, visualization, network, ipv6, gpu, lcd, lingos, ling
lingfu install LingSys
LicenseMIT
AuthorsLing Lin <taellinglin@gmail.com>
READMECode / FilesVersionsDependency GraphDependentsSecurityBuildsSettings

Code / Files (48)

src/55_common.ling
# ───────────────────────────── shared views ──────────────────────────────────
# Used by every section: a stack of Chesilin rings (any number of rings) and a scrolling
# seven-lane scope. The Memory views in 40_memory.ling keep their own copies of this.

bind D_HT = 6

fn fit_h(str, maxw, h) { return min(h, maxw / (max(str_len(str), 1) * 0.74)) }

fn ring_geom2(c, R, nr) {
    bind step = 0.7 / nr
    bind r1 = R * (1.0 - c * step)
    bind band = R * step * 0.82
    return [r1, r1 - band, band]
}

# nr rings, one per channel: fr[c] is how much of the ring is crosshatched, labels[c] runs round it.
# The hub shows `big` (Daemon) and `small`. Pulses (Z_EV, category = ring) ride the rings.
fn ring_stack(Z, nr, hm, labels, fr, big, small, bigk) {
    ring_stack_at(Z, Z[Z_W] / 2.0, Z[Z_H] / 2.0, min(Z[Z_W], Z[Z_H]) * 0.5 - 16.0, nr, hm, labels, fr, big, small, bigk)
}

# the same, centred on (cx, cy) with outer radius R
fn ring_stack_at(Z, cx, cy, R, nr, hm, labels, fr, big, small, bigk) {
    bind t = Z[Z_T]
    bind hs = Z[Z_HS]
    bind sat = Z[Z_SAT]
    bind en = Z[Z_ENERGY]
    bind c = 0
    while c < nr {
        bind gm = ring_geom2(c, R, nr)
        bind r1 = gm[0]
        bind r0 = gm[1]
        bind band = gm[2]
        bind frac = clamp(fr[c], 0.0, 1.0)
        bind spin = ring_spin(Z, c)
        bind e = en[c]
        col(hm[c], sat * 0.7, 26.0 + 14.0 * e, hs)
        draw_circle(cx, cy, r1)
        draw_circle(cx, cy, r0)
        bind sweep = max(frac * TAU, 0.03)
        bind da = 0.0215
        bind n = floor(sweep / da)
        bind k = 0
        col(hm[c], sat, 36.0 + 26.0 * e, hs)
        while k < n {
            bind a = spin + k * da
            pline(cx, cy, r0, a, r1, a + 0.05 + 0.05 * e)
            bind k = k + 1
        }
        if e > 0.35 {
            bind k = 0
            col(hm[c], sat, 30.0 + 22.0 * e, hs)
            while k < n {
                bind a = spin + k * da
                pline(cx, cy, r0, a + 0.05, r1, a)
                bind k = k + 2
            }
        }
        col(hm[c], sat, 62.0 + 28.0 * e, hs)
        pline(cx, cy, r0 - 4.0, spin, r1 + 4.0, spin)
        pline(cx, cy, r0 - 4.0, spin + sweep, r1 + 4.0, spin + sweep)
        ring_text(labels[c], cx, cy, r0 + band * 0.06, r1 - band * 0.06, spin * 0.6 + 1.0, 74.0 + 20.0 * e, hm[c], sat, hs)
        bind c = c + 1
    }
    bind hr = R * 0.3 - 6.0
    ink(34.0)
    draw_circle(cx, cy, hr)
    bind k = 0
    while k < 60 {
        bind a = k * TAU / 60.0 + Z[Z_ROT] * 0.5
        bind tl = 5.0
        if k % 5 == 0 { bind tl = 11.0 }
        pline(cx, cy, hr - tl, a, hr, a)
        bind k = k + 1
    }
    bind bh = fit_h(big, hr * 1.5, hr * 0.5)
    col(bigk, sat, 78.0, hs)
    daemon_text(big, cx - text_w(big, bh) / 2.0, cy - hr * 0.08, bh)
    bind sh = fit_h(small, hr * 1.5, hr * 0.2)
    ink(55.0)
    daemon_text(small, cx - text_w(small, sh) / 2.0, cy + hr * 0.4, sh)
    bind ev = Z[Z_EV]
    bind i = 0
    while i < len(ev) {
        bind cc = ev[i + 1]
        if cc < nr {
            bind age = t - ev[i + 2]
            bind p = age / 1.8
            bind gm = ring_geom2(cc, R, nr)
            bind rm = (gm[0] + gm[1]) / 2.0
            bind a = ring_spin(Z, cc) + ev[i + 3] * TAU
            bind x = px(cx, rm, a)
            bind y = py(cy, rm, a)
            col(hm[cc], sat, (1.0 - p) * (55.0 + 40.0 * ev[i + 4]), hs)
            if ev[i] == 0 {
                draw_circle(x, y, gm[2] * (0.25 + 1.5 * p))
                draw_circle(x, y, gm[2] * (0.1 + 0.9 * p))
            } else {
                square(x, y, gm[2] * (1.1 - 0.8 * p), a + p * 2.0)
                square(x, y, gm[2] * (0.6 - 0.4 * p), a - p * 2.0)
            }
        }
        bind i = i + 6
    }
}

# seven lanes, each a Daemon tile, a name, a current value and the last minute as a trace.
# ids are history strip numbers (hs_push), vals are the current readings as text.
# Notes (every pulse) are born at the playhead and scroll left at the trace's speed.
fn scope(Z, titles, letters, ids, vals) {
    bind W = Z[Z_W]
    bind H = Z[Z_H]
    bind t = Z[Z_T]
    bind hs = Z[Z_HS]
    bind sat = Z[Z_SAT]
    bind en = Z[Z_ENERGY]
    bind D = Z[Z_D]
    bind hst = D[D_HS]
    bind x0 = W * 0.22
    bind xph = W * 0.9
    bind dx = (xph - x0) / (HS_N - 1.0)
    bind sh = clamp((t - D[D_HT]) / 0.5, 0.0, 1.0) * dx
    bind amp = H * 0.05
    bind ts = H * 0.075
    bind c = 0
    while c < 7 {
        bind y = H * 0.15 + c * H * 0.118
        bind e = en[c]
        bind yb = y + amp
        bind ser = hst[ids[c]]
        col(c, sat * 0.6, 14.0, hs)
        draw_line(x0, yb, xph, yb)
        draw_line(x0, yb - amp * 2.0, xph, yb - amp * 2.0)
        bind k = 0
        bind ox = x0 - sh
        bind oy = yb - ser[0] * amp * 2.0
        while k < HS_N - 1 {
            bind nx = x0 + (k + 1) * dx - sh
            bind ny = yb - ser[k + 1] * amp * 2.0
            if ox >= x0 - 0.5 {
                col(c, sat * 0.8, 20.0 + 18.0 * ser[k + 1], hs)
                draw_line(nx, yb, nx, ny)
                col(c, sat, 44.0 + 36.0 * e, hs)
                draw_line(ox, oy, nx, ny)
            }
            bind ox = nx
            bind oy = ny
            bind k = k + 1
        }
        col(c, sat, 60.0 + 30.0 * e, hs)
        draw_line(ox, oy, xph, oy)
        tile(str_slice(letters, c, 1), W * 0.02, y - ts * 0.5, ts, 40.0 + 40.0 * e, c, sat, hs, 0.3 + e)
        col(c, sat, 68.0 + 20.0 * e, hs)
        daemon_text(titles[c], W * 0.02 + ts + 12.0, y - ts * 0.14, ts * 0.3)
        ink(62.0)
        daemon_text(vals[c], W * 0.02 + ts + 12.0, y + ts * 0.3, ts * 0.3)
        bind c = c + 1
    }
    ink(70.0)
    draw_line(xph, H * 0.04, xph, H * 0.97)
    draw_line(xph + 6.0, H * 0.04, xph + 6.0, H * 0.97)
    bind hist = Z[Z_HIST]
    bind i = 0
    while i < len(hist) {
        bind age = t - hist[i + 2]
        bind x = xph - age * dx * 2.0
        bind c = hist[i + 1]
        if c < 7 {
            if x > x0 {
                bind y = H * 0.15 + c * H * 0.118
                bind r = H * 0.009 + H * 0.012 * hist[i + 3]
                bind lit = 78.0 - age * 4.0
                if age < 0.4 { bind lit = 96.0 }
                col(c, sat, lit, hs)
                if hist[i] == 0 {
                    draw_circle(x, y, r)
                    if age < 0.9 { draw_circle(x, y, r * (1.0 + age * 3.0)) }
                } else {
                    square(x, y, r, age * 0.4)
                    if age < 0.9 { square(x, y, r * (1.0 + age * 2.0), age * 2.0) }
                }
            }
        }
        bind i = i + 4
    }
}

# the last n samples of a strip in a w x h box with its top-left at (x, y)
fn spark(x, y, w, h, ser, n, k, sat, lit, hs) {
    bind s0 = len(ser) - n
    bind dx = w / (n - 1.0)
    col(k, sat * 0.6, 18.0, hs)
    draw_line(x, y + h, x + w, y + h)
    bind i = 0
    while i < n - 1 {
        bind a = ser[s0 + i]
        bind b = ser[s0 + i + 1]
        col(k, sat * 0.8, 22.0 + 14.0 * b, hs)
        draw_line(x + (i + 1) * dx, y + h, x + (i + 1) * dx, y + h - b * h)
        col(k, sat, lit, hs)
        draw_line(x + i * dx, y + h - a * h, x + (i + 1) * dx, y + h - b * h)
        bind i = i + 1
    }
}

# a hatched bar: rail, then diagonal strokes for the filled part
fn hbar(x, y, w, frac, k, sat, lit, hs) {
    col(k, sat * 0.8, 38.0, hs)
    draw_line(x, y, x + w, y)
    draw_line(x, y - 6.0, x, y)
    draw_line(x + w, y - 6.0, x + w, y)
    bind fw = w * clamp(frac, 0.0, 1.0)
    col(k, sat, lit, hs)
    bind u = 0.0
    while u < fw {
        draw_line(x + u, y, x + u + 4.0, y - 6.0)
        bind u = u + 3.0
    }
}

fn bline(x0, y0, S, u0, v0, u1, v1) {
    draw_line(x0 + u0 * S, y0 + v0 * S, x0 + u1 * S, y0 + v1 * S)
}

# an axis-aligned rectangle in board units
fn brect(x0, y0, S, u0, v0, u1, v1) {
    bline(x0, y0, S, u0, v0, u1, v0)
    bline(x0, y0, S, u1, v0, u1, v1)
    bline(x0, y0, S, u1, v1, u0, v1)
    bline(x0, y0, S, u0, v1, u0, v0)
}

# diagonal hatch inside a board-unit rectangle; spacing in pixels
fn bhatch(x0, y0, S, u0, v0, u1, v1, sp) {
    bind w = (u1 - u0) * S
    bind h = (v1 - v0) * S
    bind xa = x0 + u0 * S
    bind ya = y0 + v0 * S
    bind d = sp
    while d < w + h {
        bind ax = xa
        bind ay = ya + d
        if d > h {
            bind ax = xa + d - h
            bind ay = ya + h
        }
        bind bx = xa + d
        bind by = ya
        if d > w {
            bind bx = xa + w
            bind by = ya + d - w
        }
        draw_line(ax, ay, bx, by)
        bind d = d + sp
    }
}

← Back to index