A "binding" of ricmoo/QRCode for Zig.
zig fetch --save git+https://github.com/darltrash/QRCode.zigin your build.zig file:
const qrcode_pkg = b.dependency("qrcode", .{});
exe.root_module.addImport("qrcode", qrcode_pkg.module("qrcode"));var qr = try QR.fromText(allocator, 1, .low, "HELLO WORLD!");
defer qr.deinit();
const stdout = std.io.getStdOut().writer();
for (0..qr.size) |y| {
for (0..qr.size) |x| {
const is_lit = qr.getModule(@intCast(x), @intCast(y));
const characters = if (is_lit)
"██"
else
" ";
try stdout.writeAll(characters);
}
try stdout.writeByte('\n');
}Output:
██████████████ ████ ██ ██████████████
██ ██ ██ ██ ██ ██
██ ██████ ██ ██ ██ ██ ██ ██████ ██
██ ██████ ██ ██ ██ ██ ██████ ██
██ ██████ ██ ██████ ██ ██████ ██
██ ██ ██ ██
██████████████ ██ ██ ██ ██████████████
████
████████ ██ ██ ██ ██ ██████ ██
████ ████ ████████ ████
████████ ██ ██ ████ ██ ████
██ ██ ██ ██ ██ ██
████ ██████████ ██ ██ ██ ██
████ ██ ████ ██ ██
██████████████ ██ ████████
██ ██ ████████ ██ ████
██ ██████ ██ ██ ██ ██ ██ ██
██ ██████ ██ ██ ██ ██ ██████
██ ██████ ██ ████ ██ ██ ██
██ ██ ██ ██ ████████ ██
██████████████ ██ ████ ██ ██
Note: You can also run
zig build runto test out this same demonstration fromsrc/main.zig
As I did little to no contribution to the original thing, I've decided to keep the original license of the original repo.