Daily Creative Coding

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

3Dのボックスをマウスの動きに合わせて回転させる

/**
* rotating boxes
*
* @author aa_debdeb
* @date 2016/04/10
*/

void setup(){
  size(500, 500, P3D);
}

void draw(){
  background(64);
  lights();
  for(float w = 0; w <= width; w += 50){
    for(float h = 0; h <= height; h += 50){
      pushMatrix();
      translate(w, h);
      rotateX(map(mouseY, 0, height, HALF_PI, -HALF_PI));
      rotateY(map(mouseX, 0, width, -HALF_PI, HALF_PI));
      box(25, 25, 25);
      popMatrix();
    }
  }
  
}