1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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);
}
|