xxxxxxxxxx
30
let cam;
let xScale;
let yScale;
function setup() {
createCanvas(600, 600);
cam = createCapture(VIDEO);
cam.size(600,600);
cam.hide();
xScale = width/cam.width;
yScale = height/cam.height;
}
function draw() {
background(220);
cam.loadPixels();
for(let y = 0; y < cam.height; y++){
for(let x = 0; x< cam.width; x++) {
let i = (x + y * cam.width) *4;
let r = cam.pixels[i+0];
let g = cam.pixels[i+1];
let b = cam.pixels[i+2];
noStroke();
fill(r,g,b);
rect(x*xScale,y*yScale,xScale,yScale);
}
}
cam.updatePixels();
}