Skip to content

Instantly share code, notes, and snippets.

@sparky-raccoon
Created July 8, 2023 17:53
Show Gist options
  • Save sparky-raccoon/175daa4cebedba827bd554844c198109 to your computer and use it in GitHub Desktop.
Save sparky-raccoon/175daa4cebedba827bd554844c198109 to your computer and use it in GitHub Desktop.
A simple grid computed with canvas-sketch.
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