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 = 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 color = vec{ @intToFloat(f32, i) / (width - 1), @intToFloat(f32, j) / (height - 1), 0.25, }; try write_color(stdout, color); } } try bw.flush(); }