#include <iostream>
#include <cstdlib>
#include <cmath>
#include "PostScript.hpp"

using namespace std;

void Sierp(PostScript& p, int n, double x0, double y0, 
				double x1, double y1, double x2, double y2)
{
	if (n==0) {
		p.MoveTo(x0,y0);
		p.LineTo(x1,y1);
		p.LineTo(x2,y2);
		p.LineTo(x0,y0);
	}	
	else {
		double x01 = (x0+x1) / 2.0;
		double y01 = (y0+y1) / 2.0;
		double x12 = (x1+x2) / 2.0;
		double y12 = (y1+y2) / 2.0;
		double x20 = (x2+x0) / 2.0;
		double y20 = (y2+y0) / 2.0;
		Sierp(p, n-1, x0, y0, x01, y01, x20, y20);
		Sierp(p, n-1, x01, y01, x1, y1, x12, y12);
		Sierp(p, n-1, x20, y20, x12, y12, x2, y2);
	}
}

int main(int argc, char* argv[])
{
	double r3= sqrt(3.0);
	PostScript p("sierp.ps");
	Sierp(p, 4, -10, -10/r3, 10, -10/r3, 0, 20/r3);	
	return EXIT_SUCCESS;
}

