{"id":22836606,"url":"https://github.com/peterhellberg/art","last_synced_at":"2025-04-24T03:23:28.121Z","repository":{"id":267618853,"uuid":"868860979","full_name":"peterhellberg/art","owner":"peterhellberg","description":"art is a Zig module used to build WebAssembly binaries rendering to a HTML canvas.","archived":false,"fork":false,"pushed_at":"2025-03-04T16:12:23.000Z","size":13,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T06:24:58.512Z","etag":null,"topics":["canvas","wasm","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterhellberg.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-07T10:07:27.000Z","updated_at":"2025-03-04T16:12:27.000Z","dependencies_parsed_at":"2024-12-11T12:30:00.995Z","dependency_job_id":"7d420b30-dda2-4ebd-93db-3e9c6191c9d3","html_url":"https://github.com/peterhellberg/art","commit_stats":null,"previous_names":["peterhellberg/art"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fart","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fart/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fart/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterhellberg%2Fart/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterhellberg","download_url":"https://codeload.github.com/peterhellberg/art/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250553038,"owners_count":21449327,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["canvas","wasm","zig-package"],"created_at":"2024-12-12T23:11:48.618Z","updated_at":"2025-04-24T03:23:28.108Z","avatar_url":"https://github.com/peterhellberg.png","language":"Zig","readme":"# art :art:\n\nart is a [Zig](https://ziglang.org/) ⚡ module used to build\n[WebAssembly](https://webassembly.org/) binaries rendering to a\n[HTML canvas](https://developer.mozilla.org/en-US/docs/Web/API/Canvas_API).\n\n\u003e [!IMPORTANT]\n\u003e You might want to install the [art-init](https://github.com/peterhellberg/art-init) tool\n\u003e and use that instead of manually creating the files needed to use this library.\n\n## Usage\n\nYou can have `zig build` retrieve the `art` module if you specify it as a dependency.\n\n### Create a `build.zig.zon` that looks something like this:\n```zig\n.{\n    .name = .art_canvas,\n    .version = \"0.0.0\",\n    .fingerprint = 0x0000000000,\n    .paths = .{\"\"},\n    .dependencies = .{\n        .art = .{\n            .url = \"https://github.com/peterhellberg/art/archive/refs/tags/v0.0.9.tar.gz\",\n        },\n    },\n}\n```\n\n\u003e [!NOTE]\n\u003e If you leave out the hash then `zig build` will tell you that it is missing the hash, and what it is.\n\u003e Another way to get the hash is to use `zig fetch`, this is probably how you _should_ do it :)\n\n### Download `index.html` and `script.js` from `art-init`\n\n```console\nwget https://raw.githubusercontent.com/peterhellberg/art-init/refs/heads/main/content/index.html\nwget https://raw.githubusercontent.com/peterhellberg/art-init/refs/heads/main/content/script.js\n```\n\n### Then you can add the module in your `build.zig` like this:\n\n```zig\nconst std = @import(\"std\");\n\nconst number_of_pages = 4;\n\npub fn build(b: *std.Build) void {\n    const exe = b.addExecutable(.{\n        .name = \"art-canvas\",\n        .root_source_file = b.path(\"src/canvas.zig\"),\n        .target = b.resolveTargetQuery(.{\n            .cpu_arch = .wasm32,\n            .os_tag = .freestanding,\n        }),\n        .optimize = .ReleaseSmall,\n        .strip = true,\n    });\n\n    exe.root_module.addImport(\"art\", b.dependency(\"art\", .{}).module(\"art\"));\n\n    exe.root_module.export_symbol_names = \u0026[_][]const u8{\n        \"start\",\n        \"update\",\n        \"draw\",\n        \"fps\",\n        \"width\",\n        \"height\",\n        \"offset\",\n    };\n\n    exe.entry = .disabled;\n    exe.export_memory = true;\n    exe.initial_memory = std.wasm.page_size * number_of_pages;\n    exe.max_memory = std.wasm.page_size * number_of_pages;\n    exe.stack_size = 512;\n\n    b.installArtifact(exe);\n}\n```\n\n### In your `src/canvas.zig` you should now be able to:\n\n```zig\nconst art = @import(\"art\");\n\nvar canvas: art.Canvas(16, 9) = .{};\n\nexport fn start() void {\n    art.log(\"Hello from Zig!\");\n}\n\nexport fn update(pad: u32) void {\n    _ = pad; // autofix\n}\n\nexport fn draw() void {\n    canvas.clear(.{ 0x7C, 0xAF, 0x3C, 0xFF });\n}\n\nexport fn fps() usize {\n    return 60;\n}\n\nexport fn width() usize {\n    return canvas.width;\n}\n\nexport fn height() usize {\n    return canvas.height;\n}\n\nexport fn offset() [*]u8 {\n    return canvas.offset();\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Fart","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterhellberg%2Fart","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterhellberg%2Fart/lists"}