//! Example 1.2: Bouncing Ball, with vectors. const sk = @import("sketch"); const vec = sk.math; pub const name = "bouncing_ball"; pub const width = 640; pub const height = 360; pub const State = struct { position: vec.Vec = .{ 100, 100 }, velocity: vec.Vec = .{ 2.5, 2 }, clock: sk.Clock = .{}, }; pub fn update(s: *State, in: *const sk.Input) void { for (0..s.clock.steps(in)) |_| { s.position += s.velocity; if (s.position[0] > width or s.position[0] < 0) s.velocity[0] *= -1; if (s.position[1] > height or s.position[1] < 0) s.velocity[1] *= -1; } } const ball: sk.draw.Pen = .{ .fill = .gray(127), .stroke = .black, .width = 2 }; pub fn draw(s: *const State, f: *sk.Frame) void { f.clear(sk.Color.white); sk.draw.circle(f, s.position, 24, ball); }