import rhinoscriptsyntax as rs
import sys, random  ###                                              
#sys.path.append("C:/Hue03/")     ### add path where "DM_lib.py" can be found !!!                                              
sys.path.append("P:/DM2/")     ### add path where "DM_lib.py" can be found !!!                                              
#sys.path.append("P:/dm2/")     ### add path where "DM_lib.py" can be found !!!                                              
import DM_lib as dm        ### reload(dm)    
############################## 


rs.UnitSystem(3)
dm.PointRadius(displayModeX=1, rad=2, styl=3, verbose=1)

if 1:
    rs.EnableRedraw(0)
    #delete absolutely all
    dm.eA()
    #print "pntRandVec",dm.pntRandVec(-1,1)
    
    anz = 5500
    deltaAngle = 360/anz
    rad = random.uniform(5.0, 10)
    vec = [rad, 0,0]
    #rs.AddPoint(vec)
    #vecX = rs.VectorRotate(vec,29.0,[0,1,1])
    #rs.AddPoint(vecX)
    
    coords = []
    for i in range(anz):
        vecX = rs.VectorRotate(vec, random.uniform(0,270), [0,0,1])
        vecX = rs.VectorRotate(vecX, random.uniform(0,180), [0,1,0])
        coords.append( vecX )
newPoints = rs.AddPoints(coords)

for pnt in newPoints :
    colo = [random.randint(200,255), random.randint(0,160), random.randint(0,10) ]
    rs.ObjectColor( pnt, colo )

pln0 =rs.PlaneFromNormal([0,0,0], [0,1,1], xaxis=[0,1,0])
pln1 =rs.PlaneFromNormal([0,0,0], [-1,-1,0], xaxis=[0,1,0])

# Add Arc0
#circ0 = rs.AddCircle( pln0, rad)
circ0 = rs.AddArc(pln0, rad, 180)
rs.RotateObject(circ0, [0,0,0], 90,[0,0,1])
rs.ObjectPrintColor(circ0, [0,200,0])
rs.ObjectPrintWidth(circ0, 0.2 )

# Add Arc1
circ1 = rs.AddArc(pln1, rad, 180)
rs.RotateObject(circ1, [0,0,0], 90,[0,0,1])
rs.ObjectPrintColor(circ1, [0,200,0])
rs.ObjectPrintWidth(circ1, 0.2 )

        #print deltaAngle*i
#coords upper jaw
dm.printDisplay(state=1, scale=10, thickness=1, color='Display')
lin0 = rs.AddLine( rs.CurveStartPoint(circ0), rs.CurveEndPoint(circ0))
rs.ObjectPrintColor(lin0, [0,200,220])
rs.ObjectPrintWidth(lin0, 0.2 )
coordsC = rs.DivideCurve(circ0, 1001, 0)
coordsL = rs.DivideCurve(lin0, 1001, 0)

#coords lower jaw
lin1 = rs.AddLine( rs.CurveStartPoint(circ0), rs.CurveEndPoint(circ0))
rs.ObjectPrintColor(lin1, [0,200,220])
rs.ObjectPrintWidth(lin1, 0.2 )
coordsC1 = rs.DivideCurve(circ1, 1001, 0)
coordsL1 = rs.DivideCurve(lin1, 1001, 0)

fuellCoords = []
for i in range(1001):
    
    pC = random.choice(coordsC)
    pL = random.choice(coordsL)
    pC1 = random.choice(coordsC1)
    pL1 = random.choice(coordsL1)
    #rs.AddCurve( [pC, pL] )
    pX = dm.pntInbetween(pC, pL, random.uniform(0,1))
    fuellCoords.append( pX )
    pX1 = dm.pntInbetween(pC1, pL1, random.uniform(0,1))
    fuellCoords.append( pX1 )
rs.ObjectColor(rs.AddPoints(fuellCoords), [60,170,15] )
    
    
xRange = int(rad)*2
yRange = random.randint(7,13)
zRange = random.randint(7,13)
#dm.PointRadius(displayModeX=1, rad=2, styl=3, verbose=1)

count = 0
newCoords = []
for x in range(xRange):
     #if x > xRange * 0.5:
        x += -rad+1
        for y in range(yRange):
                y += 1
                for z in range(zRange):
                            cor = [-x,-y,-z]
                            newCoords.append(cor)
                            
#rs.AddPoints(newCoords)
rs.AddCurve(newCoords)
#shuffle#
#random.shuffle(newCoords)
#newPoints = rs.AddPoints(newCoords)
#rs.AddCurve(newCoords)
#rs.AddCurve(coords, 1)
#rs.ZoomExtents()
#rand = random.uniform(0, 10)
#print rand

#colo = [random.randint(0,255), random.randint(0,255), random.randint(0,255)]
#rs.ObjectColor(pnt,colo)

#P1 = newCoords[random.randint(0, len(newCoords))]
#rs.AddPoints(coords)
#rs.AddCurve(coords, 3)

#for i in range(20):
#    P0 = random.choice(newCoords)
#    P1 = random.choice(newCoords)
#    P2 = random.choice(newCoords)
#    rs.AddCurve([P0, P1, P2, P0])