aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main.zig
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2022-11-27 11:17:24 +0900
committernsfisis <nsfisis@gmail.com>2022-11-27 11:17:24 +0900
commit39d1933943a506a0f1f2ce19fe7555f987e1752d (patch)
tree25e710c0b6f03d37efd29da054be75b35d9ff475 /src/main.zig
parent2deccc0a9ba63d19a32b636b3b81eb9be5ef019c (diff)
downloadRayTracingInOneWeekend.zig-39d1933943a506a0f1f2ce19fe7555f987e1752d.tar.gz
RayTracingInOneWeekend.zig-39d1933943a506a0f1f2ce19fe7555f987e1752d.tar.zst
RayTracingInOneWeekend.zig-39d1933943a506a0f1f2ce19fe7555f987e1752d.zip
3.3
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/main.zig b/src/main.zig
index 7373cb6..986a8f6 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -28,6 +28,14 @@ fn vecNormalized(v: Vec3f) Vec3f {
return v / vecNorm(v);
}
+fn writeColor(out: anytype, c: Color) !void {
+ try out.print("{} {} {}\n", .{
+ @floatToInt(u8, 255.999 * c[0]),
+ @floatToInt(u8, 255.999 * c[1]),
+ @floatToInt(u8, 255.999 * c[2]),
+ });
+}
+
pub fn main() !void {
// Image
@@ -47,15 +55,11 @@ pub fn main() !void {
std.debug.print("\rScanlines remaining: {}", .{j});
var i: i32 = 0;
while (i < image_width) {
- const r = @intToFloat(f64, i) / (image_width - 1);
- const g = @intToFloat(f64, j) / (image_height - 1);
- const b = 0.25;
-
- const ir = @floatToInt(u8, 255.999 * r);
- const ig = @floatToInt(u8, 255.999 * g);
- const ib = @floatToInt(u8, 255.999 * b);
-
- try stdout.print("{} {} {}\n", .{ ir, ig, ib });
+ try writeColor(stdout, Color{
+ @intToFloat(f64, i) / (image_width - 1),
+ @intToFloat(f64, j) / (image_height - 1),
+ 0.25,
+ });
i += 1;
}
j -= 1;