summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.zig36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/main.zig b/src/main.zig
index 9983774..2d42772 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -1,23 +1,37 @@
const std = @import("std");
+const warn = @import("std").debug.print;
+
+pub fn write_color(stdout: anytype, v: vec) !void {
+ const r = @floatToInt(usize, v[0] * 255.999);
+ const g = @floatToInt(usize, v[1] * 255.999);
+ const b = @floatToInt(usize, v[2] * 255.999);
+ try stdout.print("{} {} {}\n", .{ r, g, b });
+}
+
+const vec = @Vector(3, f32);
pub fn main() !void {
- const width = 256;
- const height = 256;
- std.debug.print("P3\n{} {}\n255\n", .{ width, height });
+ const width = 512;
+ const height = 512;
+ const stdout_file = std.io.getStdOut().writer();
+ var bw = std.io.bufferedWriter(stdout_file);
+ const stdout = bw.writer();
+
+ try stdout.print("P3\n{} {}\n255\n", .{ width, height });
var j: usize = height;
while (j > 0) : (j -= 1) {
+ warn("remaining: {}\n", .{j});
var i: usize = 0;
while (i < width) : (i += 1) {
- var r: f32 = @intToFloat(f32, i) / (width - 1);
- var g: f32 = @intToFloat(f32, j) / (height - 1);
- var b: f32 = 0.25;
-
- var ir: usize = @floatToInt(usize, r * 255.999);
- var ig: usize = @floatToInt(usize, g * 255.999);
- var ib: usize = @floatToInt(usize, b * 255.999);
+ var color = vec{
+ @intToFloat(f32, i) / (width - 1),
+ @intToFloat(f32, j) / (height - 1),
+ 0.25,
+ };
- std.debug.print("{} {} {}\n", .{ ir, ig, ib });
+ try write_color(stdout, color);
}
}
+ try bw.flush();
}