add frequence

This commit is contained in:
histausse 2021-05-11 21:52:01 +02:00
parent e36fb20761
commit b6e45e24cb
Signed by: histausse
GPG key ID: 67486F107F62E9E9

View file

@ -2,7 +2,7 @@ import { Universe, Cell } from "wasm-game-of-life";
// Import wasm memory
import { memory } from "wasm-game-of-life/wasm_game_of_life_bg";
const CELL_SIZE = 5;
const CELL_SIZE = 5; // px
const GRID_COLOR = "#CCCCCC";
const DEAD_COLOR = "#FFFFFF";
const ALIVE_COLOR = "#000000";
@ -17,11 +17,21 @@ canvas.width = (CELL_SIZE + 1) * width + 1;
const ctx = canvas.getContext('2d');
const renderLoop = () => {
const PERIODE = 100; // ms
let start;
const renderLoop = (timestamp) => {
drawGrid();
drawCells();
if (start === undefined)
start = timestamp;
const elapsed = timestamp - start;
if (elapsed > PERIODE) {
universe.tick();
start = timestamp;
}
requestAnimationFrame(renderLoop);
};