import { COLOR } from "./colors.ts"; import { fillRect, setPixelColor } from "./window.ts"; export const inRect = (x: number, y: number, rectX: number, rectY: number, rectW: number, rectH: number) => { return ( x >= rectX && x < rectX+rectW && y >= rectY && y < rectY+rectH ) } export function reGridWithGap (x: number, y: number, gridX: number, gridY: number, cellW: number, cellH: number, gapX: number, gapY: number): {x: number, y: number} | null { const gx = Math.floor((x-gridX)/(cellW+gapX)); const gy = Math.floor((y-gridY)/(cellH+gapY)); if (x >= gridX+(cellW+gapX)*gx+cellW || y >= gridY+(cellH+gapY)*gy+cellH) { return null; } return { x: Math.floor((x-gridX)/(cellW+gapX)), y: Math.floor((y-gridY)/(cellH+gapY)), } } export function reGrid (x: number, y: number, gridX: number, gridY: number, cellW: number, cellH: number): {x: number, y: number} { const gx = Math.floor((x-gridX)/(cellW)); const gy = Math.floor((y-gridY)/(cellH)); return { x: gx, y: gy, } } export const outlineRect = (x: number, y: number, w: number, h: number, color: number) => { fillRect(x, y, w, 1, color); fillRect(x, y, 1, h, color); fillRect(x+w-1, y, 1, h, color); fillRect(x, y+h-1, w, 1, color); } export const drawTransparentRect = (x: number, y: number, w: number, h: number) => { Array(w*h).fill(0).map((_z, j) => { const jx = j%w; const jy = Math.floor(j/w); setPixelColor(x+jx, y+jy, (jx+jy)%2 ? COLOR.BLACK : COLOR.DARKGRAY); }) }