Compare commits
No commits in common. "f0da916a22311112de892fb78f7569ffe2232cef" and "93bfeb9125d0dfa9d772b9e2b57b0cef01188d36" have entirely different histories.
f0da916a22
...
93bfeb9125
@ -1,10 +0,0 @@
|
|||||||
const std = @import("std");
|
|
||||||
const Color = @import("./vec.zig").Color;
|
|
||||||
|
|
||||||
pub fn write_color(c: Color) anyerror!void {
|
|
||||||
var ir = @floatToInt(u8, 255.999 * c.x());
|
|
||||||
var ig = @floatToInt(u8, 255.999 * c.y());
|
|
||||||
var ib = @floatToInt(u8, 255.999 * c.z());
|
|
||||||
const stdout = std.io.getStdOut();
|
|
||||||
try stdout.writer().print("{d} {d} {d}\n", .{ ir, ig, ib });
|
|
||||||
}
|
|
||||||
@ -1,29 +1,7 @@
|
|||||||
const std = @import("std");
|
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 {
|
pub fn main() anyerror!void {
|
||||||
const image_width: isize = 256;
|
std.log.info("All your codebase are belong to us.", .{});
|
||||||
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" {
|
test "basic test" {
|
||||||
|
|||||||
@ -1,19 +0,0 @@
|
|||||||
pub const Vec3 = struct {
|
|
||||||
v: @Vector(3, f32),
|
|
||||||
pub fn init(v0: f32, v1: f32, v2: f32) Vec3 {
|
|
||||||
return Vec3{
|
|
||||||
.v = .{ v0, v1, v2 },
|
|
||||||
};
|
|
||||||
}
|
|
||||||
pub fn x(vec: Vec3) f32 {
|
|
||||||
return vec.v[0];
|
|
||||||
}
|
|
||||||
pub fn y(vec: Vec3) f32 {
|
|
||||||
return vec.v[1];
|
|
||||||
}
|
|
||||||
pub fn z(vec: Vec3) f32 {
|
|
||||||
return vec.v[2];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
pub const Color = Vec3;
|
|
||||||
pub const Point3 = Vec3;
|
|
||||||
Loading…
x
Reference in New Issue
Block a user