xxxxxxxxxx
34
let vScale = 12;
function setup() {
createCanvas(400, 400);
pixelDensity(1);
cam = createCapture(VIDEO);
cam.size(width / vScale, height / vScale);
noStroke();
}
function draw() {
background(220);
cam.loadPixels();
for (let y = 0; y < cam.height; y++){
for(let x = 0; x < cam.width; x++){
let index = (x + y * cam.width) * 4;
let r = cam.pixels[index+0];
let g = cam.pixels[index+1];
let b = cam.pixels[index+2];
let brightVal = (r+g+b)/3;
let thresholdVal = 255/2;
if (brightVal > thresholdVal) {
fill(255);
} else {
fill(0);
}
rect(x*vScale, y*vScale, 20, 20);
}
}
}