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
|
//! 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 });
}
|