refresh rate, some attempts at optimizing

This commit is contained in:
2022-12-20 16:27:04 +01:00
parent 7fb9ed8958
commit 9fe16c8406
3 changed files with 28 additions and 25 deletions

View File

@ -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;
}