fix evolve 2D #11

Merged
gator merged 7 commits from dev into master 2022-12-29 17:21:48 +01:00
Showing only changes of commit 71f8a9c8b5 - Show all commits

View File

@ -111,19 +111,19 @@
// draw 2D automaton on the canvas in a loop
const draw2d = (board) => {
store.board.grid = Object.freeze(evolve2d(board.grid, selectedRules()));
drawCanvas(store.board);
const newBoard = Object.freeze(evolve2d(board.grid, selectedRules()));
if (store.board.grid == newBoard) store.toggleStop();
store.board.grid = newBoard;
};
// draw 2d automaton in a loop, starting from passed state
const draw2dNext = async (board) => {
setTimeout(() => {
requestAnimationFrame(() => {
if (!store.canDraw) return;
draw2d(board);
return draw2dNext(store.board);
});
}, store.refreshRate);
if (!store.canDraw) return;
draw2d(board);
return draw2dNext(store.board);
}, store.renderer.refreshRate);
};
// draw 2d automaton from a new state