xxxxxxxxxx
28
let capture;
function setup() {
createCanvas(640, 480);
pixelDensity(1);
capture = createCapture(VIDEO);
capture.hide();
}
function draw() {
background(255);
capture.loadPixels(); // load video pixels array
loadPixels(); // load the pixels array
let d = pixelDensity(); // pixel density for the display
for (let y = 0; y < height * d; y++ ) {
for (let x = 0; x < width * d; x++) {
let index = (x + y * width * d) * 4;
pixels[index] = capture.pixels[index]; // Red.
pixels[index + 1] = capture.pixels[index +1]; // Green.
pixels[index + 2] = capture.pixels[index +2]; // Blue.
pixels[index + 3] = 255; // Alpha.
}
}
updatePixels(); // update pixels
}