diff --git a/main.zig b/main.zig index ff20367..6634ee1 100644 --- a/main.zig +++ b/main.zig @@ -39,6 +39,14 @@ fn draw() !void { var slice: []u8 = undefined; var bytes_written: u3 = 0; var buffer_size: u32 = 0; + var polygon = primitive.LinkedList().new(allocator); + + try polygon.add(.{ .x = 5, .y = 5, .z = 0 }); + try polygon.add(.{ .x = 67, .y = 13, .z = 0 }); + try polygon.add(.{ .x = 77, .y = 33, .z = 0 }); + try polygon.add(.{ .x = 48, .y = 21, .z = 0 }); + try polygon.add(.{ .x = 21, .y = 39, .z = 0 }); + try polygon.add(.{ .x = 24, .y = 23, .z = 0 }); w = try getTermDimension(); buffer_size = w.ws_row; @@ -62,7 +70,7 @@ fn draw() !void { slice[bytes_written + ii] = 0; } } - try triangle(buffer, w, definitions.vec); + //try triangle(buffer, w, definitions.vec); //_ = try bresenham(buffer, w, Point{ .x = 10, .y = 10, .z = 0 }, Point{ .x = 30, .y = 12, .z = 0 }); try out.print("\x1B[2J", .{}); @@ -75,9 +83,10 @@ fn draw() !void { // mv_axis_border_bounce(w, &primitive.vec.b, 'y'); // mv_axis_border_bounce(w, &primitive.vec.c, 'x'); // mv_axis_border_bounce(w, &primitive.vec.c, 'y'); - + try primitive.polygon_draw(buffer, w, &polygon); try fill_draw(w, buffer); try out.print("{s}", .{buffer}); + sleep(30000000); } } diff --git a/primitives.zig b/primitives.zig index 42ec7aa..f9c9ea3 100644 --- a/primitives.zig +++ b/primitives.zig @@ -106,6 +106,19 @@ test "test linked list" { } std.debug.print("next:{}\n", .{polygon.next()}); std.debug.print("next:{}\n", .{polygon.next()}); + std.debug.print("typeof:{}\n", .{@TypeOf(polygon)}); +} + +pub fn polygon_draw(buf: []u8, w: Winsize, poly: *LinkedList()) !void { + var i: u8 = 0; + var previous: Point = poly.next(); + var current: Point = undefined; + + while (i < poly.length) : (i += 1) { + current = poly.next(); + try bresenham(buf, w, previous, current); + previous = current; + } } pub fn pixel(buffer: []u8, w: Winsize, x: i64, y: i64, symbol: u21) !void {