I'm trying to create a JS Function (nodeJS) that takes in width, height, padding (size of each square) and line width. I'd like to fit the grid perfectly into the provided width and height. Right now, it's not working.
When I put in the line width, it gives me a black box. When it's gone, it prints out a grid.
let left = 0;
let top = 0;
let bottom = canvas.height;
let right = canvas.width;
ctx.lineWidth = lineWidth;
ctx.beginPath();
for (let x=left; x<right; x+=padding) {
ctx.moveTo(x, top);
ctx.lineTo(x, bottom);
}
for (let y=top; y<bottom; y+=padding) {
ctx.moveTo(left, y);
ctx.lineTo(right, y);
}
ctx.strokeStyle = "#000000";
ctx.stroke();
Any help would be appreciated. Thanks.