summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorTom Barrett <tom@tombarrett.xyz>2022-12-19 00:20:15 +0100
committerTom Barrett <tom@tombarrett.xyz>2022-12-19 00:20:15 +0100
commit91f12439280eee0fb6e3c8f922882a598f6844ab (patch)
tree2f0b8e4abc1061e4ac840eb3cec38d657244fe0c /src
parent0edb4a4df4b41e886935a91da3b2e50ddaa6817f (diff)
3.3
Diffstat (limited to 'src')
-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();
}