diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 18:06:30 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 19:01:23 -0300 |
| commit | e63b0624f57472d40af32a006c32cc47d403b822 (patch) | |
| tree | b7295da62acd96bc7aba425720eed95605526693 /anim/scenes | |
| parent | 318e16181a28725e218121363555580725d6d0d4 (diff) | |
| download | computeranim-e63b0624f57472d40af32a006c32cc47d403b822.tar.gz computeranim-e63b0624f57472d40af32a006c32cc47d403b822.zip | |
canim: what the review found; the band as two panels; list and sort by instruction
The first videos were reviewed frame by frame and the catalogue changed
with them. A lens is a drawing over the program column and its view over
the state column, so the stack keeps six slots, its window on the whole
frame. Operands are whole. list and sort are recorded by instruction
from main (record --from), so their registers strike, links reach nodes
and cells, rows that ran are marked and jumps are drawn. A call's node is
a projection of its return address; pins travel and keep their side; a
mark covers the bytes that changed, at the element's width; a syscall's
result is stored after the kernel returns it and every panel is of one
moment; fast passes are veiled; the clock stands still during a step;
captions get their reading time and a scene's first step comes by four
seconds.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'anim/scenes')
| -rw-r--r-- | anim/scenes/fib.zig | 4 | ||||
| -rw-r--r-- | anim/scenes/gallery.zig | 10 | ||||
| -rw-r--r-- | anim/scenes/list.zig | 30 | ||||
| -rw-r--r-- | anim/scenes/sort.zig | 29 | ||||
| -rw-r--r-- | anim/scenes/syscalls.zig | 8 | ||||
| -rw-r--r-- | anim/scenes/title.zig | 5 | ||||
| -rw-r--r-- | anim/scenes/zoom.zig | 9 |
7 files changed, 66 insertions, 29 deletions
diff --git a/anim/scenes/fib.zig b/anim/scenes/fib.zig index 27d959f..214f768 100644 --- a/anim/scenes/fib.zig +++ b/anim/scenes/fib.zig @@ -44,6 +44,7 @@ fn frame(s: *anim.Frame) void { // Pacing: the same three lines three times more. Seen once, so // hurried: down the first branch at a run, to the call that does not call. + says.line(s, "Down the first branch: each call the same three lines,\none frame deeper, `n` one less."); at.hurry(s, .line, rec.lineMoment(5, call(rec, 4).enter), .{}); says.line(s, "`fib(1)` needs no other call. Its answer leaves in `rax`,\nand its frame goes."); @@ -54,6 +55,7 @@ fn frame(s: *anim.Frame) void { // The pattern is known: the rest of the tree at a sprint, the tree its // subject, slowing into the last answers. at.hurry(s, .line, call(rec, 10).exit.?, .{ .pace = canim.theme.time.sprint }); + says.line(s, "The last answers come back up, each added to the one\nbefore it: `fib(5)` is 5, in `rax`, back in `main`."); at.walk(s, .line, call(rec, 0).exit.?); - s.wait(canim.theme.time.before_cut); + says.close(s); } diff --git a/anim/scenes/gallery.zig b/anim/scenes/gallery.zig index 12a592f..3b66a24 100644 --- a/anim/scenes/gallery.zig +++ b/anim/scenes/gallery.zig @@ -74,13 +74,17 @@ fn atoms(u: ui.Ui, p: *const Pages) void { // value y = 196; title(u, 64, y, "value"); - note(u, 200, y, "digit, small number, large number, small negative, string, unknown"); + note(u, 200, y, "digit, small number, large number, small negative, string, unknown; by a signature or a type: fd, bool, char"); 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 }); + x += 84; + x = u.typed(x, rows.baseline(y), 3, .{ .fd = "\"note\"" }, .{}) + 60; + x = u.typed(x, rows.baseline(y), 1, .boolean, .{}) + 60; + _ = u.typed(x, rows.baseline(y), 'A', .character, .{}); // arrow y = 270; @@ -242,8 +246,8 @@ fn rowsPage(u: ui.Ui, p: *const Pages) void { 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); + rows.callRow(panel, 0, 880, 0, "reverse+225", "", "list.c:22", true); + rows.callRow(panel, row, 880, 1, "main+42", "", "list.c:40", false); y = 600; title(u, 64, y, "line"); diff --git a/anim/scenes/list.zig b/anim/scenes/list.zig index 53df4d5..d6f1a76 100644 --- a/anim/scenes/list.zig +++ b/anim/scenes/list.zig @@ -15,8 +15,8 @@ const recordings = @import("recordings"); pub const background = canim.background; pub const scene = anim.Live(frame, struct {}); -/// Each a pigment, the same on its tag in the list and in the table. -const tracked = [_][]const u8{ "prev", "cur", "next" }; +/// The variables whose tags the nodes carry: the three the loop moves, and `head`. +const tracked = [_][]const u8{ "prev", "cur", "next", "head" }; fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.list); @@ -25,26 +25,34 @@ fn frame(s: *anim.Frame) void { // From reverse's first line (the list of three is built) to its last. var at = canim.cursor(s, rec, rec.lineMoment(18, reverse.enter)); // The nodes are the idea; a tag slides and an arrow grows after its strike. - at.levels = .{ .cpu = false, .idea = .data, .follow = t.move, .source_rows = 5 }; + at.levels = .{ .idea = .data, .follow = t.move, .source_rows = 10 }; const end = rec.lineMoment(27, reverse.enter); at.journey(.line, end); // The idea is the subject: the lens a size up, the nodes over the bytes they are. const split = canim.layout.split.subject; - const ctx = canim.context(s, at, .{ .split = split, .quiet = true }); - const list = canim.nodes(s, .{ .cursor = at, .stage = ctx.stage, .root = "head", .track = &tracked, .quiet = true }); + const ctx = canim.context(s, at, .{ .split = split }); + const list = canim.nodes(s, .{ .cursor = at, .stage = ctx.stage, .root = "head", .track = &tracked }); var says: canim.Narrator = .{}; const joins = ctx.ties(s); - canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, list, joins }); + // The nodes come in beside their bytes, one by one: three of them. + ctx.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, list, joins }, 3); says.line(s, "A list is nodes on the heap, each holding the address of the next.\nReversing it moves no node: it rewrites every `next`."); - // Three names are set up, then the first trip round the loop, in full. - at.walk(s, .line, rec.lineMoment(20, rec.lineMoment(24, reverse.enter))); + // Three names are set up. + const first_trip = rec.lineMoment(21, reverse.enter); + at.walk(s, .line, first_trip); + // The loop's caption leads the loop. says.line(s, "`next` remembers the way on, `cur->next` is turned round,\nand `prev` and `cur` each step along."); + const second_trip = rec.lineMoment(21, rec.lineMoment(24, first_trip)); + at.walk(s, .line, second_trip); // Pacing: the second trip is the same, so hurried; it keeps its rest. - at.hurry(s, .line, rec.lineMoment(20, rec.lineMoment(24, at.moment(s))), .{}); + says.line(s, "The second node, the same way, faster:\nits `next` turns back to the first."); + const third_trip = rec.lineMoment(21, rec.lineMoment(24, second_trip)); + at.hurry(s, .line, third_trip, .{}); // The third in full again: the last `next` turns, and `cur` runs off the end. - at.walk(s, .line, rec.lineMoment(26, at.moment(s))); + says.line(s, "The last node: its `next` turns too,\nand `cur` runs off the end of the list."); + at.walk(s, .line, rec.lineMoment(26, third_trip)); says.line(s, "`head` takes the last node: the same three nodes,\nin the same places, read the other way."); at.walk(s, .line, end); - s.wait(t.before_cut); + says.close(s); } diff --git a/anim/scenes/sort.zig b/anim/scenes/sort.zig index 6ad41f9..06b35a9 100644 --- a/anim/scenes/sort.zig +++ b/anim/scenes/sort.zig @@ -22,14 +22,14 @@ fn frame(s: *anim.Frame) void { while (rec.next(.over, rec.next(.over, start)) < rec.call("swap", 0).enter) start = rec.next(.over, start); var at = canim.cursor(s, rec, start); // The array is the idea; `i` and `j` are memory, and strike a beat before their tags slide. - at.levels = .{ .cpu = false, .idea = .data, .follow = t.quick, .source_rows = 10 }; + at.levels = .{ .idea = .data, .follow = t.quick, .source_rows = 10 }; // Its last compare: nothing larger is left of 20. const last = rec.call("swap", 9); const end = rec.next(.over, rec.next(.over, last.exit.?)); at.journey(.over, end); // The context is the instrumented program's: its registers are unmarked. const split = canim.layout.split.subject; - const ctx = canim.context(s, at, .{ .split = split, .quiet = true }); + const ctx = canim.context(s, at, .{ .split = split }); // The lens: the array as cells, and the two indices that walk it. const cells = canim.array(s, .{ .cursor = at, .stage = ctx.stage, .variable = "a", .indices = &.{ "i", "j" }, .focus = true }); var says: canim.Narrator = .{}; @@ -41,23 +41,40 @@ fn frame(s: *anim.Frame) void { }.step; const joins = ctx.ties(s); - canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, cells, joins }); + // The cells come in beside their bytes, one by one. + ctx.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, cells, joins }, 8); says.line(s, "`i` walks right. Everything left of it is in order,\nand 12 is not yet in its place."); // The compare: both cells framed. It is the swap's anticipation. at.walk(s, .over, rec.next(.over, start)); says.line(s, "While the one on the left is larger, they trade places,\nand `j` follows the smaller value down."); - // The caption of the step the scene is about stands a second longer. - s.wait(t.caption_lead); + // Nearer, for the swap: the cells at x1.5, the rest of the stage cleared. + var cam: canim.Camera = .{}; + const others = .{ ctx.source, ctx.disasm, ctx.registers, ctx.stack }; + // The drawing's view is cleared with the rest (it is not the subject). + const going = s.cursor; + s.cursor = going + t.quick; + s.play(.{ctx.stage.view.to(0)}, .{ .seconds = t.camera_clear, .ease = anim.ease.linear }); + s.cursor = going; + cam.go(s, split.band, 1.5, others); // Arcs: the two values fly past each other, one over, one under. swap(at, s, rec); at.walk(s, .over, rec.next(.over, at.moment(s))); + const coming = s.cursor; + cam.back(s, others); + const back_at = s.cursor; + s.cursor = coming + t.camera; + s.play(.{ctx.stage.view.to(1)}, .{ .seconds = t.cascade, .ease = anim.ease.linear }); + s.cursor = @max(s.cursor, back_at); // Pacing: the same again, so at a run; then the long way 5 has to go, // at a sprint; slowing for the last swap. + says.line(s, "And so on: each value is carried left\nuntil the one before it is not larger."); at.hurry(s, .over, rec.call("swap", 3).enter - 1, .{ .to = t.run, .settle = false }); at.hurry(s, .over, last.enter - 1, .{ .pace = t.sprint, .from = t.run }); + says.line(s, "The last swap: 20 goes one place left, past 26."); swap(at, s, rec); at.walk(s, .over, end); says.line(s, "Nothing larger is left of 20. The array is sorted."); - s.wait(t.before_cut - t.caption_lead); + says.close(s); + cam.apply(s); } diff --git a/anim/scenes/syscalls.zig b/anim/scenes/syscalls.zig index c981e58..6e2f0b9 100644 --- a/anim/scenes/syscalls.zig +++ b/anim/scenes/syscalls.zig @@ -24,8 +24,9 @@ const lines = [_][]const u8{ fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.hello); - // From main's first call to its last line. - var at = canim.cursor(s, rec, rec.lineMoment(6, rec.call("main", 0).enter)); + // From main's first line to its last: its first lines walked under the + // first caption, then a call a phrase. + var at = canim.cursor(s, rec, rec.call("main", 0).enter); at.journey(.line, rec.lineMoment(10, at.first)); const split = canim.layout.split.subject; at.levels = .{ .source_rows = 10 }; @@ -38,6 +39,7 @@ fn frame(s: *anim.Frame) void { const joins = ctx.ties(s); canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, ctx.source, ctx.disasm, kernel, joins }); says.line(s, "A program cannot open a file or reach the screen itself.\nIt asks the kernel, and waits."); + at.walk(s, .line, rec.lineMoment(6, at.first)); // One call a phrase: its caption while nothing moves, then the crossing. for (lines) |line| { @@ -45,5 +47,5 @@ fn frame(s: *anim.Frame) void { canim.syscalls.step(at, s, .line); s.wait(t.phrase_rest); } - s.wait(t.before_cut - t.phrase_rest); + says.close(s); } diff --git a/anim/scenes/title.zig b/anim/scenes/title.zig index 3646da4..d5af819 100644 --- a/anim/scenes/title.zig +++ b/anim/scenes/title.zig @@ -10,7 +10,7 @@ fn frame(s: *anim.Frame) void { const size = canim.theme.size.sans; const text = canim.theme.color.text; const series = canim.label(s, .{ .text = "How programs really run", .box = .{ .x = 64, .y = 138, .w = 900, .h = 48 }, .size = size.kicker, .color = text.dim }); - const title = canim.label(s, .{ .text = "Five small programs,\none step at a time", .box = .{ .x = 64, .y = 220, .w = 1792, .h = size.title_leading }, .face = .sans_bold, .size = size.title, .color = text.bright }); + const title = canim.label(s, .{ .text = "Four small programs,\none step at a time", .box = .{ .x = 64, .y = 220, .w = 1792, .h = size.title_leading }, .face = .sans_bold, .size = size.title, .color = text.bright }); const under = canim.label(s, .{ .text = "recorded as they ran: every line, register and byte", .box = .{ .x = 64, .y = 500, .w = 1792, .h = 60 }, .face = .sans, .size = size.subtitle, .color = text.dim }); const marks = canim.legend(s, .{ .box = canim.theme.cols(0, 12, 512, 256) }); const t = canim.theme.time; @@ -18,5 +18,6 @@ fn frame(s: *anim.Frame) void { s.play(.{under.fadeIn()}, .{ .seconds = t.move }); s.wait(t.beat); s.play(.{marks.fadeIn()}, .{ .seconds = t.travel }); - s.wait(4); + // Ten marks to learn: long enough to read them all. + s.wait(8); } diff --git a/anim/scenes/zoom.zig b/anim/scenes/zoom.zig index 5ea2346..ee24e7d 100644 --- a/anim/scenes/zoom.zig +++ b/anim/scenes/zoom.zig @@ -18,7 +18,6 @@ pub const scene = anim.Live(frame, struct {}); fn frame(s: *anim.Frame) void { const rec = canim.open(recordings.steps); - const t = canim.theme.time; // fib(5), about to run line 6: `return fib(n-1) + fib(n-2);`. Its first call is fib(4). const call = rec.call("fib", 1); var at = canim.cursor(s, rec, rec.lineMoment(6, rec.call("fib", 0).enter)); @@ -40,11 +39,15 @@ fn frame(s: *anim.Frame) void { says.line(s, "`call` writes eight bytes on the stack: the way back.\nThe new frame saves `rbp` under them, then its own `n`."); // Nearer, for the bytes: the stack alone, twice the size. cam.go(s, split.stack, 2, .{ ctx.source, ctx.disasm, ctx.registers, ctx.backtrace }); + // Under the camera the stack holds still: six free words above rsp for the new frame. + ctx.stage.holdStack(s, at.moment(s), 6); at.walk(s, .moment, call.enter + 4); + s.wait(canim.theme.time.beat); + ctx.stage.releaseStack(s); cam.back(s, .{ ctx.source, ctx.disasm, ctx.registers, ctx.backtrace }); - says.line(s, "Eleven instructions and three words of stack later\n`fib(4)` begins: the same lines, one call deeper."); + says.line(s, "Nine instructions and three words of stack later\n`fib(4)` begins: the same lines, one call deeper."); at.walk(s, .line, end); - s.wait(t.before_cut); + says.close(s); cam.apply(s); } |
