feat: generate image

This commit is contained in:
2026-01-16 22:38:53 +01:00
parent ee6cab8102
commit 817552caa9
2 changed files with 23 additions and 6 deletions

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
.zig-cache .zig-cache
zig-out zig-out
*.ppm

View File

@@ -1,13 +1,29 @@
const std = @import("std"); const std = @import("std");
pub fn main() !void { pub fn main() !void {
var allocator = std.heap.ArenaAllocator{}; const img_width = 512;
defer allocator.deinit(); const img_height = 512;
const alloc = allocator.allocator(); var buf: [img_width * img_height * 3]u8 = undefined;
const hello_world = try std.fmt.allocPrint(alloc, "Hello, World!\n", .{}); const stdout = std.fs.File.stdout();
defer allocator.free(hello_world); var writer_f: std.fs.File.Writer = stdout.writer(&buf);
var writer = &writer_f.interface;
std.debug.print("All your {s} are belong to us.\n", .{"codebase"}); try writer.print("P3\n{d} {d}\n255\n", .{ img_width, img_height });
try writer.flush();
for (0..img_height) |j| {
for (0..img_width) |i| {
const r = @as(f64, @floatFromInt(j)) / (img_width - 1);
const g = 0.0;
const b = @as(f64, @floatFromInt(i)) / (img_height - 1);
const ir = @as(i64, @intFromFloat(r * 255.999));
const ig = @as(i64, @intFromFloat(g * 255.999));
const ib = @as(i64, @intFromFloat(b * 255.999));
try writer.print("{d} {d} {d}\n", .{ ir, ig, ib });
}
}
try writer.flush();
} }