Skip to content

Instantly share code, notes, and snippets.

@hrkd
Last active August 29, 2015 14:01
Show Gist options
  • Save hrkd/ff4695cc108ce29872ee to your computer and use it in GitHub Desktop.
Save hrkd/ff4695cc108ce29872ee to your computer and use it in GitHub Desktop.
import processing.video.*;
Capture capture;
int[] pastPixels;
void setup(){
size(1280, 720);
String[] cameras = Capture.list();
print(cameras[0]);
capture = new Capture(this, cameras[0]);
capture.start();
frameRate(15);
pastPixels = new int[width*height];
}
int[] getColor(int col){
int red = (col >> 16) & 0xFF;
int green = (col >> 8) & 0xFF;
int blue = col & 0xFF;
int[] colors = {red,green,blue};
return colors;
}
int checkColor(int color1,int color2){
int diff = color1 - color2;
return abs(diff);
}
boolean checkRGB(int color1,int color2){
int[] col1 = getColor(color1);
int[] col2 = getColor(color2);
int allow = 20;
int diff = 0;
for(int i=0;i<3;i++){
diff += checkColor(col1[i],col2[i]);
}
if(diff < allow){
return true;
}else{
return false;
}
}
void draw(){
background(0);
if (capture.available()){
capture.read();
capture.loadPixels();
int d = 20;
for(int y = d/2; y < height; y += d){
for(int x = d/2; x < width; x += d){
int px = y*width + x;
if(!checkRGB(pastPixels[px], capture.pixels[px])){
fill(capture.pixels[px]);
rect(x,y,d,d);
}
}
}
pastPixels = capture.pixels;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment