2024-12-11 19:56:39 -05:00
|
|
|
// hidden-start
|
|
|
|
import {camera} from "./cameraGasket"
|
|
|
|
// hidden-end
|
2024-12-08 19:53:06 -05:00
|
|
|
function imageIndex(
|
|
|
|
width: number,
|
|
|
|
x: number,
|
|
|
|
y: number
|
|
|
|
) {
|
|
|
|
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-11 19:56:39 -05:00
|
|
|
let [pixelX, pixelY] = camera(img.width, x, y);
|
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
|
|
|
img.width,
|
|
|
|
pixelX,
|
|
|
|
pixelY
|
2024-12-08 19:53:06 -05:00
|
|
|
);
|
2024-11-17 17:30:07 -05:00
|
|
|
|
2024-12-08 19:53:06 -05:00
|
|
|
// Skip pixels outside the display range
|
|
|
|
if (
|
2024-12-11 19:56:39 -05:00
|
|
|
i < 0 ||
|
|
|
|
i > img.data.length
|
2024-12-08 19:53:06 -05:00
|
|
|
) {
|
2024-12-08 22:50:46 -05:00
|
|
|
return;
|
2024-12-08 19:53:06 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set the pixel to black by writing 0
|
2024-12-11 19:56:39 -05:00
|
|
|
// to the first three elements at the index
|
|
|
|
// (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
|
|
|
}
|