boardToPic

This commit is contained in:
2022-12-19 22:53:48 +01:00
parent f08dedba50
commit 7a13cd2107
2 changed files with 22 additions and 16 deletions

View File

@ -35,5 +35,19 @@ export function picToBoard(pixels, width, height) {
}
return acc;
}, []);
return toMatrix(flat, Math.max(width, height));
return toMatrix(flat, width, height);
}
// convert board to ImageData
export function boardToPic(board, width, height) {
return board.flat().reduce((acc, cell, index) => {
const color = cell === 1 ? 0 : 255;
const i = index * 4;
acc.data[i] = color;
acc.data[i + 1] = color;
acc.data[i + 2] = color;
acc.data[i + 3] = 255;
return acc;
}, new ImageData(width, height));
}