JSFiddle - React, Tailwind, and code Playground
by Josh Pullen
CSS
canvas {
border: 1px solid black;
max-width: calc(100vw - 20px);
max-height: calc(100vh - 20px);
}
JavaScript
function render(canvas, ctx) {
ctx.beginPath();
for (let x = -3; x <= 3; x++) {
ctx.moveTo(x, -100);
ctx.lineTo(x, -100);
}
for (let y = -3; y <= 3; y++) {
ctx.moveTo(-100, y);
ctx.lineTo(100, y);
}
ctx.strokeStyle = "#ddd";
ctx.lineWidth = 0.05;
ctx.stroke();
}
const canvas = document.createElement("canvas");
const ctx = canvas.getContext("2d");
canvas.width = 640;
canvas.height = 480;
document.body.appendChild(canvas);
ctx.clearRect(0, 0, canvas.width, canvas.height);
ctx.translate(canvas.width / 2, canvas.height / 2);
ctx.scale(100, -100);
render(canvas, ctx);