import processing.video.*; Capture cam; int[] xs, ys; // x and y coordinates of rectangle sources // x[i],y[i] says which camera rectangle goes to window rectangle #1 PImage[] pieces; // the image fragmented into rectangles int nx=3, ny=3; // number of rectangles across and down int dx, dy; // rectangle sizes, computed from width,height and nx,ny int selX=-1,selY=-1; // if a piece has been selected, its x and y indices (-1 if none) boolean auto=false; // whether or not to auto swap pieces void setup() { size(640,480); noFill(); strokeWeight(3); cam = new Capture(this,640,480); cam.start(); dx = width/nx; dy = height/ny; // Initially, have our usual mapping, where piece at x+y*nx corresponds to (x,y) xs = new int[nx*ny]; ys = new int[nx*ny]; pieces = new PImage[nx*ny]; int p=0; for (int y=0; y= 0 && selY >= 0) { stroke(255,0,0); rect(dx*selX,dy*selY,dx,dy); // -1 to make sure red can be seen } } // Mix up all the pieces void shuffle() { // Swap each piece with some piece later in the array for (int i=0; i= 0 && selY >= 0) { if (selX == px && selY == py) { // same one twice -- cancel selX = -1; selY = -1; } else { // second selection -- swap swapPieces(px+py*nx, selX+selY*nx); selX = -1; selY = -1; } } else { // first selection selX = px; selY = py; } } void keyPressed() { if (key == 'a') auto = !auto; else if (key == 's') shuffle(); } // START NO NOTES // code used to capture screenshots void keyReleased() { if(key == '`' && !online) save("sketch.png"); }