update last board, new rules
This commit is contained in:
@ -22,6 +22,8 @@
|
||||
createBoard,
|
||||
conwayRules,
|
||||
overpopulationRules,
|
||||
lonelinessRules,
|
||||
threebornRules,
|
||||
evolve2d,
|
||||
} from "../modules/automata.js";
|
||||
import { getRandomInt, sleep } from "../modules/common.js";
|
||||
@ -38,6 +40,8 @@
|
||||
available2dRules: {
|
||||
conway: conwayRules,
|
||||
overpopulation: overpopulationRules,
|
||||
loneliness: lonelinessRules,
|
||||
threeborn: threebornRules,
|
||||
},
|
||||
};
|
||||
},
|
||||
@ -89,9 +93,10 @@
|
||||
mounted() {
|
||||
this.canvas = Object.freeze(document.getElementById("board-canvas"));
|
||||
this.workCanvas = Object.freeze(document.getElementById("work-canvas"));
|
||||
this.ctx = this.canvas.getContext("2d");
|
||||
this.workCtx = this.workCanvas.getContext("2d");
|
||||
this.workCanvas.setAttribute("willReadFrequently", true);
|
||||
this.ctx = this.canvas.getContext("2d", { willReadFrequently: true });
|
||||
this.workCtx = this.workCanvas.getContext("2d", {
|
||||
willReadFrequently: true,
|
||||
});
|
||||
this.canvasWidth = this.canvas.parentElement.clientWidth;
|
||||
this.canvasHeight = this.canvas.parentElement.clientHeight;
|
||||
this.setBoardWidth();
|
||||
@ -135,7 +140,7 @@
|
||||
this.drawCanvas(this.lastBoard);
|
||||
this.toggleStop();
|
||||
},
|
||||
// draw 2D automaton on the canvas (currently only the game of life)
|
||||
// draw 2D automaton on the canvas in a loop
|
||||
draw2d(board) {
|
||||
if (!this.canDraw) return;
|
||||
const draw2dNext = async (b) => {
|
||||
@ -145,6 +150,7 @@
|
||||
this.available2dRules[this.selected2dRules.id]
|
||||
);
|
||||
this.drawCanvas(b, this.cellProperties);
|
||||
this.lastBoard = Object.freeze(newBoard);
|
||||
await sleep(this.refreshRate);
|
||||
draw2dNext(newBoard);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user