xxxxxxxxxx
45
let video;
let colors = [
[200, 162, 200], // pastel purple
[255, 240, 120], // pastel yellow
[255, 182, 193], // pastel pink
[144, 238, 144], // pastel green
[173, 216, 230], // pastel blue
];
function setup() {
createCanvas(640, 480); // set the canvas size
video = createCapture(VIDEO); // capture video from the webcam
video.size(width / 10, height / 10); // scale down the video to create smaller pixelation
video.hide(); // hide the original video capture
}
function draw() {
// draw the video to the canvas
video.loadPixels(); // load pixel data from the video
for (let x = 0; x < video.width; x++) {
for (let y = 0; y < video.height; y++) {
// get the index for pixel data
let index = (x + y * video.width) * 4;
// get the brightness of the current pixel
let bright = brightness(color(video.pixels[index], video.pixels[index + 1], video.pixels[index + 2]));
fill( bright > 50? colors[int(random(colors.length))]:0)
// set the fill color based on brightness
// if (bright > 50) {
// // choose a pastel color based on brightness
// fill(colors[int(random(colors.length))]); // select a random pastel color
// } else {
// fill(0); // highlight dark pixels in black
// }
// draw a rectangle for each pixel (10x10 pixels)
rect(x * 10, y * 10, 10, 10);
}
}
}