mirror of
https://github.com/bspeice/speice.io
synced 2024-12-22 16:48:10 -05:00
44 lines
772 B
TypeScript
44 lines
772 B
TypeScript
// hidden-start
|
|
import { camera } from "./cameraGasket";
|
|
|
|
// hidden-end
|
|
function imageIndex(
|
|
x: number,
|
|
y: number,
|
|
width: number
|
|
) {
|
|
return y * (width * 4) + x * 4;
|
|
}
|
|
|
|
export function plot(
|
|
x: number,
|
|
y: number,
|
|
img: ImageData
|
|
) {
|
|
let [pixelX, pixelY] =
|
|
camera(x, y, img.width);
|
|
|
|
// Skip coordinates outside the display
|
|
if (
|
|
pixelX < 0 ||
|
|
pixelX >= img.width ||
|
|
pixelY < 0 ||
|
|
pixelY >= img.height
|
|
)
|
|
return;
|
|
|
|
const i = imageIndex(
|
|
pixelX,
|
|
pixelY,
|
|
img.width
|
|
);
|
|
|
|
// Set the pixel to black by setting
|
|
// the first three elements to 0
|
|
// (red, green, and blue, respectively),
|
|
// and 255 to the last element (alpha)
|
|
img.data[i] = 0;
|
|
img.data[i + 1] = 0;
|
|
img.data[i + 2] = 0;
|
|
img.data[i + 3] = 0xff;
|
|
} |