overpopulation rules

This commit is contained in:
Gator
2022-12-15 16:18:57 +01:00
parent c847e6c218
commit beab487429
5 changed files with 73 additions and 5 deletions

View File

@ -21,6 +21,7 @@
create2dState,
createBoard,
conwayRules,
overpopulationRules,
evolve2d,
} from "../modules/automata.js";
import { getRandomInt, sleep } from "../modules/common.js";
@ -34,6 +35,10 @@
workCanvas: null,
workCtx: null,
ctx: null,
available2dRules: {
conway: conwayRules,
overpopulation: overpopulationRules,
},
};
},
computed: {
@ -51,6 +56,7 @@
boardWidth: "boardWidth",
boardHeight: "boardHeight",
picture: "picture",
selected2dRules: "selected2dRules",
}),
...mapWritableState(globalStore, {
lastBoard: "lastBoard",
@ -134,7 +140,10 @@
if (!this.canDraw) return;
const draw2dNext = async (b) => {
if (!this.canDraw) return;
const newBoard = evolve2d(b, conwayRules);
const newBoard = evolve2d(
b,
this.available2dRules[this.selected2dRules.id]
);
this.drawCanvas(b, this.cellProperties);
await sleep(this.refreshRate);
draw2dNext(newBoard);