import codeanticode.gsvideo.*; GSCapture cam; PImage img; int[][][] queues; int[] qLengths; int pointer; float maxR; void setup() { size(640,480 ); img = new PImage(320, 240); //init cam cam = new GSCapture(this, 320, 240); frameRate(20); background(0); //for circular effect maxR = sqrt((cam.width/2)*(cam.width/2) + (cam.height/2)*(cam.height/2)); initQueues(); } void initQueues() { initQlenghts(); //showQueues(); queues = new int[cam.width][cam.height][]; for (int y = 0; y < cam.height; y++){ for (int x = 0; x < cam.width; x++){ queues[x][y] = new int[getQueueLength(x,y)]; } } } void initQlenghts() { qLengths = new int[cam.width*cam.height + cam.width]; for (int y = 0; y < cam.height; y++){ for (int x = 0; x < cam.width; x++){ qLengths[y*cam.width + x] = 1+ ySlit(x,y); } } } int bumps2(int x, int y) { int w = cam.width/3; int h = cam.height/3; int tmpx = x%w; int tmpy = y%h; float bump = sqrt((w/2-tmpx)*(w/2-tmpx) + (h/2-tmpy)*(h/2-tmpy)); float val = norm(bump, 0, sqrt((w/2)*(w/2) + (h/2)*(h/2))); return (int) (10-val*10); } int bumps(int x, int y) { float xb = 3*TWO_PI/(cam.width); float yb = 3*TWO_PI/(cam.height); float bump = 4 + (sin(x*xb))+ (cos(y*yb)); return (int) (bump); } int getQueueLength(int x, int y) { return qLengths[y*cam.width + x]; } int speed = 160; int xSlit(int x,int y) { float xnorm = norm(x,0, cam.width); return (int) (xnorm*speed); } int ySlit(int x,int y) { float ynorm = norm(y,0, cam.width); return (int) (ynorm*speed); } int circular(int x, int y) { float r = sqrt((cam.width/2-x)*(cam.width/2-x) + (cam.height/2-y)*(cam.height/2-y)); float normedR = norm(r,0,maxR); float fun = sin(normedR*PI); return (int) ((1-normedR)*50); //return (int) (fun*20); } void draw() { if (cam.available()) { cam.read(); cam.loadPixels(); pointer++; //pointer = ++pointer%cam.width; // Copy a column of pixels from the middle of the video // To a location moving slowly across the canvas. img.loadPixels(); for (int y = 0; y < cam.height; y++){ for (int x = 0; x < cam.width; x++){ int rowIdx = y*cam.width; queues[x][y][pointer%getQueueLength(x,y)] = cam.pixels[rowIdx+x]; img.pixels[rowIdx+x] = queues[x][y][(pointer+1)%getQueueLength(x,y)]; } } img.updatePixels(); image(img,0,0,640,480); } } void showQueues() { for (int y = 0; y < cam.height; y++){ for (int x = 0; x < cam.width; x++){ print(getQueueLength(x,y) + " "); } println(); } }