-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
34 lines (34 loc) · 1.08 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8" />
<title>height map test</title>
</head>
<body>
<canvas style="width: 100%;" id="canvas" width="320" height="200">
</canvas>
<script type="module">
import init, { main, alloc_screen, screen_get_ptr, create_height_map } from "./pkg/height_map_test.js";
let angle = 0.0;
init().then((wasm) => {
let screen = alloc_screen();
let heightMap = create_height_map();
let canvas = document.getElementById("canvas");
let ctx = canvas.getContext("2d");
let screen_ptr = screen_get_ptr(screen);
let imgData = new Uint8ClampedArray(wasm.memory.buffer, screen_ptr, 4*64000);
let imgData2 = new ImageData(imgData, 320, 200);
let render = () => {
main(screen, heightMap, angle);
ctx.putImageData(imgData2, 0, 0);
angle += 1;
if (angle >= 360.0) {
angle -= 360.0;
}
requestAnimationFrame(render);
};
requestAnimationFrame(render);
});
</script>
</body>
</html>