summaryrefslogtreecommitdiff
path: root/anim/scenes/sort.zig
diff options
context:
space:
mode:
Diffstat (limited to 'anim/scenes/sort.zig')
-rw-r--r--anim/scenes/sort.zig29
1 files changed, 23 insertions, 6 deletions
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);
}