xxxxxxxxxx
31
function setup() {
createCanvas(400, 400);
vid = createCapture(VIDEO);
vid.size(20, 20); // Set the video size to 20x20 pixels
vid.hide();
}
function draw() {
background(220);
vid.loadPixels();
for (let x = 0; x < vid.width; x++) {
for (let y = 0; y < vid.height; y++) {
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 c = color(r, g, b);
let brightValue = brightness(c);
if (brightValue > 50) {
fill(255); // White > 50% brightness
} else {
fill(0); // Black < 50% brightness
}
rect(x * 20, y * 20, 20, 20);
}
}
}