多角形の描き方

Processing Advent Calender 2011 に載せられなかったソース。

Processing Advent Calender 2011 に載せられなかったソース。

void setup(){
  size(300, 300);
}
 
void draw(){
  polygon(225, 75, 150,8);
}

///from http://blog.p5info.com/?p=28
void polygon(float centerX, float centerY, float size,int vertex){
  final float RADIUS = size / 2;
  beginShape();
  for(int i = 0; i < vertex; i++){
    float tx = cos(radians(360/vertex*i)) * RADIUS + centerX;
    float ty = sin(radians(360/vertex*i)) * RADIUS + centerY;
    vertex(tx, ty);
  }
  endShape(CLOSE);
}