Compare commits
2 Commits
b7ee15f76a
...
ece4540426
Author | SHA1 | Date | |
---|---|---|---|
|
ece4540426 | ||
|
e91c744c16 |
13
main.zig
13
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);
|
||||
}
|
||||
}
|
||||
|
@ -56,17 +56,18 @@ pub fn LinkedList() type {
|
||||
self.length += 1;
|
||||
}
|
||||
pub fn next(self: *Self) Point {
|
||||
var current: ?*Node = undefined;
|
||||
if (self.current != null) {
|
||||
current = self.current;
|
||||
self.current = self.current.?.next;
|
||||
var elem: ?*Node = undefined;
|
||||
|
||||
if (self.current == null) {
|
||||
elem = self.head;
|
||||
self.current = self.head.?.next;
|
||||
} else {
|
||||
current = self.head;
|
||||
self.current = self.head;
|
||||
elem = self.current;
|
||||
self.current = self.current.?.next;
|
||||
}
|
||||
return elem.?.point;
|
||||
}
|
||||
|
||||
return current.?.point;
|
||||
}
|
||||
pub fn dump(self: *Self) ![]Point {
|
||||
const allocator = self.allocator;
|
||||
var node = self.head;
|
||||
@ -101,25 +102,23 @@ test "test linked list" {
|
||||
|
||||
const points: []Point = try polygon.dump();
|
||||
for (points) |point| {
|
||||
std.debug.print("x:{}\n", .{point.x});
|
||||
std.debug.print("y:{}\n", .{point.y});
|
||||
std.debug.print("z:{}\n", .{point.z});
|
||||
std.debug.print("Point dump:{}\n", .{point});
|
||||
}
|
||||
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("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("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("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 {
|
||||
|
Loading…
Reference in New Issue
Block a user