############################
### diag @ IAM @ DM2_w25 ###
### hu_02 setUp_ver00    ### see examples @ DM2_w23 hu_02 !
############################


##############################
import rhinoscriptsyntax as rs
import random, time, sys   ###
sys.path.append("P:/")     ###                  ### diag's path to DM_lib.py                                                 
sys.path.append("P:/WWW/dx6419/dm2/")             ### *your* path to DM_lib.py                                            
sys.path.append("/Users/macpro/Desktop/DM2")    ### *your* path to DM_lib.py         
sys.path.append("P:/WWW/sirren")                ### *your* path to DM_lib.py         
import DM_lib as dm        ###                  ### "dm" is alias for DM_lib / for adressing definitions in  DM_lib
############################## reload(dm)

for pth in sys.path: print pth
print

rs.ShowGrid(show=1)
rs.ShowGridAxes(show=1)
rs.ViewDisplayMode(mode="Wireframe")
rs.EnableRedraw(0)
dm.PointRadius(displayModeX=0, rad=3, styl=3)
dm.printDisplay(state=3, scale=2, thickness=1, color="Display")

rs.DeleteObjects(rs.AllObjects())

allCoords = dm.setUp_hu_02( anzahl=7*12,  rotateSqu=random.uniform(70,130) )
coordsCir=allCoords[0]
coordsSqu=allCoords[1]

##### check setup - just visualization of coords
##### don't execute  @ final version of homework
if 1:
    rs.AddPoints( coordsCir )
    rs.AddPoints( coordsSqu )
if 0:
    rs.ObjectColor(dm.textDots(coordsCir), [115,0,20])
    rs.ObjectColor(dm.textDots(coordsSqu), [20,0,115])
if 0:
    rs.AddCurve( coordsCir, 5)
    rs.AddCurve( coordsSqu, 3)
    for i in range( len(coordsSqu) ):
        p0  = coordsCir[i]
        p1  = coordsSqu[i]
        lin = rs.AddLine(p0, p1)
        rs.ObjectName(lin, "linx_"+str(i))
        rs.ObjectColor(lin, [222*(i!=0), 22*(i!=0), 222])
        rs.ObjectPrintWidth( lin, 1.0*(i==2) )
##### end check setup




################ here you go as you go:
### rs.DeleteObjects( rs.AllObjects())



### the circle
rs.AddCurve( points=coordsCir, degree=3)
### the square
rs.AddCurve( coordsSqu, 1)


### connect coordsCir..coordsSqu
anzahl = len(coordsSqu)
allLines = [] ### leeres array
for i in range(anzahl):
    p0 = coordsCir[i]
    p1 = coordsSqu[i]
    lin = rs.AddLine( p0, p1 )  ### rs.AddLine(..) returns ID of line > saved 2 variable "lin"
    allLines.append( lin)       ### die ID 'lin' an array allLines anhaengen

### den lines RGB_colos zuweisen
### c = 0
allColors = []
var = random.randint(0,1)       ### einmal so, einmal soo :)
### var = 1
for i in range(anzahl):
    ### var_0:
    ### quadrant_weise: farbwexel bei (anzahl/4)*0, (anzahl/4)*1, (anzahl/4)*2, (anzahl/4)*3 .. zB 0, 32, 64, 96
    if (i%(anzahl/4) == 0):  ### wenn i/32 rest 0 ergibt ..
        ### c += 2
        c  = int(i/(anzahl-i))+1
        print "i="+str(i) , "c=", c
        ### .. neue werte fuer array (!) [R, G, B]
        colorX = [60*c, 240-(60*c), random.randint(0,255)]
    
    ### var_1:
    ### all random colors: farbwexel bei jedem loop
    if var:                     ### if var !=0 / if var == 1 / if True ..
        colorX = [random.randint(0,255), random.randint(0,255), random.randint(0,255)] ### color [R, G, B] / jeweils 0..255
    
    ### alle farbwerte [R,G,B] in allColors_array befoerdern
    allColors.append( colorX )

for i in range(anzahl):
    rs.ObjectColor( allLines[i], allColors[i] ) ### need i

#################
#rs.ZoomExtents()
dm.getTime( verbose=1 )
rs.Command("-zoom extents enter -zoom Factor 0.9 enter", 0) # change zoom for better framing


