Created
July 8, 2023 17:53
-
-
Save sparky-raccoon/175daa4cebedba827bd554844c198109 to your computer and use it in GitHub Desktop.
A simple grid computed with canvas-sketch.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const canvasSketch = require("canvas-sketch"); | |
canvasSketch( | |
({ context, width, height }) => { | |
context.fillStyle = "white"; | |
context.fillRect(0, 0, width, height); | |
const cell = 10; | |
const cols = Math.floor(width / cell); | |
const rows = Math.floor(height / cell); | |
const numCells = cols * rows; | |
const cellWidth = width / cols; | |
const cellHeight = height / rows; | |
return ({ context }) => { | |
for (let c = 0; c < numCells; c++) { | |
const col = c % cols; | |
const row = Math.floor(c / cols); | |
context.save(); | |
context.translate(col * cellWidth, row * cellHeight); | |
context.beginPath(); | |
context.rect(0, 0, cellWidth, cellHeight); | |
context.stroke(); | |
context.restore(); | |
} | |
}; | |
}, | |
{} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment