From 60ae492b0f089d49cd53746dba0d3dc94c034dcf Mon Sep 17 00:00:00 2001 From: jonathan santis Date: Fri, 25 Oct 2024 13:11:22 +0200 Subject: [PATCH] fix utf8 encoding background --- main.zig | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/main.zig b/main.zig index 2cb7ce6..7361f30 100644 --- a/main.zig +++ b/main.zig @@ -126,7 +126,10 @@ fn fillBuffer() !void { var w = Winsize{}; var i: u64 = 0; + var ii: u64 = 0; var buf = std.mem.zeroes([2]u8); + var slice: []u8 = undefined; + var bytes_written: u3 = 0; buf[0] = 0; w = try getTermDimension(); @@ -147,15 +150,18 @@ fn fillBuffer() !void { .c = Point{ .x = 30, .y = 1, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, }; + //clear buffer while (true) { buffer[0] = 0; i = 0; while (i < buffer.len) : (i += 4) { - const slice = buffer[i .. i + 4]; - _ = try std.unicode.utf8Encode('_', slice); - //slice[0] = 'm'; + 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 pixel(buffer, w, 5, 10, '\u{1F702}'); try triangle(buffer, w, vec); //_ = try bresenham(buffer, w, Point{ .x = 10, .y = 10, .z = 0 }, Point{ .x = 30, .y = 12, .z = 0 }); @@ -179,7 +185,7 @@ fn fillBuffer() !void { bounce(w, &vec2.c, 'x'); bounce(w, &vec2.c, 'y'); try out.print("{s}", .{buffer}); - sleep(1000000); + sleep(10000000); //_ = try stdin.readUntilDelimiterOrEof(&buf, '\n'); } }