xxxxxxxxxx
37
let video;
let vScale = 16;
function setup() {
createCanvas(640, 480, WEBGL);
video = createCapture(VIDEO);
video.size(width / vScale, height / vScale);
video.hide();
}
function draw() {
background(50);
lights();
video.loadPixels();
rotateX(frameCount * 0.001);
rotateZ(frameCount * 0.001);
for (let y = 0; y < video.height; y = y + 1) {
for (let x = 0; x < video.width; x = x + 1) {
let index = 4 * x + 4 * (y * video.width);
let r = video.pixels[index + 0];
let g = video.pixels[index + 1];
let b = video.pixels[index + 2];
let bright = (r + g + b) / 3;
// Map brightness to scale in Y-axis
let scaleY = map(bright, 0, 255, 0, vScale);
// Draw a scaled rectangle in 3D space
push();
translate(x * vScale - width / 2, y * vScale - height / 2, 0);
noStroke();
box(vScale, vScale, scaleY * vScale);
pop();
}
}
}