xxxxxxxxxx
159
let capture;
let cap = 4;
let call;
let sceneNum = 0;
let leave;
let preCall;
let preLeave;
//face object
function setup() {
// load p5 functions:
createCanvas(720, 540);
capture = createCapture(VIDEO);
capture.size(width/cap, height/cap);
//capture.hide();
call = createButton("Call Yourself");
call.style('background', '#c299ff');
//call.style('border', 'transparent');
call.style('color', 'white');
call.style('padding', '5px');
call.position(width/2, height-530);
//call.mousePressed(Together);
leave = createButton("Leave Me Alone");
leave.style('background', '#c299ff');
//leave.style('border', 'transparent');
leave.style('color', 'white');
leave.style('padding', '5px');
leave.position(width/3, height-530);
preCall = false;
preLeave = false;
//leave.mousePressed(LeaveMeAlone);
//pixelDensity(1);
}
function draw() {
background(0);
fill(0,255,255);
textSize(40);
textAlign(CENTER);
text("No data will be recorded \n No extension will be installed",width/2,height/2);
call.mousePressed(on);
leave.mousePressed(on2);
if(preCall==true){
together();
call.mousePressed(off);}
else if(preLeave==true){
LeaveMeAlone();
leave.mousePressed(off2);
}
}
function on(){
preCall = true;
preLeave = false;
}
function off(){
preCall = false;
background(0);
fill(0,255,255);
textSize(40);
textAlign(CENTER);
text("No data will be recorded \n No extension will be installed",width/2,height/2);
}
function on2(){
preLeave = true;
preCall = false;
}
function off2(){
preLeave = false;
background(0);
fill(0,255,255);
textSize(40);
textAlign(CENTER);
text("No data will be recorded \n No extension will be installed",width/2,height/2);
}
function together(){
push();
translate(width,0)
scale(-1,1);
capture.loadPixels();
for (x=0;x<capture.width; x++){
for (y=0;y<capture.height;y++){
let pNum = (x+y*(capture.width))*4 ;
let r = capture.pixels[pNum];
let g = capture.pixels[pNum+1];
let b = capture.pixels[pNum+2];
let a = capture.pixels[pNum+3];
let clr = map(r,0,255,0,230);
let clg = map(g,0,255,0,230);
let clb = map(g,0,255,51,255);
let alp = 400;
fill(clr,clg,clb,alp);
//stroke(0,0,255);
noStroke();
rectMode(CENTER);
rect(x*cap,y*cap,5,5);
//capture.updatePixels();
}
}
//tint(random(0,230),random(137,249),255);
//imageMode(CENTER);
//image(capture,width/2,height/2,capture.width*cap,capture.height*cap);
pop();
push();
capture.loadPixels();
for (x=0;x<capture.width; x++){
for (y=0;y<capture.height;y++){
let pNum = (x+y*(capture.width))*4 ;
let r = capture.pixels[pNum];
let g = capture.pixels[pNum+1];
let b = capture.pixels[pNum+2];
let a = capture.pixels[pNum+3];
let clr = map(r,0,255,0,230);
let clg = map(g,0,255,0,230);
let clb = map(g,0,255,51,255);
let alp = 100;
fill(r,g,clb,alp);
//stroke(0,0,255);
noStroke();
rectMode(CENTER);
rect(x*cap,y*cap,5,5);
//capture.updatePixels();
}
}
pop();
}
function LeaveMeAlone(){
push();
translate(width,0)
scale(-1,1);
capture.loadPixels();
for (x=0;x<capture.width; x++){
for (y=0;y<capture.height;y++){
let pNum = (x+y*(capture.width))*4 ;
let r = capture.pixels[pNum];
let g = capture.pixels[pNum+1];
let b = capture.pixels[pNum+2];
let a = capture.pixels[pNum+3];
let clr = map(r,0,255,0,230);
let clg = map(g,0,255,0,230);
let clb = map(g,0,255,51,255);
let alp = 400;
fill(clr,clg,clb,alp);
//stroke(0,0,255);
noStroke();
rectMode(CENTER);
rect(x*cap,y*cap,5,5);
//capture.updatePixels();
}
}
//tint(random(0,230),random(137,249),255);
//imageMode(CENTER);
//image(capture,width/2,height/2,capture.width*cap,capture.height*cap);
pop();
}