xxxxxxxxxx
31
let vid;
function setup() {
createCanvas(400, 400);
vid = createCapture(VIDEO);
vid.hide();
//console.log(vid);
noStroke()
}
function draw() {
background(0);
vid.loadPixels();
for (let x = 0; x < vid.width; x += 20) {
for (let y = 0; y < vid.height; y += 20) {
let i = 4 * (y * vid.width + x);
let r = vid.pixels[i];
let g = vid.pixels[i + 1];
let b = vid.pixels[i + 2];
let a = vid.pixels[i + 3];
let value = brightness(b);
if (value > 50) {
fill(255);
} else if (value < 50) {
fill(0);
}
rect(x, y, 20, 20);
}
}
}