summaryrefslogtreecommitdiff
path: root/test/scene_compiled.zig
diff options
context:
space:
mode:
Diffstat (limited to 'test/scene_compiled.zig')
-rw-r--r--test/scene_compiled.zig34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/scene_compiled.zig b/test/scene_compiled.zig
new file mode 100644
index 0000000..f4a917c
--- /dev/null
+++ b/test/scene_compiled.zig
@@ -0,0 +1,34 @@
+//! The anim module's test scene, compiled: Typst written and morphed, and
+//! a custom object whose data is a constant, shown as far as it is `drawn`.
+const anim = @import("anim");
+const sk = @import("sketch");
+
+pub const typst_preamble =
+ \\#set page(width: auto, height: auto, margin: 3pt, fill: none)
+ \\#set text(fill: white, size: 28pt)
+;
+pub const scene = anim.Scene(construct);
+
+/// Lines of code in a panel of 320x120 units around its origin.
+const Code = struct {
+ lines: []const []const u8,
+
+ pub fn draw(c: *const Code, f: *sk.Frame, at: anim.Placed) void {
+ sk.draw.rect(f, .{ .x = -160, .y = -60, .w = 320, .h = 120 }, at.pen(.{ .fill = .hex(0x2a2a30) }));
+ const count: f32 = @floatFromInt(c.lines.len);
+ const shown: usize = @intFromFloat(at.pose.drawn * count);
+ for (c.lines[0..shown], 0..) |line, i| at.text(f, -150, -50 + 24 * @as(f32, @floatFromInt(i)), 1.5, line, .white);
+ }
+};
+const code: Code = .{ .lines = &.{ "mov rax, 1", "add rax, rbx", "ret" } };
+
+fn construct(s: *anim.Builder) void {
+ const pythagoras = s.typst("$ a^2 + b^2 = c^2 $", .{ .y = -200 });
+ const solved = s.typst("$ c = sqrt(a^2 + b^2) $", .{ .y = -200 });
+ const panel = s.custom(&code, .{ .y = 60 });
+ const dot = s.circle(.{ .r = 20, .x = 160, .y = 120, .fill = anim.blue });
+ s.play(.{ pythagoras.write(), panel.write() }, .{ .seconds = 1 });
+ s.play(.{ pythagoras.transformInto(solved), dot.fadeIn() }, .{ .seconds = 1 });
+ s.wait(0.5);
+ s.play(.{anim.camera(.{ .zoom = 1.5 })}, .{ .seconds = 0.5 });
+}