Daily Creative Coding

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

4つの正方形上を動く円

/**
* four moving circles
*
* @author aa_debdeb
* @date 2016/08/31
*/

PVector[] vertices;
float pos = 75;

void setup(){
  size(500, 500);
  fill(0, 75, 77);
  stroke(0, 206, 209);
  strokeWeight(30);
  vertices = new PVector[4];
  vertices[0] = new PVector(pos, pos);
  vertices[1] = new PVector(pos, -pos);
  vertices[2] = new PVector(-pos, -pos);
  vertices[3] = new PVector(-pos, pos);
  
}

void draw(){
  background(255);
  translate(width / 2, height / 2);
  float amt = sin(HALF_PI * (frameCount % 100 / 100.0));
  for(int i = 0; i < vertices.length; i++){
    int j = i != vertices.length - 1 ? i + 1: 0;
    PVector v = PVector.lerp(vertices[i], vertices[j], amt);
    ellipse(v.x, v.y, 75, 75);
  }
}
f:id:aa_debdeb:20160827194424j:plain