xxxxxxxxxx
var capture;
var picA;
var picI;
var pic;
var picBW;
var r;
var w, h;
function setup() {
createCanvas(640/2, 480/2);
background(100,0,0);
capture = createCapture(VIDEO);
capture.size(640/2, 480/2);
pic = capture.get();
w = pic.width;
h = pic.height;
picBW = createImage(w,h);
randomizeBW(0.5);
}
function draw() {
r = 1.3; // stripe width
pic = capture.get();
picA = picBW.get();
picA.filter(BLUR,r);
picI = picBW.get();
picI.filter(BLUR,2*r);
pic.loadPixels();
picA.loadPixels();
picI.loadPixels();
var valA = 0;
var valI = 0;
var valP = 0;
var index;
var valOut;
var wt;
for(var x=0; x<w; x++){
for(var y=0; y<h; y++){
index = 4*(x+y*w)
for(var cI=0; cI<3; cI++){ //loop through each color channel
valP = pic.pixels[index+cI];
valA = picA.pixels[index+cI];
valI = picI.pixels[index+cI];
valOut = max(valI,valA);
valP *= valP/255; // gamma correction
wt = (log((valP+1)/255)/-4.5)+0.83; // calibration curve
valOut = (valI*wt<valA)*255.0; // binarize the image
picBW.pixels[index+cI] = valOut;
}
picBW.pixels[index+3] = 255;
}
}
picBW.updatePixels();
image(picBW,0,0);
randomizeBW(0.1); //randomize a small portion of the image to keep it evolving
}
// flip some pixels randomly
function randomizeBW(rate){
picBW.loadPixels();
var rv;
for(var x=0; x<w; x++){
for(var y=0; y<h; y++){
index = 4*(x+y*w)
for(var cI=0; cI<3; cI++){
rv = (random(1)<rate);
if(rv){
picBW.pixels[index+cI] = 255-picBW.pixels[index+cI];
}
}
picBW.pixels[index+3] = 255;
}
}
picBW.updatePixels()
}