class Grid {
constructor(numFilled, ctx) {
ctx.fillStyle = 'white';
ctx.globalAlpha = 1 - Math.abs(numFilled) / (gridSize ** 2 + 2);
let colsToFil = Math.floor(Math.abs(numFilled) / gridSize);
let remainder = Math.abs(numFilled) % gridSize;
const isEvenCol = colsToFil % 2;
const gridHeight = boxSize * gridSize;
if (numFilled < 0) {
ctx.translate(gridHeight, 0);
ctx.scale(-1, 1);
}
ctx.fillRect(0, 0, boxSize * colsToFil, gridHeight);
if (remainder) {
ctx.fillRect(
colsToFil * boxSize,
isEvenCol ? 0 : gridHeight,
boxSize,
remainder * boxSize * (isEvenCol ? 1 : -1)
);
}
ctx.fillStyle = 'transparent';
ctx.strokeStyle = '#152828';
ctx.strokeRect(0, 0, boxSize * gridSize, boxSize * gridSize);
}
}