1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
//! Export's test: time comes from the ticks alone and moves a bar, the
//! canvas is the room the host gives (`--size`), and it quits by itself.
const sk = @import("sketch");
pub const State = struct { t: f32 = 0, frames: u32 = 0 };
pub fn update(s: *State, in: *const sk.Input) void {
for (in.events) |e| if (e.kind == .tick) {
s.t += e.x;
s.frames += 1;
};
}
pub fn draw(s: *const State, f: *sk.Frame) void {
const w = f.in.window_width;
const h = f.in.window_height;
f.canvas(@intFromFloat(w), @intFromFloat(h));
f.clear(0x202020);
// 300 px a second: 10 px a frame at 30 fps, whatever the wall clock did.
f.fill(sk.Rect{ .w = s.t * 300, .h = h / 2 }, 0xff8040);
f.print(8, h - 24, 1, 0xffffff, "frame {d} of {d:.0}x{d:.0}", .{ s.frames, w, h });
if (s.frames == 8) f.quit();
}
|