Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

ortho() vs perspective()

/**
* perspective vs orthographic
*
* @author aa_debdeb
* @date 2016/05/09
*/

boolean isPerspective;

void setup(){
  size(500, 500, P3D);
  isPerspective = true;
  fill(0, 255, 157);
  stroke(128);
}

void draw(){
  lights();
  background(255, 228, 225);
  if(isPerspective){
    perspective();
  } else {
//    ortho(); // java mode
    ortho(-width / 2, width / 2, -height / 2, height / 2, 0, 1000); // processing mode
  }
  for(int x = 0; x <= 10; x++){
    for(int y = 0; y <= 10; y++){
      for(int z = 0; z < 3; z++){
        pushMatrix();
        translate(width / 2 + (x - 5) * 40, height / 2 + (y - 5) * 40, -z * 200);
        rotateX(-PI / 6);
        rotateY(PI / 3);
        box(20);
        popMatrix();
      }
    }
  } 
}

void mousePressed(){
  isPerspective = !isPerspective; 
}