SkillAgentSearch skills...

Art

art is a Zig module used to build WebAssembly binaries rendering to a HTML canvas.

Install / Use

/learn @peterhellberg/Art
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

art :art:

art is a Zig ⚡ module used to build WebAssembly binaries rendering to a HTML canvas.

[!IMPORTANT] You might want to install the art-init tool and use that instead of manually creating the files needed to use this library.

Usage

You can have zig build retrieve the art module if you specify it as a dependency.

Create a build.zig.zon that looks something like this:

.{
    .name = .art_canvas,
    .version = "0.0.0",
    .fingerprint = 0x0000000000,
    .paths = .{""},
    .dependencies = .{
        .art = .{
            .url = "https://github.com/peterhellberg/art/archive/refs/tags/v0.1.0.tar.gz",
        },
    },
}

[!NOTE] If you leave out the hash then zig build will tell you that it is missing the hash, and what it is. Another way to get the hash is to use zig fetch, this is probably how you should do it :)

Download index.html and script.js from art-init

wget https://raw.githubusercontent.com/peterhellberg/art-init/refs/heads/main/content/index.html
wget https://raw.githubusercontent.com/peterhellberg/art-init/refs/heads/main/content/script.js

Then you can add the module in your build.zig like this:

const std = @import("std");

pub fn build(b: *std.Build) void {
    const exe = b.addExecutable(.{
        .name = "art-canvas",
        .root_module = b.createModule(.{
            .root_source_file = b.path("src/canvas.zig"),
            .target = b.resolveTargetQuery(.{
                .cpu_arch = .wasm32,
                .os_tag = .freestanding,
            }),
            .optimize = .ReleaseSmall,
            .strip = true,
        }),
    });

    exe.root_module.addImport("art", b.dependency("art", .{}).module("art"));

    const number_of_pages = 4;

    exe.entry = .disabled;
    exe.export_memory = true;
    exe.initial_memory = std.wasm.page_size * number_of_pages;
    exe.max_memory = std.wasm.page_size * number_of_pages;
    exe.stack_size = 512;
    exe.rdynamic = true;

    b.installArtifact(exe);
}

In your src/canvas.zig you should now be able to:

const art = @import("art");

var canvas: art.Canvas(16, 9) = .{};

export fn start() void {
    art.log("Hello from Zig!");
}

export fn update(pad: u32) void {
    _ = pad; // autofix
}

export fn draw() void {
    canvas.clear(.{ 0x7C, 0xAF, 0x3C, 0xFF });
}

export fn fps() usize {
    return 60;
}

export fn width() usize {
    return canvas.width;
}

export fn height() usize {
    return canvas.height;
}

export fn offset() [*]u8 {
    return canvas.offset();
}
View on GitHub
GitHub Stars7
CategoryDevelopment
Updated7mo ago
Forks0

Languages

Zig

Security Score

82/100

Audited on Aug 22, 2025

No findings