Austin McCasland

21 Jan 2014

golan_good

When I was creating this piece the objective was to magnify the effects of a well-known optical illusion. Each of the horizontal lines in this gif is perfectly parallel to the others, and completely straight. The offset of the boxes gives the illusion of the horizontal lines bending. I thought that adding rotational animation to the illusion would make the lines appear to bend much more and I think in the end it worked fairly well. I created a version that rotated without changing direction and it was a much more powerful illusion, but I was unable to make it work with 10 frames of animation.

 
int     nFramesInLoop = 10; // for lenticular export, change this to 10!
int     nElapsedFrames;
boolean bRecording; 
 
 
 ////
 int boxHeight, lineWidth;
float speed, testCounter, radius, degrees, rotationSpeed;
boolean leftDirection, rightDirection, clockwise;
String  myName = "golanlevin";
 
//===================================================
void setup() {
  size (1500, 1500); 
  bRecording = false;
  nElapsedFrames = 0;
  frameRate (nFramesInLoop); 
  
  
  ///////
   boxHeight = 60;
  lineWidth =6;
  speed=.5;
  degrees=0;
  rotationSpeed = 2;
  
}
//===================================================
void keyPressed() { 
  // Press a key to export frames to the output folder
  bRecording = true;
  nElapsedFrames = 0;
}
 
//===================================================
void draw() {
 
  // Compute a percentage (0...1) representing where we are in the loop.
  float percentCompleteFraction = 0; 
  if (bRecording) {
    percentCompleteFraction = (float) nElapsedFrames / (float)nFramesInLoop;
  } 
  else {
    float modFrame = (float) (frameCount % nFramesInLoop);
    percentCompleteFraction = modFrame / (float)nFramesInLoop;
  }
 
  // Render the design, based on that percentage. 
  renderMyDesign (percentCompleteFraction);
 
  // If we're recording the output, save the frame to a file. 
  if (bRecording) {
    saveFrame("output/"+ myName + "-loop-" + nf(nElapsedFrames, 4) + ".png");
    nElapsedFrames++; 
    if (nElapsedFrames == nFramesInLoop) {
      bRecording = false;
    }
  }
}
 
//===================================================
void renderMyDesign (float percent) {
 
  
  
  background(255);
  fill(0);  
  //This for loop draws the boxes statically.   After everything is set up I would like every other layer
  //to move in an opposite direction.
  if(degrees>5) {
    clockwise = false;
  }
  if(degrees< -5) {
    clockwise = true;
  }
  if(clockwise == true) {
    degrees+=rotationSpeed;
  } else if (clockwise == false) {
    degrees-=rotationSpeed;
  }
  float angle = radians(degrees);
  translate(  (width/2)-(width/(boxHeight+lineWidth)),(width/2)-(width/(boxHeight+lineWidth)));
  rotate(angle);
  
  for(int i=0; i<=height*2+(boxHeight+lineWidth); i+=(boxHeight+lineWidth)) {
   pushStyle();
    stroke (100); 
    strokeWeight (lineWidth); 
    line(-(width), i-(width/2)-(lineWidth/2), width,i-(width/2)-(lineWidth/2));
   popStyle();
   
  }
  for(int i=-(width/2); i<=(width); i+=(boxHeight+lineWidth)) {
    if(abs(((i/(boxHeight+lineWidth))%4)) == 0) {//detects which iteration
      for(int j=-(width/4); j<=(width/2); j+=boxHeight+lineWidth) {
          rect(j*2, i, boxHeight, boxHeight);
      }
    }
    if(abs(((i/(boxHeight+lineWidth))%4)) == 1) {
      for(int j=-(width/4)+2; j<=(width/2); j+=boxHeight+lineWidth) {
        rect(j*2, i, boxHeight, boxHeight);
      }
    }
    if(abs(((i/(boxHeight+lineWidth))%4)) == 2) {
      for(int j=-(width/4); j<=(width/2); j+=boxHeight+lineWidth) {
        rect(j*2, i, boxHeight, boxHeight);
      }
    }
    if(abs(((i/(boxHeight+lineWidth))%4)) == 3) {
      for(int j=-(width/4)-2; j<=(width/2); j+=boxHeight+lineWidth) {
        rect(j*2, i, boxHeight, boxHeight);
      }
    }
  }


  
}