xxxxxxxxxx
31
let myVideo;
function setup() {
createCanvas(1000, 800, WEBGL);
myVideo = createCapture(VIDEO);
myVideo.size(1000, 800);
myVideo.hide();
}
function draw() {
background(0);
translate(-width/2, -height/2);
myVideo.loadPixels();
noStroke();
for (let y = 0; y < myVideo.height; y += 10) {
for (let x = 0; x < myVideo.width; x += 10) {
let index = (x + y * myVideo.width) * 4;
let r = myVideo.pixels[index + 0];
let g = myVideo.pixels[index + 1];
let b = myVideo.pixels[index + 2];
let brightness = (r + g + b) / 5;
let sze = map(brightness, 255, 0, 30, 0);
let depth = map(brightness, 255, 0, 0, -100);
push();
translate(x, y, depth);
fill(255, 255, 255, map(brightness, 0, 255, 0, 255));
ellipse(0, 0, sze, sze);
pop();
}
}
}