Skip to content

Instantly share code, notes, and snippets.

@superboum
Created April 2, 2018 11:36
Show Gist options
  • Save superboum/582c694ab8c512d54a9294b2e7bd8384 to your computer and use it in GitHub Desktop.
Save superboum/582c694ab8c512d54a9294b2e7bd8384 to your computer and use it in GitHub Desktop.
Camera Delay Processing
import processing.video.*;
int delay = 3;
int square_size = 5;
Capture cam;
ArrayList<PImage> frames = new ArrayList();
void setup() {
size(640, 480);
cam = new Capture(this, width, height);
cam.start();
}
void captureEvent(Capture camera) {
camera.read();
// Copy the current video frame into an image, so it can be stored in the buffer
PImage img = createImage(width, height, RGB);
cam.loadPixels();
arrayCopy(cam.pixels, img.pixels);
frames.add(img);
// Once there are enough frames, remove the oldest one when adding a new one
if (frames.size() > delay) {
frames.remove(0);
}
}
void draw() {
if (frames.size() == 0) return;
loadPixels();
PImage imgCur = frames.get(frames.size() - 1);
PImage imgOld = frames.get(0);
imgCur.loadPixels();
imgOld.loadPixels();
for (int i = 0; i < imgCur.pixels.length; i++) {
int line = i / width;
int col = i % width;
int new_line = line / square_size;
int new_col = col / square_size;
if (new_line % 2 == new_col % 2)
pixels[i] = imgCur.pixels[i];
else
pixels[i] = imgOld.pixels[i];
}
updatePixels();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment