Daily Creative Coding

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

四角形のシーケンス

/**
* sequence of rects
*
* @author aa_debdeb
* @date 2017/01/23
*/

color[] colors = {
  color(216, 36, 72),
  color(221, 163, 0),
  color(0),
  color(44, 182, 170),
  color(221, 163, 0),
  color(255)
};

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

void draw(){
  background(221, 163, 0);
  for(int i = 0; i < colors.length; i++){
    int colorIndex = (colors.length + frameCount - i) % colors.length;
    if(i == colors.length - 1 && (colorIndex == 1 || colorIndex == 4)){
      continue;
    }
    fill(colors[colorIndex]);
    float x = map(i, 0, colors.length - 1, width / 2 + 100, width / 2 - 100);
    float y = map(i, 0, colors.length - 1, height/ 2 - 100, height / 2 + 100);
    rect(x, y, 200, 200);
  }
}
f:id:aa_debdeb:20170119090246j:plain