xxxxxxxxxx
let capture;
let page_number = 1;
function setup() {
createCanvas(320, 240);
capture = createCapture({
audio: false,
video: { width: 320, height: 240 }
})
//capture = createCapture(VIDEO);
capture.hide();
imageMode(CENTER);
rectMode(CENTER);
console.log('capture ready.'); //letting us know that webcam works
}
function draw() {
if (page_number == 1){
background(167, 199, 231);
fill(150, 22, 209);
noStroke();
capture.loadPixels();
const 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;
rectMode (CENTER);
rect(x, y, radius, radius);
}
}
}
if (page_number == 2){
background(250);
image(capture, 160, 120, 320, 240)
filter(INVERT);
fill(0, 150, 255);
noStroke();
rect(160, 50, 120, 40);
rect(100, 120, 40, 130);
rect(220, 120, 40, 130);
fill(250, 95, 85);
ellipse(100, 50, 20, 30);
ellipse(100, 80, 20, 30);
ellipse(80, 65, 30, 20);
ellipse(120, 65, 30, 20);
}
}
function keyPressed(){
page_number ++;
if (page_number > 2){
page_number =1;
}
}