const std = @import("std"); const graphics = @import("root.zig"); pub const Curve = struct { const Self = @This(); const Point = struct { x: u32, y: u32, }; start: Point, middle: Point, end: Point, color: graphics.Color, pub fn render(self: *const Self, canvas: *const graphics.Canvas) void { const start_x: f64 = @floatFromInt(self.start.x); const start_y: f64 = @floatFromInt(self.start.y); const middle_x: f64 = @floatFromInt(self.middle.x); const middle_y: f64 = @floatFromInt(self.middle.y); const end_x: f64 = @floatFromInt(self.end.x); const end_y: f64 = @floatFromInt(self.end.y); for (0..100) |index| { const t: f64 = @as(f64, @floatFromInt(index)) / 100; const x: u32 = @intFromFloat(@round( (1 - t) * ((1 - t) * start_x + t * middle_x) + t * ((1 - t) * middle_x + t * end_x) )); const y: u32 = @intFromFloat(@round( (1 - t) * ((1 - t) * start_y + t * middle_y) + t * ((1 - t) * middle_y + t * end_y) )); canvas.buffer[x + canvas.width * y] = self.color; } } };