// Life Live // // by Bill Graner 1.09 // // Applies an algorithm inspired by the game of Life to a frame of video. // Click the mouse to take the picture and begin this process. Click again to reset. import processing.video.*; Capture myCapture; //application values final int APP_FPS = 120; final int WIDTH = 640; final int HEIGHT = 480; final int PIXELS = WIDTH * HEIGHT; //camera stuff final int CAMERA_FPS = 120; //sorting stuff final int ROWS_PER_FRAME = 1; //final int ROWS_PER_FRAME = 1; //final boolean HORIZONTAL_SORT = false; //final boolean VERTICAL_SORT = true; //states final int CAMERA_FEED = 0; final int TAKE_SNAPSHOT = 1; final int SORT_PIXELS = 2; final int HOLD_SNAPSHOT = 3; //FUN WITH GLOBALS ZOMG! int state = 0; //int bubbleY = HEIGHT - 1; //int bubbleX = WIDTH - 1; void captureEvent(Capture myCapture) { myCapture.read(); } void setup() { frameRate(APP_FPS); size(WIDTH, HEIGHT); myCapture = new Capture(this, width, height, CAMERA_FPS); state = CAMERA_FEED; } void mouseReleased() { //println("Mouse released."); switch (state) { case CAMERA_FEED: state = SORT_PIXELS; break; case HOLD_SNAPSHOT: state = SORT_PIXELS; break; case SORT_PIXELS: state = CAMERA_FEED; break; default: break; } //println("New state: " + state); } void draw() { switch (state) { case CAMERA_FEED: image(myCapture, 0, 0); break; case TAKE_SNAPSHOT: break; case SORT_PIXELS: for (int j=0; j0) { if (pixelTest(p1, getPixel(i, j-1))) { yesses++; } else { noes++; } } //check vs one below if (j0) { if (pixelTest(p1, getPixel(i-1, j))) { yesses++; } else { noes++; } } //check vs one on right if (i0) && (j>0)) { if (pixelTest(p1, getPixel(i-1, j-1))) { yesses++; } else { noes++; } } //check vs above right if ((i0)) { if (pixelTest(p1, getPixel(i+1, j-1))) { yesses++; } else { noes++; } } //check vs below left if ((i>0) && (j0) && (noes>0)) { setPixel(i, j, adjustForYes(p1)); } else { setPixel(i, j, adjustForNo(p1)); } } } updatePixels(); } // a testing function for our sorting rule boolean pixelTest(color c1, color c2) { return (brightness(c1) >= brightness(c2)); //return (blue(c1) > blue(c2)); } color adjustForNo(color input) { return color(red(input)+1, green(input)+1, blue(input)+1); //return color(red(input)+1, green(input), blue(input)+1); } color adjustForYes(color input) { return color(red(input)-1, green(input)-1, blue(input)-1); //return color(red(input)+1, green(input), blue(input)-1); } // an easier interface for pixels[] entries. Relies on global constants!!!! :O color getPixel(int x, int y) { return pixels[(y * WIDTH) + x]; } void setPixel(int x, int y, color input) { pixels[(y * WIDTH) + x] = input; }