package sample.svg;


import static util.SVGUtil.*;

public class RecursivePolygon {
	private static int n = 6;
	public static void generate(int d, double r) {
		if (d<=0) return;
		polygon(r);
		for(int i=0; i<n; i++) {
			double x = r*4/3*Math.cos(2*i*PI/n);
			double y = r*4/3*Math.sin(2*i*PI/n);
			pushMatrix();
			translate(x, y);
			rotate(PI);
			generate(d-1, r/3);
			popMatrix();
		}
	}
	
	public static void polygon(double r) {
		beginShape();
		for(int i=0; i<n; i++) {
			double x0 = r*Math.cos(2*i*PI/n);
			double y0 = r*Math.sin(2*i*PI/n);
			vertex(x0, y0);
		}
		endShape(true);
	}
	
	public static void main(String[] args) {
		int r=50;
		start();
		stroke(0x3f3f3f);
		beginShape();
		vertex(0, 0);
		vertex(pageWidth(), 0);
		vertex(pageWidth(), pageHeight());
		vertex(0, pageHeight());
		endShape(true);
		stroke(0x0000ff);
		noFill();
		translate(centerX(), centerY());
		rotate(-PI/2);
		generate(5, r);
		finish();
	}
}
