import { RenderedGrid } from "./renderGrid"; import colors from "open-color"; export default function drawGrid( ctx: CanvasRenderingContext2D, grid: RenderedGrid, ) { ctx.clearRect(0, 0, grid.rect.width, grid.rect.height); ctx.fillStyle = colors.gray[8]; ctx.fillRect(0, 0, grid.rect.width, grid.rect.height); ctx.strokeStyle = colors.gray[7]; grid.renderedRows.forEach((row, renderedRowIndex) => { const isLastRow = renderedRowIndex === grid.renderedRows.length - 1; row.renderedCells.forEach((cell, cellIndex) => { const { topLeft, width, height } = cell.rect; const isLastCell = cellIndex === row.renderedCells.length - 1; ctx.strokeRect( topLeft.x + 0.5, topLeft.y + 0.5, isLastCell ? width - 1 : width, isLastRow ? height - 1 : height, ); }); }); }