Write test ppm image to stdout.

This commit is contained in:
Bill Thiede 2022-07-28 22:20:42 -07:00
parent 93bfeb9125
commit f3aace486b

View File

@ -1,7 +1,29 @@
const std = @import("std");
pub fn main() anyerror!void {
std.log.info("All your codebase are belong to us.", .{});
const image_width: usize = 256;
const image_height: usize = 256;
const stdout = std.io.getStdOut();
std.log.info("Writing image {d}x{d}\n", .{ image_width, image_height });
try stdout.writer().print("P3\n{d} {d}\n255\n", .{ image_width, image_height });
var j: usize = 0;
while (j < image_height) : (j += 1) {
var i: usize = 0;
while (i < image_width) : (i += 1) {
var r = @intToFloat(f32, i) / @intToFloat(f32, image_width - 1);
var g = @intToFloat(f32, image_height - j - 1) / @intToFloat(f32, image_height - 1);
var b: f32 = 0.25;
var ir = @floatToInt(u8, 255.999 * r);
var ig = @floatToInt(u8, 255.999 * g);
var ib = @floatToInt(u8, 255.999 * b);
try stdout.writer().print("{d} {d} {d}\n", .{ ir, ig, ib });
}
}
}
test "basic test" {