package sample.svg;
import static util.SVGUtil.*;

public class Gosper {
	private static int color;
	private static int dcolor = 1;

	private static void gosperLeft(int n, double x) {
	    if (n==0) {
	        forward(Math.sqrt(x));
	        stroke(color = rotateH360(color, dcolor));
	    }  else {
	        int m = n-1;
	        double y = x/7;
	        turn(-60);
	        gosperRight(m, y);
	        turn(60);
	        gosperLeft(m, y);
	        gosperLeft(m, y);
	        turn(60);
	        turn(60);
	        gosperLeft(m, y);
	        turn(60);
	        gosperRight(m, y);
	        turn(-60);
	        turn(-60);
	        gosperRight(m, y);
	        turn(-60);
	        gosperLeft(m, y);
	    }
	}

	private static void gosperRight(int n, double x) {
	    if (n==0) {
	        forward(Math.sqrt(x));
	        stroke(color = rotateH360(color, dcolor));
	    }  else {
	        int m = n-1;
	        double y = x/7;
	        gosperRight(m, y);
	        turn(60);
	        gosperLeft(m, y);
	        turn(60);
	        turn(60);
	        gosperLeft(m, y);
	        turn(-60);
	        gosperRight(m, y); 
	        turn(-60);
	        turn(-60);
	        gosperRight(m, y);
	        gosperRight(m, y);
	        turn(-60);
	        gosperLeft(m, y);
	        turn(60);
	    }
	}

	public static void main(String[] args) {
	    start();
	    rulers();
	    stroke(color = hsb360(0, 100, 100));
	    strokeWeight(0.5);
	    penUp();
	    turn(-90); forward(65); turn(90); forward(20);
	    penDown();
	    gosperRight(4, 14406);
	    finish();
	}
}
