Daily Creative Coding

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

ひし形を連ねる

/**
* chain of diamonds
*
* @author aa_debdeb
* @date 2016/08/25
*/

float rectSize = 20;

void setup(){
  size(500, 500, P3D);
  rectMode(CENTER);
  noFill();
  stroke(255);
}

void draw(){
  background(0);
  for(int x = 0; x * rectSize + rectSize / 2 < width; x++){
    for(int y = 0; y * rectSize + rectSize / 2 < height; y++){
      pushMatrix();
      translate(x * rectSize + rectSize / 2, y * rectSize + rectSize / 2, 0);
      rotateZ(HALF_PI / 2);
      if(x % 2 == 0){
        rotateY(frameCount * 0.02);
      } else {
        rotateY(-frameCount * 0.02);
      }
      if(x % 5 == 0 || x % 5 == 4){
        stroke(255, 0, 255);
      } else if(x % 5 == 1 || x % 5 == 3){
        stroke(255, 0, 196);
      } else {
        stroke(255, 0, 128);
      }
      for(float v = 0.25; v <= 1.0; v += 0.25){
        rect(0, 0, v * rectSize / sqrt(2), v * rectSize / sqrt(2));
      }
      popMatrix();
    }
  }
}
f:id:aa_debdeb:20160821161003j:plain