bitwise operations
This commit is contained in:
parent
96daec016f
commit
e718fbfe80
@ -40,7 +40,7 @@ export function picToBoard(pixels, board) {
|
|||||||
const flat = pixels.reduce((acc, pixel, index) => {
|
const flat = pixels.reduce((acc, pixel, index) => {
|
||||||
const i = index * 4;
|
const i = index * 4;
|
||||||
const count = pixels[i] + pixels[i + 1] + pixels[i + 2];
|
const count = pixels[i] + pixels[i + 1] + pixels[i + 2];
|
||||||
const value = count >= 255 ? 1 : 0;
|
const value = (count >= 255) & 1;
|
||||||
acc[index] = value;
|
acc[index] = value;
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
@ -58,8 +58,7 @@ export function boardToPic(board) {
|
|||||||
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.flat().reduce((acc, cell, index) => {
|
||||||
// TODO : bitshift operation instead of ternary
|
const color = colors[(cell === 1) & 1];
|
||||||
const color = cell === 1 ? colors[0] : colors[1];
|
|
||||||
const i = index * 4;
|
const i = index * 4;
|
||||||
acc[i] = color[0];
|
acc[i] = color[0];
|
||||||
acc[i + 1] = color[1];
|
acc[i + 1] = color[1];
|
||||||
|
Loading…
Reference in New Issue
Block a user