xxxxxxxxxx
28
let cam;
function setup() {
createCanvas(400, 400);
pixelDensity(1);
cam = createCapture(VIDEO);
cam.hide();
noStroke();
}
function draw() {
background(220);
image(cam, 0, 0);
cam.loadPixels();
for (let x = 0; x < cam.width; x += 10) {
for (let y = 0; y < cam.height; y += 10) {
let colorFromVideo = cam.get(x, y);
let b = brightness(colorFromVideo);
if (b > 50) fill('white')
else fill('black');
rect(x, y, 10, 10);
}
}
}