implement polygon
a bug in the fill algorythm where it fills every
This commit is contained in:
parent
e91c744c16
commit
ece4540426
13
main.zig
13
main.zig
@ -39,6 +39,14 @@ fn draw() !void {
|
|||||||
var slice: []u8 = undefined;
|
var slice: []u8 = undefined;
|
||||||
var bytes_written: u3 = 0;
|
var bytes_written: u3 = 0;
|
||||||
var buffer_size: u32 = 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();
|
w = try getTermDimension();
|
||||||
buffer_size = w.ws_row;
|
buffer_size = w.ws_row;
|
||||||
@ -62,7 +70,7 @@ fn draw() !void {
|
|||||||
slice[bytes_written + ii] = 0;
|
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 bresenham(buffer, w, Point{ .x = 10, .y = 10, .z = 0 }, Point{ .x = 30, .y = 12, .z = 0 });
|
||||||
|
|
||||||
try out.print("\x1B[2J", .{});
|
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.b, 'y');
|
||||||
// mv_axis_border_bounce(w, &primitive.vec.c, 'x');
|
// mv_axis_border_bounce(w, &primitive.vec.c, 'x');
|
||||||
// mv_axis_border_bounce(w, &primitive.vec.c, 'y');
|
// mv_axis_border_bounce(w, &primitive.vec.c, 'y');
|
||||||
|
try primitive.polygon_draw(buffer, w, &polygon);
|
||||||
try fill_draw(w, buffer);
|
try fill_draw(w, buffer);
|
||||||
try out.print("{s}", .{buffer});
|
try out.print("{s}", .{buffer});
|
||||||
|
|
||||||
sleep(30000000);
|
sleep(30000000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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("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 {
|
pub fn pixel(buffer: []u8, w: Winsize, x: i64, y: i64, symbol: u21) !void {
|
||||||
|
Loading…
Reference in New Issue
Block a user