Daily Creative Coding

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

重なって回転するボックス

/**
* overlapping boxes
*
* @author aa_debdeb
* @date 2016/04/11
*/

ArrayList<PVector> speeds;

void setup(){
  size(500, 500, P3D);
  noStroke();
  
  speeds = new ArrayList<PVector>();
  for(int i = 0; i < 10; i++){
    PVector speed = new PVector(random(-1, 1), random(-1, 1), random(-1, 1));
    speed.normalize();
    speed.mult(0.04);
    speeds.add(speed);
  }
}

void draw(){
  background(64);
  lights();
  pushMatrix();
  translate(width / 2, height / 2);
  for(PVector speed: speeds){
    pushMatrix();
    rotateX(speed.x * frameCount);
    rotateY(speed.y * frameCount);
    rotateZ(speed.z * frameCount);
    box(200, 200, 200);
    popMatrix();
  }
  popMatrix();
}