diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 11:27:39 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-12 13:22:02 -0300 |
| commit | 71e534631bf68f33f802d64794340870374b9f69 (patch) | |
| tree | 2a45229ce238a4e2ce355683f0e75a7725d4851a /test/scene_compiled.zig | |
| parent | 00605f7a109845a99f16621b267305a8b995dddc (diff) | |
| download | sketchbook-71e534631bf68f33f802d64794340870374b9f69.tar.gz sketchbook-71e534631bf68f33f802d64794340870374b9f69.zip | |
sketchbook: anim, manim-style scenes as a module (from the game's vecanim), with objects a scene draws itself
The player takes its canvas from the room it has and fits the scene's
frame into it, plays through and quits when exported, and draws vector
objects in runs around custom ones. The renderers' resvg comparison and
the timings come along as `zig build diff` and `zig build bench`; the
comparison's reference is padded to whole blocks rather than squeezed,
which had put Typst text over the limit.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'test/scene_compiled.zig')
| -rw-r--r-- | test/scene_compiled.zig | 34 |
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 }); +} |
