wip picture to board

This commit is contained in:
2022-12-20 11:59:48 +01:00
parent 9684ac5b8c
commit cfe233b056
2 changed files with 25 additions and 7 deletions

View File

@ -28,11 +28,10 @@ export function picToBlackAndWhite(pixels, width, height) {
// convert an ImageData into a 2D array of boolean (0, 1) values
export function picToBoard(pixels, width, height) {
const flat = pixels.reduce((acc, pixel, index) => {
if (index % 4 == 0) {
const count = pixels[index] + pixels[index + 1] + pixels[index + 2];
const value = count >= 255 ? 1 : 0;
acc[index] = value;
}
const i = index * 4;
const count = pixels[i] + pixels[i + 1] + pixels[i + 2];
const value = count >= 255 ? 1 : 0;
acc[index] = value;
return acc;
}, []);