Daily Creative Coding

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

伸び縮みする腕

/**
* expanding and contracting arms
*
* @author aa_debdeb
* @date 2016/09/25
*/

ArrayList<Float> radiouses;
ArrayList<Float> angles;

void setup(){
  size(640, 640);  
  stroke(230);
  strokeWeight(2);
  setCircles();
}

void setCircles(){
  radiouses = new ArrayList<Float>();
  angles = new ArrayList<Float>();
  for(int i = 0; i < 10; i++){
    float angle = random(TWO_PI);
    for(int j = 0; j < 15; j++){
      float radious = map(sqrt(j / 15.0), 0, 1, 0, 350);
      radiouses.add(radious);
      angles.add(angle);
      angle += random(-PI / 16, PI / 16);
      angles.add(angle);
    }
  }
}

void draw(){
  background(230);
  translate(width / 2, height / 2);
  float time = PI * (frameCount % 100) / 100.0 + HALF_PI;
  for(int i = 0; i < radiouses.size(); i++){
    switch(i % 4){
      case 0:
        fill(40);
        break;
      case 1:
        fill(0, 206, 209);
        break;
      case 2:
        fill(230);
        break;
      case 3:
        fill(209, 0, 101);
        break;
    }
    float radious = radiouses.get(i) * (1.0 - abs(sin(time)));
    float angle = angles.get(i);
    float diameter = map(radious , 0, 350, 130, 5);
    ellipse(radious * cos(angle), radious * sin(angle), diameter, diameter);
  }
  if(frameCount % 100 == 0){
    setCircles();
  }
  
}
f:id:aa_debdeb:20160920174011j:plain