xxxxxxxxxx
69
/*
Experimental Photography
Interactive Media Arts @ NYU
Ellen Nickles
*------------------------------------*
USE IN CHROME
*------------------------------------*
ITP/IMA ER webcams and apps to adjust settings:
https://tinyurl.com/externalwebcams
----> mouse press to save Canvas <----
*/
let num = 0;
let canvasWidth = 1;
let canvasHeight = 1;
let webcams = [];
function setup() {
pixelDensity(1);
createCanvas(canvasWidth, canvasHeight);
getVideoDevices();
}
function draw() {
// mirror video devices
translate(width, 0);
scale(-1, 1);
if (webcams) {
for (let i = 0; i < webcams.length; i++) {
image(
webcams[i].vidElement,
i * canvasWidth,
0,
canvasWidth,
canvasHeight
);
// Only use with built-in camera if possible
// For external webcams use separate apps
// filter(GRAY);
}
}
}
function updateCanvas() {
let heights = [];
if (webcams) {
for (let webcam of webcams) {
let camWidth = int(webcam.constraints.video.width);
let camHeight = int(webcam.constraints.video.height);
heights.push(camHeight);
let minHeight = Math.min(heights);
if (camHeight === minHeight) {
canvasHeight = camHeight;
canvasWidth = camWidth;
}
}
}
resizeCanvas(canvasWidth * webcams.length, canvasHeight);
}
function mousePressed() {
num++;
saveCanvas(`pic${num}.png`);
}