xxxxxxxxxx
114
let video;
//this would theoretically be the amount of rgb every pixel would need to change to register as dropping alpha
let threshold = 30;
//this will hold every pixel in state
let pixelValues = [];
let currentr = 0;
let currentg = 0;
let currentb = 0;
let priorr = 0;
let priorg = 0;
let priorb = 0;
let currenta = 0;
let priora = 0;
//in setup initialize all alpha values to 255, as i am collecting data from pixel array don't touch alpha values, when i detect a change put down the alpha values
//let acounter = 255;
function setup() {
createCanvas(640, 480);
pixelDensity(1);
video = createCapture(VIDEO);
video.size(width,height);
video.hide();
frameRate(60);
}
function draw() {
image(video,0,0,width,height);
video.loadPixels();
loadPixels();
for (let y=0; y<height; y++){
for (let x=0; x<width; x++){
/* so far:
put the video up there
load up the pixels
for every pixel store in state the current rgb value
if it's different from the previous rgb value
turn alpha all the way down
*/
let i = (x + y * width) * 4;
currentr = video.pixels[i];
currentg = video.pixels[i+1];
currentb = video.pixels[i+2];
currenta = video.pixels[i+3];
//entire thing one interdependent using boolean logic
/*
if ((currentr != priorr && ((currentr >= (priorr + threshold)) ||
(currentr <= (priorr - threshold)))) ||
(currentg != priorg && ((currentg >= (priorg + threshold)) ||
(currentg <= (priorg - threshold)))) ||
(currentb != priorb && ((currentb >= (priorb + threshold)) ||
(currentb <= (priorb - threshold)))))
{
video.pixels[i+3] -= 255;
}
*/
/*
//each one an individual check with threshold
if (currentr != priorr && ((currentr >= (priorr + threshold)) ||
(currentr <= (priorr - threshold)))) {
video.pixels[i+3] -= 200;
} else if (currentg != priorg && ((currentg >= (priorg + threshold)) || (currentg <= (priorg - threshold)))) {
video.pixels[i+3] -= 200;
} else if (currentb != priorb && ((currentb >= (priorb + threshold)) || (currentb <= (priorb - threshold))))
{
video.pixels[i+3] -= 200;
}
*/
//just checking if they're at all different
if (video.pixels[i] != pixelValues[i]) {
video.pixels[i+3] -= 255;
}
if (video.pixels[i+1] != pixelValues[i+1]) {
video.pixels[i+3] -= 255;
}
if (video.pixels[i+2] != pixelValues[i+2]) {
video.pixels[i+3] -= 255;
}
pixelValues[i] = currentr;
pixelValues[i+1] = currentg;
pixelValues[i+2] = currentb;
pixelValues[i+3] = currenta;
}
}
updatePixels();
video.updatePixels();
//console.log(pixels[4246]);
}
/*
what do i want to do
i want the video to be slowly erased based on the person's movements
so if they hold very still maybe they dont fade
but if they move they fade (the alpha goes down)
so in pseudocode... if the pixel's rgb values change significantly every time
the loop runs, the alpha goes down maybe ten or 20
what's my threshold? let's say 30?
*/