This commit is contained in:
jonathan santis 2024-10-28 14:39:26 +01:00
parent e8f0988d46
commit 131a8c5fcd

View File

@ -36,6 +36,11 @@ const Vec3 = struct {
b: Point, b: Point,
c: Point, c: Point,
}; };
const Triangle = struct {
bufa: *i32,
bufb: *i32,
bufc: *i32,
};
pub fn main() !void { pub fn main() !void {
var win = Winsize{}; var win = Winsize{};
@ -124,9 +129,32 @@ fn draw() !void {
mv_axis_border_bounce(w, &vec2.b, 'Y'); mv_axis_border_bounce(w, &vec2.b, 'Y');
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;
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');
sleep(30000000); sleep(30000000);
//_ = try stdin.readUntilDelimiterOrEof(&buf, '\n');
} }
} }
fn mv_axis_border_bounce(w: Winsize, point: *Point, axis: u8) void { fn mv_axis_border_bounce(w: Winsize, point: *Point, axis: u8) void {
@ -262,14 +290,7 @@ fn bresenham(buf: []u8, w: Winsize, p1: Point, p2: Point) !void {
} }
fn triangle(buffer: []u8, w: Winsize, vec: Vec3) !void { fn triangle(buffer: []u8, w: Winsize, vec: Vec3) !void {
var vec_fill: Vec3 = vec;
try bresenham(buffer, w, vec.a, vec.b); try bresenham(buffer, w, vec.a, vec.b);
try bresenham(buffer, w, vec.b, vec.c); try bresenham(buffer, w, vec.b, vec.c);
try bresenham(buffer, w, vec.c, vec.a); try bresenham(buffer, w, vec.c, vec.a);
while (vec_fill.a.y < vec.c.y) : (vec_fill.a.y += 1) {
try bresenham(buffer, w, vec_fill.a, vec.b);
}
while (vec_fill.a.y > vec.c.y) : (vec_fill.a.y -= 1) {
try bresenham(buffer, w, vec_fill.a, vec.b);
}
} }