diff options
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); +} |
