summaryrefslogtreecommitdiff
path: root/anim/scenes/intro_code.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-12 11:32:59 -0300
committerGabriel Schneider <[email protected]>2026-11-12 13:19:32 -0300
commiteab50d1c040774351f332a1568fa332c377860bd (patch)
tree0e727f9bf323e49aa6a2f55bb4fabd166aa9a492 /anim/scenes/intro_code.zig
parent38971edd9b49a802e6e726fb51d162df1bf58b83 (diff)
downloadcomputeranim-eab50d1c040774351f332a1568fa332c377860bd.tar.gz
computeranim-eab50d1c040774351f332a1568fa332c377860bd.zip
canim: the introduction as one video, with a chapter on registers
From the user. One scene, intro, in four chapters: memory, registers, the stack, code and meaning (210 s). The registers chapter builds the panel before the stack needs it: sixteen rows with their chains, rip pinned on the code band and rsp and rbp on the stack's, rdi opened into its parts as mov edi changes one byte, a call to malloc stepped over with its result in rax, the registers a scene never changes folded. The chapters join at seams that say their title and keep it as the clock's label; one recording (from push(9), no agent, the heap from --heap) and one clock. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNCKgYCGiANnEwcEQxa
Diffstat (limited to 'anim/scenes/intro_code.zig')
-rw-r--r--anim/scenes/intro_code.zig106
1 files changed, 32 insertions, 74 deletions
diff --git a/anim/scenes/intro_code.zig b/anim/scenes/intro_code.zig
index eb66554..7682842 100644
--- a/anim/scenes/intro_code.zig
+++ b/anim/scenes/intro_code.zig
@@ -1,44 +1,30 @@
-//! The introduction, chapter III: code and meaning (design/motion.md, "A
-//! scene: the introduction", III1 to III5; mocks 32, 33, 36). On the
+//! The introduction, chapter IV: code and meaning (design/motion.md, "A
+//! scene: the introduction", IV1 to IV5; mocks 32, 33, 36), a function the
+//! scene `intro` calls after III's seam. On the
//! `intro` recording at the load in `reverse` (line 21, `node *next =
//! cur->next;`, the instruction that reads `cur->next`): the code's bytes
//! as a dump row, that instruction's four framed; `decode`d into its row
//! of `aligned` (`interleaved`), its neighbours at a run, each line level
//! with its run; then `align` to `columns`; then the working frame with the
//! nodes drawn from the heap's bytes, each pane's minimap drawing itself
-//! last; then the map (`surface`). It opens on chapter II's last picture,
-//! its state column staying veiled until the decoded code spans it. The
+//! last; then the map (`surface`). It opens on chapter III's last picture,
+//! its state column staying veiled until the decoded code spans it, and
+//! the one clock steps on to the load as the working frame assembles. The
//! texts `above` the aligned panel, then below the working frame, the
//! last landing before the map surfaces under it.
const std = @import("std");
const anim = @import("anim");
const sk = @import("sketch");
const canim = @import("canim");
-const recordings = @import("recordings");
-const two = @import("intro_stack.zig");
-
-pub const background = canim.background;
-pub const scene = anim.Live(frame, struct {});
+const intro = @import("intro.zig");
+const stack = @import("intro_stack.zig");
const t = canim.theme.time;
+const f = intro.f;
+const run = intro.run;
+const on = intro.on;
-fn f(frames: f32) f32 {
- return frames / 60;
-}
-
-fn run(s: *anim.Frame, v: anim.Value, frames: f32) void {
- s.play(.{v.to(0)}, .{ .seconds = 0 });
- s.play(.{v.to(frames)}, .{ .seconds = f(frames), .ease = anim.ease.linear });
-}
-
-fn on(rec: *canim.Recording, from: u64, text: []const u8) u64 {
- var buf: [256]u8 = undefined;
- var i = from;
- while (i < rec.end()) : (i += 1) if (rec.instruction(i, rec.register(i, "rip"), &buf)) |here| if (std.mem.indexOf(u8, here.text, text) != null) return i;
- return from;
-}
-
-/// The page over a part not drawn yet (a pane's minimap until III4).
+/// The page over a part not drawn yet (a pane's minimap until IV4).
const Page = struct {
box: canim.Rect,
pub fn draw(c: *const Page, fr: *sk.Frame, placed: anim.Placed) void {
@@ -46,46 +32,11 @@ const Page = struct {
}
};
-/// Chapter II's last picture (scenes/intro_stack.zig, its layout and texts
-/// as there): its registers and stack, a context of their own at II's last
-/// moment, the window held as II holds it; main's rows, faint, and reverse's
-/// first rows under them; II4's text dimmed and II5's.
-fn lastOfTwo(s: *anim.Frame, rec: *canim.Recording) struct { state: [2]anim.Obj, code: [2]anim.Obj, texts: [2]anim.Obj } {
- const enter = rec.call("reverse", 0).enter;
- const last = enter + 3;
- var at = canim.cursor(s, rec, enter);
- at.journey(.moment, last);
- at.levels = .{ .fire = .disasm, .source_rows = 14, .introduction = true };
- // As II walked it: its push, `mov` and `sub` the steps behind its last moment.
- at.jumpWalked(s, enter, last);
- var split = canim.layout.split.none;
- split.backtrace.h = 0;
- const ctx = canim.context(s, at, .{ .split = split });
- const g = two.layout(ctx.stage, rec, enter);
- two.hold(s, ctx.stage, enter);
- const stack = canim.add(s, canim.Stack{ .cursor = ctx.cursor, .stage = ctx.stage });
- // (Placed at the origin: it draws at its own box.)
- const caller = s.custom(s.new(canim.descent.Caller{ .rec = rec, .at = enter, .call = rec.register(enter - 1, "rip"), .box = g.caller, .in = s.value(999), .faint = s.value(1) }), .{ .x = -640, .y = -360, .scale = canim.ui.scale });
- const left = canim.theme.canvas.margin_x;
- const said = [2]canim.Aside{
- .{ .text = two.texts[two.texts.len - 2], .x = left, .level = g.span_y, .dim = s.value(1) },
- .{ .text = two.texts[two.texts.len - 1], .x = left, .level = g.registers_y, .dim = s.value(0) },
- };
- var texts: [2]anim.Obj = undefined;
- for (said, &texts) |a, *o| o.* = s.custom(s.new(a), .{ .x = -640, .y = -360, .scale = canim.ui.scale });
- for ([_]anim.Obj{ ctx.registers, stack, caller, ctx.disasm, texts[0], texts[1] }) |o| s.play(.{o.fadeIn()}, .{ .seconds = 0 });
- return .{ .state = .{ ctx.registers, stack }, .code = .{ caller, ctx.disasm }, .texts = texts };
-}
-
/// The variables whose tags the nodes carry, as the list scene's.
const tracked = [_][]const u8{ "prev", "cur", "next", "head" };
-fn frame(s: *anim.Frame) void {
- const rec = canim.open(recordings.intro);
- // list.c's types as the pass would tell them: the recording is of the
- // plain build, which tells none (its locals are the debug info's).
- rec.declare("head", "*`struct node`");
- rec.declare("`struct node`", "struct(16){value@0:i64;next@8:*`struct node`;}");
+/// From the seam's opening (the cursor), on chapter III's last picture.
+pub fn chapter(s: *anim.Frame, rec: *canim.Recording, three: stack.Three, title: intro.Title) void {
const reverse = rec.call("reverse", 0);
// The load: `cur->next` read, line 21's second instruction.
const moment = on(rec, rec.lineMoment(21, reverse.enter), "[rax + 8]");
@@ -100,9 +51,8 @@ fn frame(s: *anim.Frame) void {
for (code[0..insn.len], 0..) |b, k| hex.print(s.arena, "{s}{x:0>2}", .{ if (k > 0) " " else "", b }) catch {};
const text = std.mem.replaceOwned(u8, s.arena, insn.text, "qword ptr ", "") catch insn.text;
- // Chapter II's last picture, which this chapter opens on (II's own
- // context at II's last moment, laid out as II has it, under this one's).
- const opening = lastOfTwo(s, rec);
+ const opening = three;
+ const begun = s.cursor;
var at = canim.cursor(s, rec, moment);
at.journey(.moment, moment + 1);
@@ -110,6 +60,8 @@ fn frame(s: *anim.Frame) void {
const ctx = canim.context(s, at, .{ .split = canim.layout.split.subject });
const list = canim.nodes(s, .{ .cursor = at, .stage = ctx.stage, .root = "head", .track = &tracked, .named = true });
ctx.map.add(s, canim.Nodes{ .cursor = at, .stage = ctx.map.stage, .root = "head", .track = &tracked, .named = true });
+ // The one clock (II's and III's cursor), over this context's map: it takes the old one's place at once, the same picture.
+ const clock = intro.clock(s, rec, opening.at, ctx);
// The relations, and rax's link to the node as III3 names it.
const joins, const rax_link = ctx.tiesWith(s, "rax", 1.0);
@@ -122,19 +74,18 @@ fn frame(s: *anim.Frame) void {
const al = s.new(canim.Aligned.init(s, rec, moment));
const panel = s.custom(al, .{ .x = -640, .y = -360, .scale = canim.ui.scale });
+ s.cursor = begun;
s.play(.{panel.fadeIn()}, .{ .seconds = 0 });
// Texts above the panel that spans both columns: twice a beside's line (two lines in the band of 120).
var asides: canim.Asides = .{ .wrap = 2 * 40 };
const left = canim.theme.canvas.margin_x;
const above = canim.theme.canvas.stage.y + 40;
- // From II's last picture: its texts and code give way (12 f, 18 f); its
- // state column stays, veiled at 50%, until the decoded code takes both columns.
- s.wait(t.beat);
- s.play(.{ opening.texts[0].fadeOut(), opening.texts[1].fadeOut() }, .{ .seconds = t.caption_out, .ease = canim.ease.exit });
- s.cursor -= t.caption_out;
- s.play(.{ opening.code[0].fadeOut(), opening.code[1].fadeOut(), opening.state[0].move(.{ .opacity = 0.5 }), opening.state[1].move(.{ .opacity = 0.5 }) }, .{ .seconds = f(18), .ease = anim.ease.linear });
- s.wait(t.beat);
+ // The opening, from III's last picture (its texts gone at the seam): its code gives
+ // way (18 f); its state column stays, veiled at 50%, until the decoded code takes both
+ // columns; the clock and its label stay, under the stage.
+ s.play(.{ opening.code[0].fadeOut(), opening.code[1].fadeOut(), opening.code[2].fadeOut(), opening.state[0].move(.{ .opacity = 0.5 }), opening.state[1].move(.{ .opacity = 0.5 }) }, .{ .seconds = f(18), .ease = anim.ease.linear });
+ title.out(s);
// III1: the code's bytes, one instruction's framed.
asides.say(s, std.fmt.allocPrint(s.arena, "Code is bytes too: `{s}` is one instruction.", .{hex.items}) catch "", left, above);
@@ -171,7 +122,14 @@ fn frame(s: *anim.Frame) void {
s.play(.{ strips[0].fadeIn(), strips[1].fadeIn(), strips[2].fadeIn(), strips[3].fadeIn() }, .{ .seconds = 0 });
s.play(.{ ctx.source.fadeIn(), ctx.disasm.fadeIn(), panel.fadeOut() }, .{ .seconds = f(12), .ease = anim.ease.linear });
var says: canim.Narrator = .{};
- canim.establish(s, .{ ctx.clock, ctx.registers, ctx.stack, joins });
+ // The one clock goes on, forward, to IV's moment: the chapters before's cursor taken
+ // there (its panels gone), the count changing and its gold fading in as a step's (12 f).
+ const later: canim.Plan = .{ .advance = 0, .travel = 0, .total = t.quick };
+ const counted = s.cursor;
+ s.play(.{ opening.clock.fadeOut(), clock.fadeIn() }, .{ .seconds = 0 });
+ opening.at.step(s, moment, later, later.total);
+ s.cursor = counted;
+ canim.establish(s, .{ ctx.registers, ctx.stack, joins });
// III3: the node it reads, as bytes and drawn: the band comes in, its
// elements rising from their bytes. No camera: at x1.5 the drawing's
// nodes and its bytes do not both fit the frame, and the band is whole at x1.