2024-12-11 19:56:39 -05:00
|
|
|
// hidden-start
|
2024-12-15 21:19:09 -05:00
|
|
|
import { camera } from "./cameraGasket";
|
|
|
|
|
2024-12-11 19:56:39 -05:00
|
|
|
// hidden-end
|
2024-12-08 19:53:06 -05:00
|
|
|
function imageIndex(
|
|
|
|
x: number,
|
2024-12-15 21:19:09 -05:00
|
|
|
y: number,
|
|
|
|
width: number
|
2024-12-08 19:53:06 -05:00
|
|
|
) {
|
|
|
|
return y * (width * 4) + x * 4;
|
|
|
|
}
|
2024-11-17 17:30:07 -05:00
|
|
|
|
2024-12-08 19:53:06 -05:00
|
|
|
export function plot(
|
|
|
|
x: number,
|
|
|
|
y: number,
|
|
|
|
img: ImageData
|
|
|
|
) {
|
2024-12-15 21:19:09 -05:00
|
|
|
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;
|
2024-11-17 17:30:07 -05:00
|
|
|
|
2024-12-11 19:56:39 -05:00
|
|
|
const i = imageIndex(
|
2024-12-08 22:50:46 -05:00
|
|
|
pixelX,
|
2024-12-15 21:19:09 -05:00
|
|
|
pixelY,
|
|
|
|
img.width
|
2024-12-08 19:53:06 -05:00
|
|
|
);
|
2024-11-17 17:30:07 -05:00
|
|
|
|
2024-12-15 21:19:09 -05:00
|
|
|
// Set the pixel to black by setting
|
|
|
|
// the first three elements to 0
|
2024-12-11 19:56:39 -05:00
|
|
|
// (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;
|
2024-11-17 17:30:07 -05:00
|
|
|
}
|