xxxxxxxxxx
let capture;
function setup() {
capture = createCapture(VIDEO);
capture.size(480, 320);
createCanvas(capture.width, capture.height);
capture.hide();
noStroke();
}
function draw() {
if (!capture) {
//do nothing if the webcam capture isn't ready yet.
return;
}
//get the current video image into an image for quicker access
let img = capture.get(0, 0, capture.width, capture.height);
//prepare the image to be queried about its pixels
img.loadPixels();
const pixelColour = img.get(mouseX, mouseY);
fill(pixelColour);
square(mouseX, mouseY, 20);
}
function mousePressed() {
if (random([true, false])) {
image(capture, 0, 0)
} else {
background(255);
}
}