Last active
October 28, 2025 16:48
-
-
Save rileyjshaw/72c9d65e7003233836737404c348cec9 to your computer and use it in GitHub Desktop.
Quickly generate grid images to test shader positioning
This file contains hidden or 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 { createCanvas } = require('canvas'); | |
| const fs = require('fs'); | |
| const gridWidth = parseInt(process.argv[2]) || 16; | |
| const gridHeight = parseInt(process.argv[3]) || 16; | |
| const SQUARE_SIZE = 200; | |
| // Inferred. | |
| const WIDTH_PX = gridWidth * SQUARE_SIZE; | |
| const HEIGHT_PX = gridHeight * SQUARE_SIZE; | |
| const canvas = createCanvas(WIDTH_PX, HEIGHT_PX); | |
| const ctx = canvas.getContext('2d'); | |
| ctx.fillStyle = '#ffffff'; | |
| ctx.fillRect(0, 0, WIDTH_PX, HEIGHT_PX); | |
| // Select background color based on position. | |
| function getSquareColor(x, y) { | |
| const hue = (x / (gridWidth - 1)) * 240; // Red to blue. | |
| const saturation = 10 + (y / (gridHeight - 1)) * 90; // 10% to 100% saturation. | |
| const lightness = 50; | |
| return `hsl(${hue}, ${saturation}%, ${lightness}%)`; | |
| } | |
| function drawCenteredText(ctx, text, x, y, width, height, fontSize, color = '#000000') { | |
| ctx.fillStyle = color; | |
| ctx.font = `bold ${fontSize}px Arial`; | |
| ctx.textAlign = 'center'; | |
| ctx.textBaseline = 'middle'; | |
| const centerX = x + width / 2; | |
| const centerY = y + height / 2; | |
| ctx.fillText(text, centerX, centerY); | |
| } | |
| // Draw the grid. | |
| for (let row = 0; row < gridHeight; row++) { | |
| for (let col = 0; col < gridWidth; col++) { | |
| const x = col * SQUARE_SIZE; | |
| const y = row * SQUARE_SIZE; | |
| const color = getSquareColor(col, row); | |
| ctx.fillStyle = color; | |
| ctx.fillRect(x, y, SQUARE_SIZE, SQUARE_SIZE); | |
| ctx.strokeStyle = '#000000'; | |
| ctx.lineWidth = 2; | |
| ctx.strokeRect(x, y, SQUARE_SIZE, SQUARE_SIZE); | |
| const xPosition = col + 1; | |
| drawCenteredText(ctx, xPosition.toString(), x, y, SQUARE_SIZE, SQUARE_SIZE, 80, '#000000'); | |
| const yPosition = row + 1; | |
| drawCenteredText(ctx, yPosition.toString(), x, y + 60, SQUARE_SIZE, SQUARE_SIZE, 40, '#000000'); | |
| } | |
| } | |
| const buffer = canvas.toBuffer('image/png'); | |
| const filename = `grid_${gridWidth}_${gridHeight}.png`; | |
| fs.writeFileSync(filename, buffer); | |
| console.log(`Image generated successfully as "${filename}"`); | |
| console.log(`Image size: ${WIDTH_PX}x${HEIGHT_PX} pixels`); | |
| console.log(`Grid: ${gridWidth}x${gridHeight} squares of ${SQUARE_SIZE}x${SQUARE_SIZE} pixels each`); |
View raw
(Sorry about that, but we can’t show files that are this big right now.)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment





























































