#include <math.h>
#include "svg.h"

void gosperRight(int n, double x);

int color;
int dcolor = 1;

void gosperLeft(int n, double x) {
    if (n==0) {
        forward(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);
    }
}

void gosperRight(int n, double x) {
    if (n==0) {
        forward(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);
    }
}

int main(void) {
    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();
    return 0;
}
