zigrtiow: use signed ints to match C++ example.

This commit is contained in:
Bill Thiede 2022-07-29 20:31:30 -07:00
parent f3aace486b
commit a4adefdb23

View File

@ -1,20 +1,21 @@
const std = @import("std");
const info = std.log.info;
pub fn main() anyerror!void {
const image_width: usize = 256;
const image_height: usize = 256;
const image_width: isize = 256;
const image_height: isize = 256;
const stdout = std.io.getStdOut();
std.log.info("Writing image {d}x{d}\n", .{ image_width, image_height });
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;
var j: isize = image_height - 1;
while (j >= 0) : (j -= 1) {
var i: isize = 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 g = @intToFloat(f32, j) / @intToFloat(f32, image_height - 1);
var b: f32 = 0.25;
var ir = @floatToInt(u8, 255.999 * r);