Daily Creative Coding

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

順に反転する円

/**
* reverse
*
* @author aa_debdeb
* @date 2016/12/04
*/

float ELLIPSE_SIZE = 10;
float edge = 0;
float edgeSpeed = 4;
color c1, c2;

void setup(){
  size(500, 500);
  mousePressed();
}

void mousePressed(){
  c1 = color(random(255), random(255), random(255));
  c2 = color(random(255), random(255), random(255));
}

void draw(){
  background(c1);
  noStroke();
  fill(c2);
  triangle(0, 0, 0, edge, edge, 0);
  for(float w = ELLIPSE_SIZE / 2; w < width; w += ELLIPSE_SIZE){
    for(float h = ELLIPSE_SIZE / 2; h < height; h += ELLIPSE_SIZE){
      if(w + h <= edge - ELLIPSE_SIZE / 2){
        fill(c1);
      } else if(w + h >= edge + ELLIPSE_SIZE / 2) {
        fill(c2);
      } else {
        fill(lerpColor(c2, c1, (edge + (ELLIPSE_SIZE / 2) - (w + h)) / ELLIPSE_SIZE));
      }
      ellipse(w, h, ELLIPSE_SIZE, ELLIPSE_SIZE);
    }
  }
  
  edge += edgeSpeed;
  if(edge <= 0 || edge >= width * 2){
    edgeSpeed *= -1;
  }
}
f:id:aa_debdeb:20161127201531j:plain