fill rectangles

This commit is contained in:
jonathan santis 2024-10-29 11:29:31 +01:00
parent 131a8c5fcd
commit 039cc7e912

View File

@ -47,7 +47,7 @@ pub fn main() !void {
win = try getTermDimension(); win = try getTermDimension();
print("winsize.ws_row: {}\nws_line: {}\nws_xpixel: {} \nws_ypixel: {}\n", .{ win.ws_row, win.ws_col, win.ws_xpixel, win.ws_ypixel }); 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(); try draw();
} }
@ -95,6 +95,7 @@ fn draw() !void {
.c = Point{ .x = 30, .y = 1, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } }, .c = Point{ .x = 30, .y = 1, .z = 0, .direction = .{ .x = 1, .y = 1, .z = 1 } },
}; };
_ = try stdin.readUntilDelimiterOrEof(&buf, '\n');
//video loop //video loop
while (true) { while (true) {
buffer[0] = 0; buffer[0] = 0;
@ -130,33 +131,48 @@ fn draw() !void {
mv_axis_border_bounce(w, &vec2.c, 'x'); mv_axis_border_bounce(w, &vec2.c, 'x');
mv_axis_border_bounce(w, &vec2.c, 'y'); mv_axis_border_bounce(w, &vec2.c, 'y');
i = 0; try fill_draw(w, buffer);
ii = 0;
var fill: u8 = 0;
var code: [4]u8 = std.mem.zeroes([4]u8);
_ = try std.unicode.utf8Encode('█', &code);
while (i < buffer.len) : (i += 4) {
slice = buffer[i .. i + 4];
if (i - ii >= w.ws_col) {
ii += 1;
}
if (fill == 0 and std.mem.eql(u8, slice, &code) == true) {
fill = 1;
} else if (fill == 1 or fill == 2 and std.mem.eql(u8, slice, &code) == false) {
_ = try std.unicode.utf8Encode('X', slice);
fill = 2;
} else if (fill == 2 and std.mem.eql(u8, slice, &code) == true) {
fill = 3;
} else if (fill == 3 and std.mem.eql(u8, slice, &code) == false) {
fill = 0;
}
}
try out.print("{s}", .{buffer}); try out.print("{s}", .{buffer});
_ = try stdin.readUntilDelimiterOrEof(&buf, '\n'); _ = try stdin.readUntilDelimiterOrEof(&buf, '\n');
sleep(30000000); 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('X', utf_slice);
}
}
}
}
fn mv_axis_border_bounce(w: Winsize, point: *Point, axis: u8) void { fn mv_axis_border_bounce(w: Winsize, point: *Point, axis: u8) void {
var cor = &point.x; var cor = &point.x;
var dir = &point.direction.x; var dir = &point.direction.x;