refresh rate, some attempts at optimizing

This commit is contained in:
Gator
2022-12-20 16:27:04 +01:00
parent 44d749ac4e
commit c825752405
3 changed files with 28 additions and 25 deletions

View File

@ -89,8 +89,8 @@
getDraw2d(value) {
if (value == true) this.draw2dNew();
},
getDraw2dLast(value) {
if (value == true) this.draw2dLast();
async getDraw2dLast(value) {
if (value == true) await this.draw2dLast();
},
getDraw2dPicture(value) {
if (value == true) this.draw2dPicture();
@ -118,10 +118,10 @@
"setBoardHeight",
]),
// draws the board on the canvas
drawCanvas(board, width, height) {
async drawCanvas(board, width, height) {
const d = this.cellProperties.size;
// bool to RGBA colors
const img = boardToPic(board, width, height, this.cellProperties);
const img = await boardToPic(board, width, height, this.cellProperties);
// rescale and draw
this.ctx.save();
this.ctx.clearRect(0, 0, this.canvasWidth, this.canvasHeight);
@ -168,14 +168,14 @@
this.lastBoard = Object.freeze(newBoard);
},
// draw 2d automaton in a loop, starting from passed state
async draw2dNext(board) {
requestAnimationFrame(() => {
if (!this.canDraw) return;
const newBoard = evolve2d(board, this.selectedRules);
this.draw2d(board);
this.lastBoard = Object.freeze(newBoard);
return this.draw2dNext(newBoard);
});
async draw2dNext(board, time) {
setTimeout(() => {
requestAnimationFrame(() => {
if (!this.canDraw) return;
this.draw2d(board);
return this.draw2dNext(this.lastBoard);
});
}, this.refreshRate);
},
// draw 2d automaton from a new state
async draw2dNew() {