createBoad : flat array
This commit is contained in:
parent
745c197f09
commit
f19f3bb311
@ -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;
|
||||||
|
@ -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];
|
||||||
|
Loading…
Reference in New Issue
Block a user