From 0edb4a4df4b41e886935a91da3b2e50ddaa6817f Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sun, 18 Dec 2022 22:56:16 +0100 Subject: 2.2 --- src/main.zig | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 src/main.zig (limited to 'src') diff --git a/src/main.zig b/src/main.zig new file mode 100644 index 0000000..9983774 --- /dev/null +++ b/src/main.zig @@ -0,0 +1,23 @@ +const std = @import("std"); + +pub fn main() !void { + const width = 256; + const height = 256; + std.debug.print("P3\n{} {}\n255\n", .{ width, height }); + + var j: usize = height; + while (j > 0) : (j -= 1) { + 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); + + std.debug.print("{} {} {}\n", .{ ir, ig, ib }); + } + } +} -- cgit v1.2.3