Skip to content

Instantly share code, notes, and snippets.

@ktnyt
Created July 7, 2014 07:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ktnyt/ec02e6e71e79294ca13d to your computer and use it in GitHub Desktop.
Save ktnyt/ec02e6e71e79294ca13d to your computer and use it in GitHub Desktop.
Press enter to take a picture
import processing.video.*;
Capture camera;
PImage picture = null;
void setup() {
size(640, 480);
camera = new Capture(this, 640, 480, 30);
camera.start();
}
void draw() {
if(camera.available() == true) {
camera.read();
}
if(picture == null) {
set(0, 0, camera);
} else {
set(0, 0, picture);
}
}
void keyPressed() {
if(key == ENTER) {
if(picture == null) {
picture = new PImage(640, 480);
for(int i = 0; i < 640; i++) {
for(int j = 0; j < 480; j++) {
picture.pixels[i + j * 640] = camera.pixels[i + j * 640];
}
}
} else {
picture = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment