diff options
author | Tom Barrett <tom@tombarrett.xyz> | 2022-12-18 22:56:16 +0100 |
---|---|---|
committer | Tom Barrett <tom@tombarrett.xyz> | 2022-12-18 22:56:16 +0100 |
commit | 0edb4a4df4b41e886935a91da3b2e50ddaa6817f (patch) | |
tree | 2a5f71b87d324284baa9578554c42e9f45b941a1 |
2.2
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | build.zig | 31 | ||||
-rw-r--r-- | src/main.zig | 23 |
3 files changed, 56 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..53b6426 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +zig-* +*ppm diff --git a/build.zig b/build.zig new file mode 100644 index 0000000..5dfbc9c --- /dev/null +++ b/build.zig @@ -0,0 +1,31 @@ +const std = @import("std"); + +pub fn build(b: *std.build.Builder) void { + // Standard target options allows the person running `zig build` to choose + // what target to build for. Here we do not override the defaults, which + // means any target is allowed, and the default is native. Other options + // for restricting supported target set are available. + const target = b.standardTargetOptions(.{}); + + // Standard release options allow the person running `zig build` to select + // between Debug, ReleaseSafe, ReleaseFast, and ReleaseSmall. + const mode = b.standardReleaseOptions(); + + const exe = b.addExecutable("raytracing", "src/main.zig"); + exe.setTarget(target); + exe.setBuildMode(mode); + exe.install(); + + const run_cmd = exe.run(); + run_cmd.step.dependOn(b.getInstallStep()); + if (b.args) |args| { + run_cmd.addArgs(args); + } + + const run_step = b.step("run", "Run the app"); + run_step.dependOn(&run_cmd.step); + + const exe_tests = b.addTest("src/main.zig"); + exe_tests.setTarget(target); + exe_tests.setBuildMode(mode); +} 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 }); + } + } +} |