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 {
nextState = evolve1d(prevState, rules);
}
board = board.concat([nextState]);
// flat array
board.push(...nextState);
prevState = nextState;
}
return board;

View File

@ -57,7 +57,7 @@ export function boardToPic(board) {
const dead = board.cellProperties.deadColor;
const img = new ImageData(board.width, board.height);
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 i = index * 4;
acc[i] = color[0];