Compare commits

..

No commits in common. "d3af692502d9caf2e3bc82368f496301dfee76d2" and "a567b565e9e6a895c55522e3b78c9e6b69caf501" have entirely different histories.

4 changed files with 10 additions and 18 deletions

View File

@ -3,7 +3,7 @@
"version": "0.1.0", "version": "0.1.0",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "vite --host", "dev": "vite",
"build": "vite build", "build": "vite build",
"serve": "vite preview", "serve": "vite preview",
"lint": "eslint --ext .js,.vue --ignore-path .gitignore --fix src", "lint": "eslint --ext .js,.vue --ignore-path .gitignore --fix src",

View File

@ -47,10 +47,6 @@
canvasHeight: "canvasHeight", canvasHeight: "canvasHeight",
getReset: "reset", getReset: "reset",
}), }),
// used to determine the dimensions of the board
max() {
return Math.max(this.boardWidth, this.boardHeight);
},
}, },
watch: { watch: {
getDraw1d(value) { getDraw1d(value) {
@ -80,7 +76,6 @@
"setBoardWidth", "setBoardWidth",
"setBoardHeight", "setBoardHeight",
]), ]),
// draws the board on the canvas
drawCanvas(board) { drawCanvas(board) {
const props = this.cellProperties; const props = this.cellProperties;
board.map((row, y) => { board.map((row, y) => {
@ -97,22 +92,22 @@
}); });
}); });
}, },
// create a first state, either a single living cell
// at the center or random ones
compute1dInitialState() { compute1dInitialState() {
if (this.initial1dState === "onecell") if (this.initial1dState === "onecell")
return create1dStateOneCell(this.boardWidth); return create1dStateOneCell(this.boardWidth);
return create1dState(this.boardWidth, getRandomInt, [0, 2]); return create1dState(this.boardWidth, getRandomInt, [0, 2]);
}, },
// draw elementary automaton on the canvas based on selected ruleset
draw1d() { draw1d() {
const initialState = this.compute1dInitialState(); const initialState = this.compute1dInitialState();
const board = createBoard(initialState, this.ruleset.rules, this.max); const board = createBoard(
initialState,
this.ruleset.rules,
this.boardWidth
);
this.lastBoard = Object.freeze(board); this.lastBoard = Object.freeze(board);
this.drawCanvas(board); this.drawCanvas(board);
this.toggleStop(); this.toggleStop();
}, },
// draw 2D automaton on the canvas (currently only the game of life)
draw2d(board) { draw2d(board) {
if (!this.canDraw) return; if (!this.canDraw) return;
const draw2dNext = async (b) => { const draw2dNext = async (b) => {
@ -124,7 +119,6 @@
}; };
return draw2dNext(board); return draw2dNext(board);
}, },
// draw 2d automaton from a new state
draw2dNew() { draw2dNew() {
const initialState = create2dState( const initialState = create2dState(
this.boardWidth, this.boardWidth,
@ -136,11 +130,9 @@
this.lastBoard = Object.freeze(board); this.lastBoard = Object.freeze(board);
this.draw2d(board); this.draw2d(board);
}, },
// draw 2d automaton from the last known generated board
async draw2dLast() { async draw2dLast() {
if (this.lastBoard != undefined) this.draw2d(this.lastBoard); if (this.lastBoard != undefined) this.draw2d(this.lastBoard);
}, },
// stop drawing routines and clear the canvas
reset() { reset() {
this.toggleStop(); this.toggleStop();
this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height); this.ctx.clearRect(0, 0, this.canvas.width, this.canvas.height);

View File

@ -25,6 +25,7 @@
emits: ["update-active"], emits: ["update-active"],
computed: { computed: {
isActive() { isActive() {
console.log(this.rowTitle, "vs", this.active);
return this.rowTitle == this.active; return this.rowTitle == this.active;
}, },
}, },

View File

@ -31,12 +31,11 @@ function evolve1d(state, rules) {
// } // }
// performance "choke point" in full imperative // performance "choke point" in full imperative
function createBoard(state, rules, max) { function createBoard(state, rules, height) {
var board = []; var board = [];
let prevState = []; let prevState = [];
for (let i = 0; i < max; i++) { for (let i = 0; i < height; i++) {
let nextState = []; let nextState = [];
// use the passed initial step during first iteration
if (i == 0) { if (i == 0) {
nextState = evolve1d(state, rules); nextState = evolve1d(state, rules);
} else { } else {
@ -122,7 +121,7 @@ function getDrawingValues(state, acc, cell) {
// Populates the first state with a single living cell in the center // Populates the first state with a single living cell in the center
function create1dStateOneCell(width) { function create1dStateOneCell(width) {
return [...Array(width)].map((cell, index) => { return [...Array(width)].map((cell, index) => {
if (index === Math.floor(width / 2)) return 1; if (index === width / 2 || index === width + 1 / 2) return 1;
return 0; return 0;
}); });
} }