From e718fbfe80a92e5e6e7ed4b54fad4aa9c0736ef4 Mon Sep 17 00:00:00 2001 From: Gator Date: Tue, 27 Dec 2022 11:24:14 +0100 Subject: [PATCH] bitwise operations --- src/modules/picture.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/modules/picture.js b/src/modules/picture.js index a65e566..117d358 100644 --- a/src/modules/picture.js +++ b/src/modules/picture.js @@ -40,7 +40,7 @@ export function picToBoard(pixels, board) { const flat = pixels.reduce((acc, pixel, index) => { const i = index * 4; const count = pixels[i] + pixels[i + 1] + pixels[i + 2]; - const value = count >= 255 ? 1 : 0; + const value = (count >= 255) & 1; acc[index] = value; return acc; }, []); @@ -58,8 +58,7 @@ export function boardToPic(board) { const img = new ImageData(board.width, board.height); const colors = [hexToRGB(live), hexToRGB(dead)]; board.grid.flat().reduce((acc, cell, index) => { - // TODO : bitshift operation instead of ternary - const color = cell === 1 ? colors[0] : colors[1]; + const color = colors[(cell === 1) & 1]; const i = index * 4; acc[i] = color[0]; acc[i + 1] = color[1];