読者です 読者をやめる 読者になる 読者になる

Daily Creative Coding

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

手書きのドット

静画
f:id:aa_debdeb:20161012201758j:plain

hand-written dots - OpenProcessing

/**
* hand-written dots
*
* @author aa_debdeb
* @date 2016/10/18
*/

ArrayList<Circle> circles; 

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

void mousePressed(){
  background(random(255), random(255), random(255));
  noStroke();
  fill(0);
  circles = new ArrayList<Circle>();
  for(int i = 0; i < 50000; i++){
    Circle circle = new Circle();
    boolean overlapped = false;
    for(Circle another: circles){
      if(PVector.dist(circle.loc, another.loc) < circle.radious + another.radious){
        overlapped = true;
        break;
      }
    } 
    if(!overlapped){
      circle.display();
      circles.add(circle);
    }
  }
}

void draw(){

}

class Circle{

  PVector loc;
  float radious;
  
  Circle(){
    loc = new PVector(random(width), random(height));
    radious = random(5, 50);
  }
  
  void display(){
    pushMatrix();
    translate(loc.x, loc.y);
    float angStep = 1;
    beginShape();
    PVector nOffset = new PVector(random(1000), random(1000));
    for(float angle = 0; angle < 360; angle += angStep){
      float radian = radians(angle);
      float ex = radious * cos(radian);
      float ey = radious * sin(radian);
      float nr = radious - map(noise(ex * 0.01 + nOffset.x, ey * 0.01 + nOffset.y), 0, 1, 0, radious / 2);
      float nx = nr * cos(radian);
      float ny = nr * sin(radian);
      vertex(nx, ny);
    }
    endShape(CLOSE);
    popMatrix();
  }
  
}