2017年4月14日金曜日

マル9な円周率その2

その2。動いているのはこちら
float n=1;

void setup(){
  size(300,350);
  background(255);  
}

void draw(){
  float s=0;
  background(255);
  fill(255);
  noFill();
  stroke(255,0,0);
  ellipse(0,0,600,600);
  float x0=0;
  float y0=1.0;


  for(int m=1;m<n+1;m++){
    float x=m/n;
    float y=sqrt(1-pow((x),2.0));
    stroke(0);
    line(x*300,y*300,x0*300,y0*300);
    s=s+sqrt(pow((x-x0),2.0)+pow((y-y0),2.0));
    x0=x;
    y0=y;
}
  n+=int(n/10+1);
 if(n<300){
   delay(int(1000/sqrt(n)));
  }
  fill(0);
  textSize(15);
  text(str(int(n)),5,330);  
  text(str(s*2.0),150,330);
  if(n>10000000){
    noLoop();
  }    
}

void mousePressed(){
  n=1;
  loop();
}