xxxxxxxxxx
35
let capture;
function setup() {
createCanvas(640, 480);
capture = createCapture(VIDEO);
capture.size(100, 480);
capture.hide();
}
function draw() {
background(0);
capture.loadPixels();
for (let y = 0; y < capture.height; y++) {
for (let x = 0; x < capture.width; x++) {
let ind = (x + y * capture.width) * 4;
let r = capture.pixels[ind + 0]; //R
let g = capture.pixels[ind + 1]; //G
let b = capture.pixels[ind + 2]; //B
let bright = (r + g + b) / 3;
if (bright < 128) {
capture.pixels[ind + 0] = 0; //R
capture.pixels[ind + 1] = 0; //G
capture.pixels[ind + 2] = 0; //B
} else {
capture.pixels[ind + 0] = 255; //R
capture.pixels[ind + 1] = 255; //G
capture.pixels[ind + 2] = 255; //B
}
}
}
capture.updatePixels();
image(capture, 0, 0, width, height);
}