# 五角形の再帰分割

```/**
* pentagon division
*
* @author aa_debdeb
* @date 2016/10/01
*/

float phi = (1.0 + sqrt(5.0)) / 2.0;

void setup(){
size(640, 640);
translate(width / 2, height / 2);
ArrayList<Pentagon> pentagons = new ArrayList<Pentagon>();
for(int i = 0; i < 4; i++){
ArrayList<Pentagon> nextPentagons = new ArrayList<Pentagon>();
for(Pentagon p: pentagons){
}
pentagons = nextPentagons;
}
background(230);
stroke(180);
fill(60);
for(Pentagon p: pentagons){
p.display();
}
}

void draw(){

}

class Pentagon{

PVector center;
float startAngle;

Pentagon(){
center = new PVector(0, 0);
startAngle = -HALF_PI;
}

Pentagon(PVector _center, float _radious, float _startAngle){
center = _center;
startAngle = _startAngle;
}

void display(){
pushMatrix();
translate(center.x, center.y);
beginShape();
for(int i = 0; i < 5; i++){
float angle = startAngle + i * TWO_PI / 5;
}
endShape(CLOSE);
popMatrix();
}

ArrayList<Pentagon> divide(){
ArrayList<Pentagon> children = new ArrayList<Pentagon>();
float r = radious / sq(phi);
children.add(new Pentagon(new PVector(center.x, center.y), r, startAngle + PI));
for(int i = 0; i < 5; i++){
float angle = startAngle + i * TWO_PI / 5;
float x = center.x + (radious - r) * cos(angle);
float y = center.y + (radious - r) * sin(angle);
children.add(new Pentagon(new PVector(x, y), r, angle));
}
return children;
}
}
```