createBoad : flat array

This commit is contained in:
Ali Gator 2022-12-30 23:47:01 +01:00
parent 745c197f09
commit f19f3bb311
2 changed files with 3 additions and 2 deletions

View File

@ -46,7 +46,8 @@ function createBoard(state, rules, max) {
} else { } else {
nextState = evolve1d(prevState, rules); nextState = evolve1d(prevState, rules);
} }
board = board.concat([nextState]); // flat array
board.push(...nextState);
prevState = nextState; prevState = nextState;
} }
return board; return board;

View File

@ -57,7 +57,7 @@ export function boardToPic(board) {
const dead = board.cellProperties.deadColor; const dead = board.cellProperties.deadColor;
const img = new ImageData(board.width, board.height); const img = new ImageData(board.width, board.height);
const colors = [hexToRGB(live), hexToRGB(dead)]; const colors = [hexToRGB(live), hexToRGB(dead)];
board.grid.flat().reduce((acc, cell, index) => { board.grid.reduce((acc, cell, index) => {
const color = colors[(cell === 1) & 1]; const color = colors[(cell === 1) & 1];
const i = index * 4; const i = index * 4;
acc[i] = color[0]; acc[i] = color[0];