summaryrefslogtreecommitdiff
path: root/anim/src/aside.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/src/aside.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/src/aside.zig')
-rw-r--r--anim/src/aside.zig74
1 files changed, 69 insertions, 5 deletions
diff --git a/anim/src/aside.zig b/anim/src/aside.zig
index c2c0ef8..66c8ce7 100644
--- a/anim/src/aside.zig
+++ b/anim/src/aside.zig
@@ -29,11 +29,13 @@ pub const Aside = struct {
level: f32,
/// 0 newest, 1 the account (no paper, `dim`).
dim: anim.Value,
+ /// Units it has glided down from `level` to make room for a newer one.
+ drop: ?anim.Value = null,
/// Characters a line, at most.
wrap: usize = chars,
pub fn draw(a: *const Aside, f: *sk.Frame, placed: anim.Placed) void {
- const u = (ui.Ui{ .f = f, .at = placed }).moved(0, (1 - placed.pose.opacity) * theme.time.caption_rise);
+ const u = (ui.Ui{ .f = f, .at = placed }).moved(0, (1 - placed.pose.opacity) * theme.time.caption_rise + if (a.drop) |d| placed.value(d) else 0);
const wrapped = wrap(u, a.text, a.wrap);
const top = a.level - first;
const h = first * 2 + @as(f32, @floatFromInt(wrapped.len - 1)) * line_pitch;
@@ -50,39 +52,101 @@ pub const Aside = struct {
/// until the last has been read, arrives (18 f, `enter`), and is followed
/// by its lead (60 f); the one before it dims (18 f), or leaves (12 f,
/// `exit`, then the caption's gap) where the new one would stand on it.
+/// With a `floor`, one in the way glides down under it instead (24 f,
+/// `glide`), the others under that with it, as far as the floor (past it,
+/// it leaves), and three stand at most (the column's way).
/// `leave`: all go together.
pub const Asides = struct {
shown: [8]?anim.Obj = @splat(null),
dims: [8]anim.Value = undefined,
+ drops: [8]anim.Value = undefined,
spans: [8][2]f32 = undefined,
+ /// Each text's first top, before it glided.
+ tops: [8]f32 = undefined,
n: usize = 0,
read_by: f32 = 0,
/// Characters a line, at most, of the texts it says.
wrap: usize = chars,
+ /// Where texts in the way glide down to, at most (null: they leave).
+ floor: ?f32 = null,
pub fn say(a: *Asides, s: *anim.Frame, text: []const u8, x: f32, level: f32) void {
s.wait(@max(a.read_by - s.cursor, 0));
const dim = s.value(0);
- const made = s.new(Aside{ .text = text, .x = x, .level = level, .dim = dim, .wrap = a.wrap });
+ const drop = s.value(0);
+ const made = s.new(Aside{ .text = text, .x = x, .level = level, .dim = dim, .wrap = a.wrap, .drop = drop });
const obj = s.custom(made, .{ .x = -640, .y = -360, .scale = ui.scale });
const span = [2]f32{ level - first, level + first + @as(f32, @floatFromInt(lines(text, a.wrap) - 1)) * line_pitch };
const at = s.cursor;
var in_the_way = false;
- for (a.shown[0..a.n], a.dims[0..a.n], a.spans[0..a.n]) |*o, d, other| {
+ var glided = false;
+ // With a floor: the two newest stay, top down, each in the way gliding under what is over it.
+ var keep: [8]bool = @splat(false);
+ if (a.floor) |floor| {
+ var kept: usize = 0;
+ var k = a.n;
+ while (k > 0) {
+ k -= 1;
+ if (a.shown[k] == null or kept == 2) continue;
+ keep[k] = true;
+ kept += 1;
+ }
+ var bottom = span[1] + 12;
+ while (true) {
+ // The highest kept one not yet placed.
+ var next: ?usize = null;
+ for (0..a.n) |j| if (keep[j] and a.shown[j] != null and (next == null or a.spans[j][0] < a.spans[next.?][0])) {
+ next = j;
+ };
+ const j = next orelse break;
+ keep[j] = false;
+ const sp = a.spans[j];
+ s.cursor = at;
+ s.play(.{a.dims[j].to(1)}, .{ .seconds = 18.0 / 60.0, .ease = easeGlide });
+ s.cursor = at;
+ if (sp[1] + 12 <= span[0]) continue;
+ const shift = @max(bottom - sp[0], 0);
+ if (sp[1] + shift > floor) {
+ s.play(.{a.shown[j].?.fadeOut()}, .{ .seconds = time.caption_out, .ease = easeExit });
+ a.shown[j] = null;
+ in_the_way = true;
+ continue;
+ }
+ if (shift > 0) {
+ s.play(.{a.drops[j].to(sp[0] + shift - a.tops[j])}, .{ .seconds = 24.0 / 60.0, .ease = easeGlide });
+ a.spans[j] = .{ sp[0] + shift, sp[1] + shift };
+ glided = true;
+ }
+ bottom = a.spans[j][1] + 12;
+ }
+ }
+ for (a.shown[0..a.n], a.dims[0..a.n], a.spans[0..a.n], 0..) |*o, d, other, j| {
s.cursor = at;
if (o.* == null) continue;
+ if (a.floor != null) {
+ // Past the two newest: it leaves.
+ var newer: usize = 0;
+ for (a.shown[j + 1 .. a.n]) |later| newer += @intFromBool(later != null);
+ if (newer >= 2) {
+ s.play(.{o.*.?.fadeOut()}, .{ .seconds = time.caption_out, .ease = easeExit });
+ o.* = null;
+ }
+ continue;
+ }
if (other[0] < span[1] + 12 and span[0] < other[1] + 12) {
s.play(.{o.*.?.fadeOut()}, .{ .seconds = time.caption_out, .ease = easeExit });
o.* = null;
in_the_way = true;
} else s.play(.{d.to(1)}, .{ .seconds = 18.0 / 60.0, .ease = easeGlide });
}
- // One it would stand on is gone first, then a gap: never two texts over each other.
- s.cursor = if (in_the_way) at + time.caption_out + time.caption_gap else at;
+ // One it would stand on is gone first, then a gap, or has glided from under it: never two texts over each other.
+ s.cursor = at + @max(@as(f32, if (in_the_way) time.caption_out + time.caption_gap else 0), @as(f32, if (glided) 24.0 / 60.0 else 0));
s.play(.{obj.fadeIn()}, .{ .seconds = time.caption_in, .ease = easeEnter });
a.shown[a.n] = obj;
a.dims[a.n] = dim;
+ a.drops[a.n] = drop;
a.spans[a.n] = span;
+ a.tops[a.n] = span[0];
a.n += 1;
a.read_by = s.cursor + time.caption(@intCast(std.unicode.utf8CountCodepoints(text) catch text.len));
s.wait(time.caption_lead);