clumpswap - edit online

some explanation...

For old time's sake here is the Processing/Java version, I coded up to see if it was much faster:

int GRIDSIZE = 25;
int CANVASSIZE = 600;
float sz;
color[] grid;
color green;
color red;

int offset(int x,int y){
   return x * GRIDSIZE + y; 
}

void setup() {
  size(600, 600);
  frameRate(1000);
  noFill();
  noStroke();
  grid = new int[GRIDSIZE*GRIDSIZE];
  sz = CANVASSIZE / GRIDSIZE;
  
  red = color(200,100,100);
 green = color(100,200,100);

  
  for(int x = 0; x < GRIDSIZE; x++){
    for(int y = 0; y < GRIDSIZE; y++){
      grid[offset(x,y)] = 
        x < GRIDSIZE/2 ? red : green;
      fill(grid[offset(x,y)]);
      rect(x * sz, y * sz, sz, sz);
    }
    
  }
}

void swapEm(int x1,int y1,int x2,int y2){
   color a = grid[offset(x1,y1)];
   color b = grid[offset(x2,y2)];
  
    //fill(255);
  
   grid[offset(x1,y1)] = b;
   fill(b);
   rect(x1 * sz, y1 * sz, sz, sz);

   grid[offset(x2,y2)] = a;
   fill(a);
   rect(x2 * sz, y2 * sz, sz, sz);
  
   
   
}

void swapVert(int x,int y) {
  int y1 = y;
  int y2 = y >= GRIDSIZE-1 ? 0 : y + 1;
  swapEm(x,y1,x,y2);  
}
void swapHoriz(int x,int y) {
  int x1 = x;
  int x2 = x >= GRIDSIZE-1 ? 0 : x + 1;
  swapEm(x1,y,x2,y);
}


void draw() {
    int x = int(random(0,GRIDSIZE));
    int y = int(random(0,GRIDSIZE));

    if(random(1) <= .5) {
      swapVert(x,y);
    } else {
       swapHoriz(x,y);
    }

}