Daily Creative Coding

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

ローテーター

/**
* rotators
*
* @author aa_debdeb
* @date 2016/12/29
*/

int LOOP = 50;
int NUM = 12;
int BOX_SIZE = 15;
float SPHERE_SIZE = 120;

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

void draw(){
  background(#FCF1D3);
  translate(width / 2, height / 2);
  lights();
  rotateX(map(mouseY, 0, height, -HALF_PI, HALF_PI));
  rotateY(map(mouseX, 0, width, -HALF_PI, HALF_PI));
  float time = float(frameCount % LOOP) / LOOP;
  float a = map(calcQuad(time), 0, 1, 0, TWO_PI / NUM);
  fill(#8858AA);
  for(int i = 0; i < NUM; i++){
    pushMatrix();
    float angle = TWO_PI / NUM * i + a;
    translate(SPHERE_SIZE * cos(angle), 0, SPHERE_SIZE * sin(angle));
    box(BOX_SIZE);
    popMatrix();
  }
  fill(#1DAF9E);
  for(int i = 0; i < NUM; i++){
    pushMatrix();
    float angle = TWO_PI / NUM * (i + 0.5) + a ;
    translate(0, SPHERE_SIZE * cos(angle), SPHERE_SIZE * sin(angle));
    box(BOX_SIZE);
    popMatrix();
  }
}

float calcQuad(float v){
  if(v < 0.5){
    return 2.0 * v * v;
  } else {
    return -2.0 * (v - 1.0) * (v - 1.0) + 1.0;
  }
}
f:id:aa_debdeb:20161225170004j:plain