32 lines
974 B
Zig
32 lines
974 B
Zig
const std = @import("std");
|
|
const info = std.log.info;
|
|
const vec = @import("./vec.zig");
|
|
const Vec3 = vec.Vec3;
|
|
const Color = vec.Color;
|
|
const write_color = @import("./color.zig").write_color;
|
|
|
|
pub fn main() anyerror!void {
|
|
const image_width: isize = 256;
|
|
const image_height: isize = 256;
|
|
|
|
const stdout = std.io.getStdOut();
|
|
|
|
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: isize = image_height - 1;
|
|
while (j >= 0) : (j -= 1) {
|
|
info("Scanlines remaining: {d}", .{j});
|
|
|
|
var i: isize = 0;
|
|
while (i < image_width) : (i += 1) {
|
|
const pixel_color = Color.init(@intToFloat(f32, i) / @intToFloat(f32, image_width - 1), @intToFloat(f32, j) / @intToFloat(f32, image_height - 1), 0.25);
|
|
try write_color(pixel_color);
|
|
}
|
|
}
|
|
}
|
|
|
|
test "basic test" {
|
|
try std.testing.expectEqual(10, 3 + 7);
|
|
}
|