import processing.video.*;
Capture camera;
color[][] previousPixels;
int frames = 20;
void setup(){
size(640, 480);
camera = new Capture(this, width, height);
camera.start();
previousPixels = new color[width][height];
}
void draw(){
if(frameCount == 1){
camera.loadPixels();
loadPixels();
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
color c = camera.pixels[y * width + x];
pixels[y * width + x] = c;
previousPixels[x][y] = c;
}
}
updatePixels();
} else {
camera.loadPixels();
loadPixels();
for(int x = 0; x < width; x++){
for(int y = 0; y < height; y++){
color c = camera.pixels[y * width + x];
color currentPixel = color(
(red(previousPixels[x][y]) * ((frames - 1) / float(frames))) + (red(c) / float(frames)),
(green(previousPixels[x][y]) * ((frames - 1) / float(frames))) + (green(c) / float(frames)),
(blue(previousPixels[x][y]) * ((frames - 1) / float(frames))) + (blue(c) / float(frames)));
pixels[y * width + x] = currentPixel;
previousPixels[x][y] = currentPixel;
}
}
updatePixels();
}
}
void captureEvent(Capture camera){
camera.read();
}