Compare commits

..

No commits in common. "ece4540426a30e89466723c0ac1c28675b4eb696" and "b7ee15f76a5400856e5870246cddb129634e199e" have entirely different histories.

2 changed files with 26 additions and 34 deletions

View File

@ -39,14 +39,6 @@ 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;
@ -70,7 +62,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", .{});
@ -83,10 +75,9 @@ 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);
} }
} }

View File

@ -56,18 +56,17 @@ pub fn LinkedList() type {
self.length += 1; self.length += 1;
} }
pub fn next(self: *Self) Point { pub fn next(self: *Self) Point {
var elem: ?*Node = undefined; var current: ?*Node = undefined;
if (self.current != null) {
if (self.current == null) { current = self.current;
elem = self.head;
self.current = self.head.?.next;
} else {
elem = self.current;
self.current = self.current.?.next; self.current = self.current.?.next;
} } else {
return elem.?.point; current = self.head;
self.current = self.head;
} }
return current.?.point;
}
pub fn dump(self: *Self) ![]Point { pub fn dump(self: *Self) ![]Point {
const allocator = self.allocator; const allocator = self.allocator;
var node = self.head; var node = self.head;
@ -102,23 +101,25 @@ test "test linked list" {
const points: []Point = try polygon.dump(); const points: []Point = try polygon.dump();
for (points) |point| { for (points) |point| {
std.debug.print("Point dump:{}\n", .{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("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)}); std.debug.print("next:{}\n", .{polygon.next()});
} std.debug.print("next:{}\n", .{polygon.next()});
std.debug.print("next:{}\n", .{polygon.next()});
pub fn polygon_draw(buf: []u8, w: Winsize, poly: *LinkedList()) !void { std.debug.print("next:{}\n", .{polygon.next()});
var i: u8 = 0; std.debug.print("next:{}\n", .{polygon.next()});
var previous: Point = poly.next(); std.debug.print("next:{}\n", .{polygon.next()});
var current: Point = undefined; std.debug.print("next:{}\n", .{polygon.next()});
std.debug.print("next:{}\n", .{polygon.next()});
while (i < poly.length) : (i += 1) { std.debug.print("next:{}\n", .{polygon.next()});
current = poly.next(); std.debug.print("next:{}\n", .{polygon.next()});
try bresenham(buf, w, previous, current); std.debug.print("next:{}\n", .{polygon.next()});
previous = current; std.debug.print("next:{}\n", .{polygon.next()});
} std.debug.print("next:{}\n", .{polygon.next()});
} }
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 {