Daily Creative Coding

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

ポップアップ円弧

f:id:aa_debdeb:20161007214336j:plain
/**
* arc 3D
*
* @author aa_debdeb
* @date 2016/10/14
*/

void setup(){
  size(640, 640, P3D);
  noStroke();
  mousePressed();
}

void mousePressed(){
  background(255);
  translate(width / 2, height / 2);
  for(int i = 0; i < 20; i++){
    int arcNum = int(random(1, 5));
    float startAng = random(TWO_PI);
    float endAng = startAng + random(PI);
    float startRadious = random(20, 200);
    float arcWidth = random(5, 40);
    float arcInterval = random(5, 30);
    fill(random(255), random(255), random(255));
    pushMatrix();
    rotateX(random(TWO_PI));
    rotateY(random(TWO_PI));
    rotateZ(random(TWO_PI));
    for(int ai = 0; ai < arcNum; ai++){
      beginShape();
      float radious1 = startRadious + ai * (arcWidth + arcInterval);
      for(float angle = startAng; angle <= endAng; angle += 0.01){
        vertex(radious1 * cos(angle), radious1 * sin(angle));
      }
      float radious2 = startRadious + arcWidth + ai * (arcWidth + arcInterval);
      for(float angle = endAng; angle >= startAng; angle -= 0.01){
        vertex(radious2 * cos(angle), radious2 * sin(angle));
      }
      endShape(CLOSE);
    }
    popMatrix();
  }
}

void draw(){

}