xxxxxxxxxx
39
// modified p5.js reference example pixel array
function setup() {
createCanvas(1920/4, 1080/4);
//pixelDensity(1); // fix for high density displays
capture = createCapture(VIDEO);
capture.size(1920/4, 1080/4);
//capture.hide();
}
function draw() {
background(222);
loadPixels();
capture.loadPixels();
let d = pixelDensity();
for (let x = 0; x < width *d ; x++) {
for (let y = 0; y < height *d; y++) {
//let index = (y + x * width) * 4;
let index = (x + y * width) * 4*d; // Corrected index formula
// Red.
// Red.
pixels[index] = capture.pixels[index];
// Green.
pixels[index + 1] = 0;
// Blue.
pixels[index + 2] = 0;
// Alpha.
pixels[index + 3] = 255;
}
}
updatePixels();
capture.updatePixels();
}