import codeanticode.gsvideo.*; GSCapture cam; PImage img; int[][][] cube; int DEPTH = 24; int WIDTH = 320; int HEIGHT = 240; int enlarge = 4; int pointer; int recordIDX = 0; void setup() { size(WIDTH*enlarge,HEIGHT*enlarge ); img = new PImage(WIDTH, HEIGHT); //init cam cam = new GSCapture(this, WIDTH, HEIGHT); frameRate(20); background(0); cube = new int[WIDTH][HEIGHT][DEPTH]; } void draw() { if (cam.available()) { if(recordIDX%2==0) { pointer = (++pointer)%DEPTH; insertFrame(); } getMouse(); selectSlice(); image(img,0,0,WIDTH*enlarge,HEIGHT*enlarge); println(frameCount + " and pointer = " + pointer); // String f = createFileName(); // saveFrame(f); recordIDX++; } } void selectSlice() { img.loadPixels(); float phase = (float)recordIDX/TWO_PI; int idx = 0; for (int y = 0; y < HEIGHT; y++){ for (int x = 0; x < WIDTH; x++){ //img.pixels[idx] = cube[x][y][clampPointer(pointer)]; img.pixels[idx] = getPixel(x,y,movingBubble(x,y)); idx++; } } img.updatePixels(); } int diameterSQ = 150*150; float movingBubble(int x, int y) { float dx = cx-x; float dy = cy-y; float dist = dx*dx+dy*dy; if (dist>diameterSQ) return 0.0; float z = 15*sin(HALF_PI * norm(dist,0,diameterSQ)); return z; } float cx, cy; void mouseClicked() { getMouse(); println("center = (" + cx + ", " + cy + ")"); } void getMouse() { cx = map(mouseX, 0, WIDTH*enlarge, 0, WIDTH); cy = map(mouseY, 0, HEIGHT*enlarge, 0, HEIGHT); } /** * interpolates between frames */ int getPixel(int x, int y, float p) { int cur = pointer - ceil(p); int prev = cur-1; float percent = ceil(p) - p; int curval = cube[x][y][clampPointer(cur)]; // if (percent<.05) // return curval; int preval = cube[x][y][clampPointer(prev)]; // do it for each color ... float r = (preval >> 16 & 0xFF)*(1-percent) + percent * (curval >> 16 & 0xFF); float g = (preval >> 8 & 0xFF)*(1-percent) + percent * (curval >> 8 & 0xFF); float b = (preval & 0xFF)*(1-percent) + percent * (curval & 0xFF); return color(r,g,b); } void insertFrame() { cam.read(); cam.loadPixels(); int idx = 0; for (int y = 0; y < HEIGHT; y++){ for (int x = 0; x < WIDTH; x++){ cube[x][y][pointer%DEPTH] = cam.pixels[idx]; idx++; } } } /** * create a zeropadded * sequential filename */ String createFileName() { String tmp = "" + recordIDX; while(tmp.length()<5) tmp = "0" + tmp; return tmp + ".png"; } int clampPointer(int p) { if (p<0) return p+DEPTH; else return p%DEPTH; }