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_live.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_live.zig')
| -rw-r--r-- | test/scene_live.zig | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/scene_live.zig b/test/scene_live.zig new file mode 100644 index 0000000..cb21b9b --- /dev/null +++ b/test/scene_live.zig @@ -0,0 +1,38 @@ +//! The anim module's test scene, live: a custom object drawn with 2D +//! commands between two vector objects, on the same timeline and camera. +const anim = @import("anim"); +const sk = @import("sketch"); + +pub const typst = struct { + pub const title = "#text(fill: white, size: 30pt)[registers]"; +}; +pub const scene = anim.Live(frame, typst); + +/// A panel of 200x100 units around its origin, with a label and a bar. +const Panel = struct { + label: []const u8, + /// How much of the bar is full, 0 to 1. + level: f32, + + pub fn draw(p: *const Panel, f: *sk.Frame, at: anim.Placed) void { + sk.draw.rect(f, .{ .x = -100, .y = -50, .w = 200, .h = 100 }, at.pen(.{ .fill = .hex(0x204060) })); + sk.draw.rect(f, .{ .x = -100, .y = 10, .w = 200 * p.level, .h = 40 }, at.pen(.{ .fill = .hex(0xf0ac5f) })); + at.text(f, -92, -42, 1.5, p.label, .white); + } +}; + +fn frame(s: *anim.Frame) void { + const title = s.typst(typst.title, .{ .y = -250 }); + // Added in this order, shown in this order: circle, panel, square. + const under = s.circle(.{ .r = 120, .x = -100, .fill = anim.red }); + const panel = s.new(Panel{ .label = "rax", .level = 0 }); + const table = s.custom(panel, .{ .x = -300 }); + const over = s.rect(.{ .w = 60, .h = 60, .x = 100, .y = 50, .fill = anim.green }); + const level = s.value(0); + s.play(.{ title.fadeIn(), under.fadeIn(), table.fadeIn(), over.fadeIn() }, .{ .seconds = 1 }); + s.play(.{ table.move(.{ .x = 0 }), level.to(0.5) }, .{ .seconds = 1 }); + s.pause(); + s.play(.{ anim.camera(.{ .zoom = 2 }), table.move(.{ .opacity = 0.5 }) }, .{ .seconds = 1 }); + // After the plays: the value as it stands now. + panel.level = s.get(level); +} |
