Daily Creative Coding

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

円の上を回転する円

/**
* cirlces on circles
*
* @author aa_debdeb
* @date 20160902
*/

int NUM = 30;
float RADIOUS = 100;

void setup(){
  size(500, 500);
  background(0);
}

void draw(){
  fill(0, 30);
  noStroke();
  rect(0, 0, width, height);
  noFill();
  stroke(255, 100, 0);
  strokeWeight(2);
  translate(width / 2, height / 2);
  float angStep = TWO_PI / NUM;
  for(int i = 0; i < NUM; i++){
    pushMatrix();
    float cx = RADIOUS * cos(angStep * i);
    float cy = RADIOUS * sin(angStep * i);
    translate(cx, cy);
    float angle = frameCount * 0.01;
    angle *= i % 2 == 0 ? -1: 1;
    rotate(angle + angStep * i + PI);
    ellipse(RADIOUS, 0, 50, 50);
    popMatrix();
  }
}
f:id:aa_debdeb:20160829224031j:plain