import rhinoscriptsyntax as rs
import random as rand
import sys                                  # load System Library



# Get all the system paths
print(sys.path)

# sys.path.append( "lib/" )                ## set relative path,
# sys.path.append( "P:/dm2/lib/")            ## set absolute path to our P:// Drive

# reload the library in case wie change something in the meantime (uncomment to use it only while changing code)
# reload(dm2lib)

#delet everything and start from scratch
# allobjs = rs.AllObjects()
# rs.DeleteObjects (allobjs)

# https://www.w3schools.com/python/gloss_python_function_recursion.asp

def tri_recursion(k):
    if(k>0):
        result = k+tri_recursion(k-1)
        print(result)
    else:
        result = 0
    return result

print("\n\nRecursion Example Results")
tri_recursion(6)




# Fibonacci Rekursion

def fib(n,st,en):
    if n-1==0:
        return en
    if n>0:
        print(en)
        temp_st=en

        en=st+en
        print(en)
        return fib(n-1,temp_st,en)


print(fib(9,0,1))




def Hex(c,r):
    cc = rs.AddPoint(c)
    first = rs.MoveObject(cc, [r,0,0])
    VList = []
    VList.append(first)

    for i in range (1,6):
        P = rs.RotateObject(first, c, i*60, None, True)
        VList.append(P)
    # L1 = rs.AddCurve([VList[0], VList[-1]],1)
    L1 = rs.AddLine(VList[0], VList[-1])
    # L2 = rs.AddCurve(VList, 1)
    L2 = rs.AddPolyline(VList)
    L = rs.JoinCurves([L1, L2], True, None)
    domain = rs.CurveDomain(L)
    # LC = rs.RebuildCurve(L[0],1)
    # print(domain)
    rad_list = [3,8]
    param_list = [0,120]
    # print(type(rad_list))
    # print(rs.AddPipe(L, [0.0, 10.0], [3,8])) # ,1,1)
    rs.AddPipe(L,0,2)

    return VList



def HexRecursion(c,r,v):
    if v <= 1:
        Hex(c,r)
    else:
        ratio = 1.5
        theList = Hex(c,r)
        all3Center = []

        for i in range(0,3):
            line = rs.AddLine(c, theList[i*2])
            cNew = rs.CurveMidPoint(line, 2)
            all3Center.append(cNew)
            Hex(cNew, r/ratio)
        return HexRecursion(all3Center[0], r/ratio, v-1),HexRecursion(all3Center[1], r/ratio, v-1),HexRecursion(all3Center[2], r/ratio, v-1)

level = 3
center = [0,0,0]
radius = 200
HexRecursion(center,radius,level)
