import math
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from hilbertcurve.hilbertcurve import HilbertCurve
penthickness = 28
import Program
import Command


def hilbert( laenge, dicke):
    tiefe=math.floor(math.log(laenge/dicke,2)-1)
    print(tiefe)
    hilbert_curve = HilbertCurve(tiefe , 2)
    pts = [hilbert_curve.coordinates_from_distance(i) for i in range(4*(2**tiefe))]
    return pts
    
def hilbert_curve(plt):
	
	list=hilbert(min(plt.winsize[0],plt.winsize[1]),penthickness)
	return Program([Command('IN'),Command('SP1'),Command('PU',*list[-1])]\
	+[Command('PD',*p) for p in list]\
	+[Command('PU')])


