xxxxxxxxxx
let capture; //creating a video variable for webcam footage
function setup() { //function setup
createCanvas(320, 240);
// specify multiple formats for different browsers
capture = createCapture({ //assigning a value to wwebcam variable
audio: false, //turning off audio
video: { width: 320, height: 240 } //setting width and height
}, function() { //creating a function
console.log('capture ready.'); //printing to the console to let us know that webcam works.
});
capture.hide(); //hides raw camera footage that sits off canvas
noStroke(); //gets rid of outline
fill(106, 154, 168);
}
function draw() {
background(242, 233, 56);
capture.loadPixels();
//const stepSize = round(constrain(mouseX / 8, 6, 32));
let stepSize = 5
for (let y = 0; y < height; y += stepSize) {
for (let x = 0; x < width; x += stepSize) {
const i = y * width + x;
const darkness = (255 - capture.pixels[i * 4]) / 255;
const radius = stepSize * darkness;
rect(x, y, radius, radius);
}
}
}