import math
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), '..'))
from Program import Program
from Command import Command

from hilbertcurve.hilbertcurve import HilbertCurve
penthickness=28

def hilbert( laenge, dicke):
    tiefe=math.floor(math.log(laenge/dicke,2)+3)
    print("Tiefe",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[0])]\
    +[Command('PD',*p) for p in list[1:]]\
    +[Command('PU')])
