diff options
Diffstat (limited to 'index.html')
| -rw-r--r-- | index.html | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/index.html b/index.html new file mode 100644 index 0000000..d2ab090 --- /dev/null +++ b/index.html @@ -0,0 +1,42 @@ +<!DOCTYPE html> +<html> + <head> + <script type="module"> + async function init() { + const { instance } = await WebAssembly.instantiateStreaming( + fetch("./graphics.wasm") + ); + + const width = 600; + const height = 600; + const bytes_per_pixel = 4; + + const canvas = document.getElementById("graphics-canvas"); + 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, + bytes_per_pixel * width * height, + ), + width, + height, + ); + + const ctx = canvas.getContext("2d"); + + instance.exports.go(buffer_address, width, height); + + ctx.putImageData(image, 0, 0); + } + + init(); + </script> + </head> + <body> + <canvas id="graphics-canvas"></canvas> + </body> +</html> |
