stop button, loop skipped a frame

This commit is contained in:
2021-12-31 11:10:32 +01:00
parent 04db31e4f4
commit 39fc339776
3 changed files with 23 additions and 4 deletions

11
main.js
View File

@ -8,11 +8,12 @@ const dead = document.querySelector('#dead');
const live = document.querySelector('#live');
const startBtn = document.querySelector('#start');
const resetBtn = document.querySelector('#reset');
const stopBtn = document.querySelector('#stop');
const cellSize = document.querySelector('#cellSize');
const loop = document.querySelector('#loop');
canvas.width = main.offsetWidth;
canvas.height = main.offsetHeight;
canvas.width = main.offsetWidth * 0.9;
canvas.height = main.offsetHeight * 0.9;
// TODO: Hide iterator inside
function evolve(state, acc, rules) {
@ -89,7 +90,7 @@ async function draw(state, acc) {
await sleep(40);
const newAcc = () => {
if (position >= canvas.height && loop.checked) return 1;
if (position >= canvas.height && loop.checked) return 0;
return acc;
};
@ -118,3 +119,7 @@ startBtn.addEventListener('click', async () => {
resetBtn.addEventListener('click', async () => {
reset();
});
stopBtn.addEventListener('click', async () => {
drawing = 0;
});