refresh rate, some attempts at optimizing
This commit is contained in:
@ -54,13 +54,16 @@ export function picToBoard(pixels, width, height) {
|
||||
export function boardToPic(board, width, height, cellProperties) {
|
||||
const live = cellProperties.liveColor;
|
||||
const dead = cellProperties.deadColor;
|
||||
return board.flat().reduce((acc, cell, index) => {
|
||||
const color = cell === 1 ? hexToRGB(live) : hexToRGB(dead);
|
||||
const img = new ImageData(width, height);
|
||||
const colors = [hexToRGB(live), hexToRGB(dead)];
|
||||
board.flat().reduce((acc, cell, index) => {
|
||||
const color = colors[cell];
|
||||
const i = index * 4;
|
||||
acc.data[i] = color[0];
|
||||
acc.data[i + 1] = color[1];
|
||||
acc.data[i + 2] = color[2];
|
||||
acc.data[i + 3] = 255;
|
||||
acc[i] = color[0];
|
||||
acc[i + 1] = color[1];
|
||||
acc[i + 2] = color[2];
|
||||
acc[i + 3] = 255;
|
||||
return acc;
|
||||
}, new ImageData(width, height));
|
||||
}, img.data);
|
||||
return img;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user