xxxxxxxxxx
121
let cam;
let threshold;
let filterX = [44, 525, 525, 424, 300];
let filterY = [32, 68, 531, 502, 300];
let filter_index = 0;
let xoff;
let start = 0;
let h, m, s, d, mo, y;
function setup() {
let canvas = createCanvas(600, 600);
//load camera
cam = createCapture(VIDEO);
cam.size(600, 600);
cam.hide();
noStroke();
//pixelDensity(1);
// frameRate(3);
}
function draw() {
//noise color
xoff = start;
xoff = xoff + 1;
let cNoise = noise(xoff) * 50;
start += 1;
background(0);
threshold = 100;
//call pixels from camera
cam.loadPixels();
//draw a grid of pixels onto the canvas
for (x = -10; x < width; x = x + 10) {
for (y = -10; y < height; y = y + 10) {
//call RGB values within pixels
index = (x + y * cam.width) * 4;
// RGB index
r = cam.pixels[index + 0];
g = cam.pixels[index + 1];
b = cam.pixels[index + 2];
a = cam.pixels[index + 3];
fill(0,0,b);
ellipse(x ,y,10,10);
//fill(r, g + cNoise * 10, b);
//text("1", x + (10 * Math.random()), y);
}
};
filterLayer();
//viewFinder(sX, sY)
viewFinder(mouseX, mouseY);
// metadataDisplay(txX, txY)
metadataDisplay(156, 590)
}
function mousePressed() {
if (mouseX < width && mouseY < height) {
saveCanvas(canvas, 'CCLab-ExperimentalCam', 'jpg');
}
}
//filter layer
function filterLayer() {
push()
//scan pixel location in array
filter_index = filter_index + 1;
if (filter_index == filterX.length) {
filter_index = 0;
}
blendMode(OVERLAY);
let colorFromVideo = cam.get(filterX[filter_index], filterY[filter_index]);
fill(colorFromVideo);
stroke(255, 0, 0);
//rect(0, 0, 200, 200);
pop();
}
//view finder window
function viewFinder(sX, sY) {
copy(cam, sX, sY, 183, 183, 406, 406, 183, 183)
//check location of filter color from pixels
console.log("filterX:", filterX[filter_index], " filterY:", filterY[filter_index]);
}
//metadata display
function metadataDisplay(txX, txY) {
h = hour();
m = minute();
s = second();
mo = month();
d = day();
y = year();
push();
fill(255,255,0);
textSize(16);
text('Created: ' + mo + "/" + d + "/" + y + " at " + h + ":" + m + ":" + s, txX, txY);
pop();
}