From 40b847344481803e94e78ba2dacde8dc78636948 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Fri, 14 Feb 2025 16:51:07 +0100 Subject: graphics: make curve more smooth --- src/estd/graphics/curve.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/estd/graphics') diff --git a/src/estd/graphics/curve.zig b/src/estd/graphics/curve.zig index 70569a3..6c591fa 100644 --- a/src/estd/graphics/curve.zig +++ b/src/estd/graphics/curve.zig @@ -29,7 +29,7 @@ pub const Curve = struct { const middle_y: f64 = @floatFromInt(self.middle.y); const end_x: f64 = @floatFromInt(self.end.x); const end_y: f64 = @floatFromInt(self.end.y); - const resolution = 2 + ( + const resolution = 1 + ( distance(self.start.x, self.end.x) + distance(self.start.y, self.end.y) ) / 8; @@ -37,7 +37,7 @@ pub const Curve = struct { canvas.buffer[last.x + last.y * canvas.width] = .{ .red = 0xff, .green = 0xff, .blue = 0xff }; - for (1..resolution) |index| { + for (1..resolution + 1) |index| { const t: f64 = @as(f64, @floatFromInt(index)) / @as(f64, @floatFromInt(resolution)); const x: u32 = @intFromFloat(@round( (1 - t) * ((1 - t) * start_x + t * middle_x) + t * ((1 - t) * middle_x + t * end_x) -- cgit v1.2.3-70-g09d2