diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 16:05:20 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 16:43:58 -0300 |
| commit | 165bb6c1344b98de7bef1d3c2b72147b4a40797a (patch) | |
| tree | 0e70e6222700063f604f78673f6ab3a5bfb9242d /anim/scenes/gallery.zig | |
| parent | 66a2a7cf733f6abc1f79561c52d901ce67019fb1 (diff) | |
| download | computeranim-165bb6c1344b98de7bef1d3c2b72147b4a40797a.tar.gz computeranim-165bb6c1344b98de7bef1d3c2b72147b4a40797a.zip | |
canim: the renderer speaks the design language
The blocks, their states and the tokens carry the catalogue's names:
atoms in ui, chain/reg/slot in rows, insn with its line column, jump lane
and annotations (read, write, taken or not, a call with its arguments, a
return, a syscall) in disasm, bytes and hexdump with field paper and the
reading column, the three splits and relayout in stage, the ties (thread,
link and pin, projection, echo). A lens is a band over the whole context,
its drawing left and its bytes right. Frames' spans on the stack, each
instruction's line and a callee's parameter count come from the tracer.
A gallery scene draws every block; the test compares six of its pages
with pictures kept in test/gallery, drawn from a recording kept there
too. The scenes are ported; the motion checks report no pop and no
metronome in any of them.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'anim/scenes/gallery.zig')
| -rw-r--r-- | anim/scenes/gallery.zig | 301 |
1 files changed, 301 insertions, 0 deletions
diff --git a/anim/scenes/gallery.zig b/anim/scenes/gallery.zig new file mode 100644 index 0000000..12a592f --- /dev/null +++ b/anim/scenes/gallery.zig @@ -0,0 +1,301 @@ +//! The gallery: every block of the design language (design/README.md, the +//! vocabulary) drawn in its states, a page at a time, under the +//! catalogue's names. The test of the catalogue is that this shows what it +//! says; `test/gallery.script` compares its pages with the pictures in +//! `test/gallery/`. +//! +//! 0 s atoms: address, value, arrow, byte, mark, plaque, pin, bracket, tag +//! 1 s rows: chain, reg (rip with the flags), slot, line, bytes, call +//! 2 s the frame at rest, `beside`: every panel, the thread (mock 9) +//! 3.6 s a step, mid-way: struck, read, projection, echo (mock 10) +//! 6 s `subject` (mock 11); 8 s `none`, with the backtrace +const std = @import("std"); +const sk = @import("sketch"); +const anim = @import("anim"); +const canim = @import("canim"); +const recordings = @import("recordings"); + +pub const background = canim.background; +pub const scene = anim.Live(frame, struct {}); + +const ui = canim.ui; +const rows = canim.rows; +const theme = canim.theme; +const t = theme.color.text; +const region = theme.color.region; + +/// The pages of atoms and rows, drawn from a moment of the list's recording. +const Pages = struct { + rec: *canim.Recording, + moment: u64, + box: canim.Rect = .{ .x = 0, .y = 0, .w = 1920, .h = 1080 }, + + pub fn draw(p: *const Pages, f: *sk.Frame, at: anim.Placed) void { + const u: ui.Ui = .{ .f = f, .at = at }; + if (at.t < 1) atoms(u, p) else if (at.t < 2) rowsPage(u, p); + } +}; + +fn title(u: ui.Ui, x: f32, y: f32, name: []const u8) void { + u.text(.sans_medium, theme.size.sans.tag, x, y, name, t.primary); +} + +fn note(u: ui.Ui, x: f32, y: f32, words: []const u8) void { + u.text(.sans, theme.size.sans.micro, x, y, words, t.faint); +} + +fn atoms(u: ui.Ui, p: *const Pages) void { + const m = p.rec.moment(p.moment); + const regs = (m.regs(p.rec.tid) catch null).?; + const row = theme.metric.context.row; + title(u, 64, 40, "1 atoms"); + // address + var y: f32 = 80; + title(u, 64, y, "address"); + note(u, 200, y, "plain, lead, name, rwx; struck, read, held"); + y += 12; + var x: f32 = 64; + x = u.address(x, rows.baseline(y), 0x407010, .{ .ink = ui.rgb(region.heap) }) + 40; + for ([_]u64{ 0x402470, 0x402481, 0x402495 }, 0..) |a, i| _ = u.address(x, rows.baseline(y + @as(f32, @floatFromInt(i)) * row), a, .{ .ink = ui.rgb(region.code_), .lead = ui.shared(&.{ 0x402470, 0x402495 }) }); + x += 120; + x = u.address(x, rows.baseline(y), regs.rip, .{ .ink = ui.rgb(region.code_), .name = p.rec.strings.get(regs.rip) orelse "" }) + 40; + x = u.address(x, rows.baseline(y), 0x7ffff7ff0000, .{ .ink = ui.rgb(region.data), .rwx = true }) + 40; + const struck: ui.Heat = .{ .level = 1, .solid = 1 }; + const cell: canim.Rect = .{ .x = x, .y = y, .w = 6 * 12, .h = row }; + _ = u.written(cell, struck, 9); + _ = u.address(x, rows.baseline(y), 0x407050, .{ .ink = ui.rgb(t.ink), .face = .mono_bold }); + x += 112; + u.read(.{ .x = x, .y = y, .w = 72, .h = row }, 1); + _ = u.address(x, rows.baseline(y), 0x407058, .{ .ink = ui.rgb(region.heap) }); + x += 112; + _ = u.written(.{ .x = x, .y = y, .w = 72, .h = row }, .ember, 9); + _ = u.address(x, rows.baseline(y), 0x407030, .{ .ink = ui.rgb(region.heap) }); + + // value + y = 196; + title(u, 64, y, "value"); + note(u, 200, y, "digit, small number, large number, small negative, string, unknown"); + y += 12; + x = 64; + for ([_]u64{ 4, 0x21, 0x8dea2ff80214, std.math.maxInt(u64) }) |v| x = u.value(x, rows.baseline(y), v, false, .{}) + 60; + u.text(.mono, theme.size.mono.context, x, rows.baseline(y), "\"./list\"", theme.color.string); + x += 140; + u.unknown(.{ .x = x, .y = y, .w = 24, .h = row }); + + // arrow + y = 270; + title(u, 64, y, "arrow, hop"); + note(u, 240, y, "points, holds, more"); + y += 12; + _ = u.arrow(64, y + row / 2, .points); + _ = u.arrow(130, y + row / 2, .holds); + _ = u.arrow(196, y + row / 2, .more); + _ = u.arrow(320, y + row / 2, .points); + _ = u.address(350, rows.baseline(y), 0x407030, .{ .ink = ui.rgb(region.heap) }); + + // byte + y = 344; + title(u, 64, y, "byte"); + note(u, 200, y, "number, pointer, allocator, unread; pad"); + y += 12; + { + var values: [16]u8 = .{ 9, 0, 0, 0, 0, 0, 0, 0, 0x30, 0x70, 0x40, 0, 0, 0, 0, 0 }; + var known: [16]bool = @splat(true); + rows.bytes(u, y, 0x407050, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .number }, .{ .first = 8, .len = 8, .kind = .pointer } }, region.heap, 4, true, m); + values = .{ 0, 0, 0, 0, 0, 0, 0, 0, 0x21, 0, 0, 0, 0, 0, 0, 0 }; + rows.bytes(u, y + row, 0x407060, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .unread }, .{ .first = 8, .len = 8, .kind = .allocator } }, region.heap, 4, false, m); + } + + // mark, in the context and in a lens's cell + y = 442; + title(u, 64, y, "mark"); + note(u, 200, y, "in the context: current, armed, struck, held, read, trail, unknown"); + y += 12; + u.current(.{ .x = 64, .y = y, .w = 200, .h = row }, theme.metric.plaque.line, 0); + u.text(.mono_bold, theme.size.mono.context, 64 + 46 - 24, rows.baseline(y), "21", t.ink); + x = 300; + for ([_]ui.Heat{ .{ .arm = 1 }, struck, .ember }) |h| { + const ink = u.written(.{ .x = x, .y = y, .w = 72, .h = row }, h, 9); + _ = u.address(x, rows.baseline(y), 0x407070, .{ .ink = if (ink) |i| i.ink else ui.rgb(region.heap), .face = if (ink) |i| i.face else .mono }); + x += 120; + } + u.read(.{ .x = x, .y = y, .w = 72, .h = row }, 1); + _ = u.address(x, rows.baseline(y), 0x407098, .{ .ink = ui.rgb(region.heap) }); + x += 120; + for (0..3) |k| u.trail(x + @as(f32, @floatFromInt(k)) * 16, y, k); + x += 70; + u.unknown(.{ .x = x, .y = y, .w = 24, .h = row }); + y += 40; + note(u, 64, y, "in a lens's cell: armed, struck, held, read, allocated, freed, fault, attention, kernel"); + y += 12; + x = 64; + const cell_size = [2]f32{ 72, 44 }; + for ([_]ui.Heat{ .{ .arm = 1 }, struck, .ember }, [_][]const u8{ "4", "9", "16" }) |h, digits| { + const r: canim.Rect = .{ .x = x, .y = y, .w = cell_size[0], .h = cell_size[1] }; + const ink = u.cellWritten(r, h, theme.color.raised); + u.label(ink.face, theme.size.mono.small, r, .center, digits, ink.ink); + x += 100; + } + { + const r: canim.Rect = .{ .x = x, .y = y, .w = cell_size[0], .h = cell_size[1] }; + u.fill(r, theme.color.raised); + u.cellRead(r, 1); + u.label(.mono, theme.size.mono.small, r, .center, "25", t.primary); + x += 100; + const a: canim.Rect = .{ .x = x, .y = y, .w = cell_size[0], .h = cell_size[1] }; + u.fill(a, theme.mark(.allocated).ember); + u.frame(a, theme.mark(.allocated).solid, theme.stroke.line); + x += 100; + u.dashedFrame(.{ .x = x, .y = y, .w = cell_size[0], .h = cell_size[1] }, theme.mark(.freed).solid, theme.stroke.line); + x += 100; + const fault: canim.Rect = .{ .x = x, .y = y, .w = 120, .h = cell_size[1] }; + u.fill(fault, theme.mark(.fault).solid); + u.fill(.{ .x = fault.x + 8, .y = fault.y + 8, .w = fault.w - 16, .h = fault.h - 16 }, t.ink); + u.label(.mono_bold, theme.size.mono.context, fault, .center, "SIGSEGV", t.bright); + x += 148; + u.frame(.{ .x = x, .y = y, .w = cell_size[0], .h = cell_size[1] }, theme.mark(.attention).solid, theme.stroke.line); + x += 100; + const k: canim.Rect = .{ .x = x, .y = y, .w = 120, .h = cell_size[1] }; + u.fill(k, theme.color.kernel); + u.label(.mono_bold, theme.size.mono.context, k, .center, "read", theme.color.on_kernel.ink); + } + + // plaque, pin, bracket + y = 624; + title(u, 64, y, "plaque"); + note(u, 200, y, "gold: rip 54, a line 50, the pc 24; chip"); + y += 12; + u.fill(.{ .x = 64, .y = y, .w = theme.metric.plaque.rip, .h = row }, theme.mark(.current).solid); + u.text(.mono_bold, theme.size.mono.context, 74, rows.baseline(y), "rip", t.ink); + u.fill(.{ .x = 140, .y = y, .w = theme.metric.plaque.line, .h = row }, theme.mark(.current).solid); + u.text(.mono_bold, theme.size.mono.context, 140 + 46 - 24, rows.baseline(y), "21", t.ink); + u.fill(.{ .x = 212, .y = y, .w = theme.metric.plaque.pc, .h = row }, theme.mark(.current).solid); + sk.draw.polygon(u.f, &.{ .{ 230, y + 12 }, .{ 220, y + 6 }, .{ 220, y + 18 } }, u.at.pen(.{ .fill = ui.rgb(t.ink) })); + u.chip(.{ .x = 260, .y = y + 2, .w = 32, .h = 20 }); + u.text(.mono_bold, theme.size.mono.context, 264, rows.baseline(y), "PF", t.bright); + + y = 698; + title(u, 64, y, "pin"); + note(u, 140, y, "row; under; a count after three names"); + y += 12; + u.pinRow(64, y, &.{ "rsp", "rbp" }, region.stack); + u.pinRow(64, y + row, &.{ "rax", "rdi", "rsi", "r8" }, region.heap); + u.fill(.{ .x = 400, .y = y - 20, .w = 116, .h = 20 }, theme.color.raised); + u.pinUnder(458, y, &.{ "rax", "rdi" }, region.heap, theme.size.mono.context); + + y = 698; + title(u, 700, y, "bracket"); + note(u, 800, y, "quiet, tie, thread"); + y += 12; + u.bracket(712, y, y + 2 * row, ui.mix(region.heap, theme.color.page, 0.6), theme.metric.bracket.quiet, 1, false); + u.bracket(762, y, y + 2 * row, theme.mark(.read).solid, theme.metric.bracket.tie, 1, false); + u.bracket(812, y, y + 2 * row, theme.mark(.current).solid, theme.metric.bracket.thread, 1, false); + + // tag + y = 800; + title(u, 64, y, "tag"); + note(u, 120, y, "focus; a note; a legend"); + y += 12; + _ = (u.moved(64, y)).panel(560, 56, "the list", .{ .focus = true, .note = "a note, ranged right" }); + _ = (u.moved(660, y)).panel(880, 56, "registers", .{ .legend = &canim.contextLegend }); +} + +fn rowsPage(u: ui.Ui, p: *const Pages) void { + const m = p.rec.moment(p.moment); + const regs = (m.regs(p.rec.tid) catch null).?; + const row = theme.metric.context.row; + title(u, 64, 40, "2 rows"); + var y: f32 = 80; + title(u, 64, y, "chain"); + note(u, 160, y, "as far as it points; cut where its room ends: a string first, then `more`"); + y += 12; + _ = rows.chain(u, 64, y, m, regs.rbp, 880, .{}); + _ = rows.chain(u, 64, y + row, m, regs.rbp, 420, .{}); + _ = rows.chain(u, 64, y + 2 * row, m, regs.r12, 880, .{}); + _ = rows.chain(u, 64, y + 3 * row, m, regs.r12, 320, .{}); + + y = 214; + title(u, 64, y, "reg"); + note(u, 140, y, "plain, struck, held, read; rip with the flags"); + y += 12; + var panel = u.moved(64, y); + _ = rows.reg(panel, 0, 880, "rsi", m, regs.rsi, .{}); + _ = rows.reg(panel, row, 880, "rdi", m, regs.rdi, .{ .first = .{ .level = 1, .solid = 1 } }); + _ = rows.reg(panel, 2 * row, 880, "rax", m, regs.rax, .{ .first = .ember }); + _ = rows.reg(panel, 3 * row, 880, "rbp", m, regs.rbp, .{ .read = 1, .read_shows = 1 }); + rows.rip(panel, 4 * row, 880, m, regs.rip, regs.eflags, 1 << 6, 1, 0); + + y = 380; + title(u, 64, y, "slot"); + note(u, 140, y, "its pins in the lane; the chain from 122; `call` spans at the right"); + y += 12; + panel = u.moved(64, y); + for (0..4) |i| { + const addr = regs.rsp + 8 * i; + _ = rows.slot(panel, @as(f32, @floatFromInt(i)) * row, 880, m, addr, if (i == 0) &.{ "rsp", "rbp" } else &.{}, 1, .{ .lead = ui.shared(&.{ regs.rsp, regs.rsp + 24 }), .first = if (i == 2) .ember else .none }); + } + rows.span(panel, 880, 0, 2 * row, "reverse", true, false); + rows.span(panel, 880, 2 * row, 4 * row, "main", false, true); + + y = 520; + title(u, 64, y, "call"); + note(u, 140, y, "row, in a backtrace"); + y += 12; + panel = u.moved(64, y); + rows.callRow(panel, 0, 880, 0, "reverse+225", "list.c:22", true); + rows.callRow(panel, row, 880, 1, "main+42", "", false); + + y = 600; + title(u, 64, y, "line"); + note(u, 140, y, "current, trail, plain; cut at 67 characters"); + y += 12; + panel = u.moved(64, y); + const plain = " cur->next = prev;"; + const styles: [128]u8 = @splat(0); + rows.line(panel, 0, 880, 22, plain, styles[0..plain.len], .{ .current = 0 }); + rows.line(panel, row, 880, 21, " node *next = cur->next;", styles[0..31], .{ .trail = 0 }); + rows.line(panel, 2 * row, 880, 20, " while (cur) {", styles[0..17], .{ .trail = 1 }); + const long = " a line of source longer than the panel has room for, which is cut at its end"; + rows.line(panel, 3 * row, 880, 9, long, styles[0..long.len], .plain); + + y = 750; + title(u, 64, y, "bytes"); + note(u, 160, y, "runs from the types; marks per run: struck, read, held"); + y += 12; + panel = u.moved(976, y); + var values: [16]u8 = .{ 12, 0, 0, 0, 0, 0, 0, 0, 0x10, 0x70, 0x40, 0, 0, 0, 0, 0 }; + var known: [16]bool = @splat(true); + rows.bytes(panel, 0, 0x407030, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .number, .read = 1 }, .{ .first = 8, .len = 8, .kind = .pointer, .heat = .{ .level = 1, .solid = 1 } } }, region.heap, 4, true, m); + values[8] = 0x50; + rows.bytes(panel, row, 0x407050, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .number }, .{ .first = 8, .len = 8, .kind = .pointer, .heat = .ember } }, region.heap, 4, true, m); + known = @splat(false); + rows.bytes(panel, 2 * row, 0x407060, &values, &known, &.{ .{ .first = 0, .len = 8, .kind = .unread }, .{ .first = 8, .len = 8, .kind = .unread } }, region.heap, 4, false, m); +} + +fn frame(s: *anim.Frame) void { + const rec = canim.open(recordings.gallery); + const reverse = rec.call("reverse", 0); + // In the loop, about to read `cur->next`. + const rest = rec.lineMoment(21, rec.lineMoment(24, reverse.enter)); + const pages = canim.add(s, Pages{ .rec = rec, .moment = rest }); + s.play(.{pages.fadeIn()}, .{ .seconds = 0 }); + + const at = canim.cursor(s, rec, rest); + const ctx = canim.context(s, at, .{ .split = canim.layout.split.beside, .quiet = true }); + const list = canim.nodes(s, .{ .cursor = at, .stage = ctx.stage, .root = "head", .track = &.{ "prev", "cur", "next" }, .quiet = true }); + const joins = ctx.ties(s); + const says = canim.caption(s, "The gallery: the frame, at rest. Every panel, the thread,\nthe lens beside it: the list and the bytes it is drawn from."); + const panels = .{ ctx.clock, ctx.registers, ctx.stack, ctx.backtrace, ctx.source, ctx.disasm, list, joins, says }; + s.wait(2); + var all: [panels.len]anim.Animation = undefined; + inline for (panels, 0..) |o, i| all[i] = o.fadeIn(); + s.play(all, .{ .seconds = 0 }); + // A step at 3 s, its strikes and ties at about 3.6. + s.wait(3 - s.cursor); + at.walk(s, .line, rec.next(.line, rest)); + s.wait(5 - s.cursor); + ctx.stage.relayout(s, canim.layout.split.subject); + s.wait(7 - s.cursor); + ctx.stage.relayout(s, canim.layout.split.none); + s.wait(9 - s.cursor); +} |
