Daily Creative Coding

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

Approximate Circle

/**
*
* Approximate Circle
*
* @author aa_debdeb
* @date 2015/08/25
*/

void setup(){
  size(500, 500);
  smooth();
  noFill();
  background(255);
  
  float centerX = width / 2.0;
  float centerY = height / 2.0;
  float diameter = 400;
  float radious = diameter / 2.0;
 
  stroke(192);
  strokeWeight(7);
  arc(centerX, centerY, diameter, diameter, 0, 2.0*PI);
  
  stroke(0);
  strokeWeight(1);
  int numSteps = 100;
  float angleStepSize = 2.0 * PI / numSteps;
  for(int i = 0; i < numSteps; i++){
    float x = radious * cos(angleStepSize * i) + centerX;
    float y = radious * sin(angleStepSize * i) + centerX;
    float nextX = radious * cos(angleStepSize * (i + 1)) + centerX;
    float nextY = radious * sin(angleStepSize * (i + 1)) + centerX;
    line(x, y, nextX, nextY);
  }
}