add frequence

master
histausse 3 years ago
parent e36fb20761
commit b6e45e24cb
Signed by: histausse
GPG Key ID: 67486F107F62E9E9

@ -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();
universe.tick();
if (start === undefined)
start = timestamp;
const elapsed = timestamp - start;
if (elapsed > PERIODE) {
universe.tick();
start = timestamp;
}
requestAnimationFrame(renderLoop);
};

Loading…
Cancel
Save