import type { Graphics } from 'pixi.js'; /** Side of one square of the transparency checkerboard, in screen pixels. */ const CHECKER_SIZE = 8; const CHECKER_DARK = 0x1a1c21; const CHECKER_LIGHT = 0x24272e; /** * The checkerboard behind a picture at (x, y, w, h). Only squares inside `0..clipW × 0..clipH` are * drawn: a 4000 px sheet zoomed in would otherwise cost tens of thousands of rectangles per redraw. */ export function drawChecker( g: Graphics, x: number, y: number, w: number, h: number, clipW: number, clipH: number, ): void { if (w <= 0 || h <= 0) return; g.rect(x, y, w, h).fill(CHECKER_DARK); const from = (start: number, limit: number) => Math.max(0, Math.floor((limit - start) / CHECKER_SIZE)); const x0 = from(x, 0); const y0 = from(y, 0); const x1 = Math.min(Math.ceil(w / CHECKER_SIZE), from(x, clipW) + 1); const y1 = Math.min(Math.ceil(h / CHECKER_SIZE), from(y, clipH) + 1); for (let cy = y0; cy < y1; cy++) { for (let cx = x0; cx < x1; cx++) { if ((cx + cy) % 2 === 0) continue; g.rect( x + cx * CHECKER_SIZE, y + cy * CHECKER_SIZE, Math.min(CHECKER_SIZE, w - cx * CHECKER_SIZE), Math.min(CHECKER_SIZE, h - cy * CHECKER_SIZE), ); } } g.fill(CHECKER_LIGHT); }