Daily Creative Coding

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

画面の分割

/**
* screen breakup
*
* @author aa_debdeb
* @date 2016/12/09
*/

int LOOP = 60;
int rectNum = 0;
boolean state = true;

void setup(){
  size(500, 500);
  rectMode(CENTER);
  noStroke();
}

void draw(){
  int step = frameCount % LOOP;
  if(step == 0){
    state = !state;
    rectNum++;
    if(rectNum > 7){
      rectNum = 0;
    }
  }
  color c1, c2;
  if(state){
    c1 = color(0);
    c2 = color(255);
  } else {
    c1 = color(255);
    c2 = color(0);
  }
  background(c1);
  fill(c2);
  float maxRectSize = float(width) / pow(2, rectNum);
  float rectSize = map(sqrt(float(step) / LOOP), 0, 1, maxRectSize, 0);
  for(int x = 0; x < pow(2, rectNum); x++){
    for(int  y = 0; y < pow(2, rectNum); y++){
      pushMatrix();
      translate(maxRectSize * x +  maxRectSize / 2, maxRectSize * y + maxRectSize / 2);
      if((x + y) % 2 == 0){
        rotate(PI * 1 / LOOP * step);
      } else {
        rotate(-PI * 1 / LOOP * step);
      }
      rect(0, 0, rectSize, rectSize);    
      popMatrix();
    }
  }  

}
f:id:aa_debdeb:20161205072826j:plain