A 3D math playground visualizing on a canvas trait which the user needs to implement e.g. using XCB or a HTML5 Canvas for drawing as WebAssembly application. (Both exists in separate projects.)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
962 B

import { View3d } from "wasm-game-of-life";
import { memory } from "wasm-game-of-life/wasm_game_of_life_bg";
// 3D canvas stuff
const view3d = View3d.new(300, 300);
const view3d_canvas = document.getElementById("view3d");
view3d_canvas.width = view3d.width();
view3d_canvas.height = view3d.height();
const view3d_ctx = view3d_canvas.getContext('2d');
const view3d_renderLoop = () => {
view3d.update();
drawView3d();
requestAnimationFrame(view3d_renderLoop);
}
const drawView3d = () => {
const view3d_imagePtr = view3d.image();
const view3d_image = new ImageData(
new Uint8ClampedArray( memory.buffer
, view3d.image()
, view3d.width() * view3d.height() * 4 )
, view3d.width()
, view3d.height() );
view3d_ctx.putImageData(view3d_image, 0, 0);
}
// start everything ...
view3d.update();
drawView3d();
requestAnimationFrame(view3d_renderLoop);