xxxxxxxxxx
206
let cam;
let threshold;
let scene = 0;
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);
button1 = createButton('hello');
button1.position(270,330);
button1.mousePressed(changeScene);
button2 = createButton('I know');
button2.position(270,330);
button2.mousePressed(changeScene);
button3 = createButton('Stop');
button3.position(300,10);
button3.mousePressed(changeScene);
//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);
switch(scene){
case 0 :
background(0);
textFont('Helvetica');
textAlign(CENTER);
textSize(20);
fill(255);
text("This is a camera filter made by zhehui ", width / 2, height / 2);
break;
case 1 :
background(0);
textFont('Helvetica');
textAlign(CENTER);
textSize(20);
fill(255);
text("It totally free to use and there and no backdoor device to collect your photo ", width / 2, height / 2);
break;
case 2 :
Scene2();
}
if (scene == 0) {
button1.show();
button1.mousePressed(changeScene);
} else {
button1.hide();
}
if (scene == 1) {
button2.show();
button2.mousePressed(changeScene);
} else {
button2.hide();
}
if (scene == 2) {
button3.show();
button3.mousePressed(backScene);
} else {
button3.hide();
}
}
function changeScene(){
scene+=1;
}
function backScene(){
scene-=2;
}
function Scene2(){
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();
}