const std = @import("std"); const expect = std.testing.expect; const print = std.debug.print; const getenv = std.posix.getenv; const stdout = std.io.getStdOut(); const out = stdout.writer(); const stdin = std.io.getStdIn().reader(); const sleep = std.time.sleep; const primitive = @import("primitives.zig"); const Point = primitive.Point; const pixel = primitive.pixel; const triangle = primitive.triangle; const term = @import("term.zig"); const Winsize = term.Winsize; const getTermDimension = term.getTermDimension; const movement = @import("movement.zig"); const mv_axis_border_bounce = movement.mv_axis_border_bounce; const definitions = @import("definitions.zig"); pub fn main() !void { var win = Winsize{}; win = try getTermDimension(); print("winsize.ws_row: {}\nws_col: {}\nws_xpixel: {} \nws_ypixel: {}\n", .{ win.ws_row, win.ws_col, win.ws_xpixel, win.ws_ypixel }); try draw(); } fn draw() !void { const allocator = std.heap.page_allocator; var w = Winsize{}; var i: u64 = 0; var ii: u64 = 0; 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; buffer_size = buffer_size * w.ws_col * 4; var buffer = try allocator.alloc(u8, buffer_size); //utf-8 can be 4 bytes long defer allocator.free(buffer); definitions.obj[0].a.x = 10; wait_for_enter(); // defer std.heap.page_allocator.free(tmp); //video loop while (true) { i = 0; //clear buffer while (i < buffer.len) : (i += 4) { slice = buffer[i .. i + 4]; bytes_written = try std.unicode.utf8Encode(' ', slice); ii = 0; while ((bytes_written + ii) < 4) : (ii += 1) { slice[bytes_written + ii] = 0; } } //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", .{}); //sleep(100000); // try triangle(buffer, w, primitive.vec); // mv_axis_border_bounce(w, &primitive.vec.a, 'x'); // mv_axis_border_bounce(w, &primitive.vec.a, 'y'); // mv_axis_border_bounce(w, &primitive.vec.b, 'x'); // 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); } } fn fill_draw(w: Winsize, buffer: []u8) !void { var i: u64 = 0; var ii: u16 = 0; var iii: u16 = 0; var fill: u8 = 0; var start: u16 = 0; var end: u16 = 0; var code: [4]u8 = std.mem.zeroes([4]u8); _ = try std.unicode.utf8Encode('█', &code); while (i < buffer.len - w.ws_col * 4) : (i += w.ws_col * 4) { var line: []u8 = buffer[i .. i + w.ws_col * 4]; fill = 0; start = 0; end = 0; ii = 0; iii = 0; while (ii < line.len - 4) : (ii += 4) { const utf_slice: []u8 = line[ii .. ii + 4]; if (std.mem.eql(u8, utf_slice, &code) == true and fill == 0) { fill = 1; start = ii; iii = ii; while (iii < line.len - 4) : (iii += 4) { const lookahead: []u8 = line[iii .. iii + 4]; if (std.mem.eql(u8, lookahead, &code) == true) { end = iii; } } } if (ii > start and ii < end and fill == 1 and std.mem.eql(u8, utf_slice, &code) == false) { _ = try std.unicode.utf8Encode('●', utf_slice); } } } } fn wait_for_enter() void { _ = stdin.readUntilDelimiterAlloc(std.heap.page_allocator, '\n', 3) catch |err| { print("string to long{}", .{err}); }; //Memory leak? }