boardToPic
This commit is contained in:
@ -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));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user