pcolor

//trail_150324a
boolean alternate = false;
color pColor;
int width = 540,
   height = 810,
   tx = 0,
   ty = 0,
   threshold = 135,
   lineLength = width/48;
int[] directions = {
 (width*-1)-1,
 (width*-1)+1,
 width+1,
 width-1
};

void setup(){
 background(0);
 size(width,height,OPENGL);
}

void draw(){
 fill(0,25);
 stroke(0,25);
 rect(-2,-2,width+2,height+2);
 updatePoints();
 alterPixels();
}

void updatePoints(){
 noStroke();
 int vertices = lineLength;
   for (int j=0; j<vertices; j++){
     pushMatrix();
     translate(width/2,height/2,width/3);

     float jX = cos(j)*vertices;
     float jY = sin(j)*vertices;
     float jZ = cos(j)*vertices;

       float rRate = radians(millis()*0.2);
       translate(jX,jY);
       rotateY(rRate);

       beginShape();
         for (int i=0; i<vertices; i++){
             float iX = sin(i)*vertices*i;
             float iY = cos(i)*vertices*(i+j);
             float iZ = cos(i)*vertices+abs(i*j);

             float colorR = abs(iX+jX)*2;
             float colorG = abs(iZ+jZ)*2;
             float colorB = abs(iY+jY)*2;
             float colorA = 100;
             fill(colorR,colorG,colorB,colorA);

             vertex(iX,iY,iZ);
         }
       endShape();
     popMatrix();
   }
}

void alterPixels(){
 loadPixels();
   for (int k=width+1; k<pixels.length-width-1; k++) {
     int pModifier = selectRandom(directions);
     if (brightness(pixels[k]) == threshold) {
       pixels[k] = pixels[k] « 24;
       pixels[k] = pixels[k] » 1;
     } else if (brightness(pixels[k]) > threshold) {
       pixels[k] = pixels[k+pModifier];
     } else {
       //
     }
   }
 updatePixels();
 threshold = setThreshold(threshold,50,254);
}

int setThreshold(int threshold, int minThreshold, int maxThreshold) {
 if (threshold <= maxThreshold && threshold >= minThreshold && alternate) {
   threshold++;
 } else if (threshold <= maxThreshold && threshold >= minThreshold) {
   threshold—;
 } else if (alternate) {
   threshold = maxThreshold;
   alternate = !alternate;
 } else {
   threshold = minThreshold;
   alternate = !alternate;
 }
 return threshold;
}

int selectRandom(int[] cases){
 int selected = int(random(cases.length));
 int output = cases[selected];
 return output;
}