1
Fork 0
simplesailing/front/index.js
Andy Killorin 63f6a46482
stuff on-screen
also made a full justfile for web3 (wrong three) codegolfing (no node)

blitting works thanks to http://cliffle.com/blog/bare-metal-wasm/
2023-08-25 20:57:26 -05:00

35 lines
766 B
JavaScript

async function init() {
const { instance } = await WebAssembly.instantiateStreaming(
fetch("./pirates.wasm")
);
const width = 600;
const height = 600;
const canvas = document.getElementById("window");
canvas.width = width;
canvas.height = height;
const buffer_address = instance.exports.BUFFER.value;
const image = new ImageData(
new Uint8ClampedArray(
instance.exports.memory.buffer,
buffer_address,
4 * width * height,
),
width,
);
const ctx = canvas.getContext("2d");
const render = () => {
instance.exports.frame_entry();
ctx.putImageData(image, 0, 0);
requestAnimationFrame(render);
}
render();
}
init();