xxxxxxxxxx
89
// basic camera demo code
// arts 444
// grosser, apr 2019
let cam;
let xScale;
let yScale;
function setup() {
createCanvas(640,480);
// colorMode(HSB);
// setup the camera
cam = createCapture(VIDEO);
cam.size(120,80);
//cam.size(60,40);
cam.hide();
// setup some scale variables we'll use
// for sizing rects later
xScale = width/cam.width;
yScale = height/cam.height;
}
function draw() {
// background(220);
// fill(0, 10);
// rect(0, 0, width, height);
// tell p5 we're going to use the pixel []
cam.loadPixels();
// go through all the camera pixels in this frame
// first by row (y)
for(let y=0;y<cam.height;y++) {
// then by column (x)
for(let x=cam.width;x>=0;x--) {
// get the r,g,b of each pixel
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];
// if(mouseIsPressed) {
// print(r+","+g+","+b);
// }
// use that color to draw a rect to the screen
stroke(48);
colorMode(RGB);
let h = hue(color(r,g,b));
if(h > 210.35 && h < 499.78||h > 0 && h < 24) {
let i = (x-1+ y-1 * cam.width) * 4;
let r = cam.pixels[i+0];
let g = cam.pixels[i+1];
let b = cam.pixels[i+2];
// fill(50,10);
//fill(50)
fill(r,g,b);
} else {
fill(r,g,b);
}
// fill(hue(color(r,g,b)),100,100);
noStroke();
rect((cam.width-x-1)*xScale, y*yScale,xScale,yScale);
} // end x for()
} // end y for()
//also can try random(yScale,yScale)
// tell p5 we're done messing with pixel []
cam.updatePixels();
}
function mouseClicked() {
let c = get(mouseX,mouseY);
let h = hue(color(c[0],c[1],c[2]));
print(c[0]+","+c[1]+","+c[2]);
print(h);
}
//move pizels a little,
//add color to some portions
//change frames opacity
//CHANGE GREY PIXELS TO GET INFO OF SURROUNDING PIXELS....MAKE PPL DISAPEAR??