Camera and outline rect functions

This commit is contained in:
dylan
2023-05-10 00:06:08 -07:00
parent b394f81477
commit e955a4c00d
6 changed files with 59 additions and 24 deletions

18
util.ts
View File

@@ -1,3 +1,6 @@
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 &&
@@ -26,4 +29,19 @@ export function reGrid (x: number, y: number, gridX: number, gridY: number, cell
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);
})
}