Daily Creative Coding

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

カテナリー曲線

/**
* catenaries
* 
* @author aa_debdeb
* @date 2016/08/11
*/

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

void draw(){}

void mousePressed(){
  background(248, 248, 255);
  noFill();
  for(int i = 0; i < 150; i++){
    float a = random(1, 2);
    PVector middle = new PVector(random(width), random(height));
    stroke(0, random(100, 255));
    strokeWeight(1);
    beginShape();
    for(float x = 0; x <= width; x += 1){
      float c = getCatenary(a, (x - middle.x) * 0.02);
      vertex(x, middle.y - c);
    }
    endShape();
  }
}

float getCatenary(float a, float x){
  return a * ((exp(x / a) + exp(-x / a)) / 2.0);
}
f:id:aa_debdeb:20160805130311j:plain