xxxxxxxxxx
39
let numPixels;
let video;
let vScale = 16;
function setup() {
createCanvas(640, 480);
video = createCapture(VIDEO);
video.size(width, height);
video.hide();
}
function draw() {
video.loadPixels(); // Make the pixels of video available
for (let x = 0; x < video.width; x = x + 10) {
for (let y = 0; y < video.height; y = y +10) {
let pixel_index = 4*(x + y * video.width);
var currR = video.pixels[pixel_index + 0];
var currG = video.pixels[pixel_index + 1];
var currB = video.pixels[pixel_index + 2];
let bright = (currR, currG, currB) / 3;
// stroke(currR, currG, currB);
fill(currR,currG,currB,50);
strokeWeight(4);
if (currR > currG && currR > currB) {
stroke((random(currR, 255)), (random(0, currG)), (random(0, currB)));
let r = map(bright, 0, 255, 0, vScale);ellipse(x, y, r);
}
else if (currG > currR && currG > currB) {
stroke((random(0, currR)), (random(currG, 255)), (random(0, currB)));
square(random(0,200), random(0,200), 5);
}
else {
stroke((random(0, currR)), (random(0, currG)), (random(currB, 255)));
line(x, y, x + 8, y + 16);
}
}
}
}