|
diff --git a/zig-ppm/main.zig b/zig-ppm/main.zig
|
| ... |
| 24 |
}; |
24 |
}; |
| 25 |
|
25 |
|
| 26 |
pub fn main() !void { |
26 |
pub fn main() !void { |
| 27 |
const imageFile = try std.fs.cwd().createFile("image.ppm", .{}); |
27 |
const image_file = try std.fs.cwd().createFile("image.ppm", .{}); |
| 28 |
defer imageFile.close(); |
28 |
defer image_file.close(); |
| 29 |
|
29 |
|
| 30 |
// NOTE: This should be done at compile time instead since the data is |
30 |
// NOTE: This should be done at compile time instead since the data is |
| 31 |
// known in advance. I am leaving this here as a reference. |
31 |
// known in advance. I am leaving this here as a reference. |
| ... |
| 35 |
// and there must be a better way of doing this. Good enough! |
35 |
// and there must be a better way of doing this. Good enough! |
| 36 |
const header = "P3\n" ++ std.fmt.comptimePrint("{d}", .{ImageSize}) ++ " " ++ std.fmt.comptimePrint("{d}", .{ImageSize}) ++ "\n255\n"; |
36 |
const header = "P3\n" ++ std.fmt.comptimePrint("{d}", .{ImageSize}) ++ " " ++ std.fmt.comptimePrint("{d}", .{ImageSize}) ++ "\n255\n"; |
| 37 |
|
37 |
|
| 38 |
_ = try imageFile.write(header); |
38 |
_ = try image_file.write(header); |
| 39 |
|
39 |
|
| 40 |
for (0..(ImageSize * ImageSize)) |_| { |
40 |
for (0..(ImageSize * ImageSize)) |_| { |
| 41 |
const color = Color.initRandom(); |
41 |
const color = Color.initRandom(); |
| 42 |
_ = try imageFile.write(color.toString()); |
42 |
_ = try image_file.write(color.toString()); |
| 43 |
} |
43 |
} |
| 44 |
} |
44 |
} |