#############################
### diag @ IAM @ DM2_w25  ###
### hu_02 setUp_ver00_demo_02
#############################


##############################
import rhinoscriptsyntax as rs
import random, time, sys   ###
sys.path.append("P:/")     ###                  ### diag's path to DM_lib.py  .. please keep it !                                               
sys.path.append("P:/TUGonlineUsernam/dm2/")     ### *your* path to DM_lib.py                                            
sys.path.append("P:/WWW/lukschme/dm2/") ### *your* path to DM_lib.py                                            
sys.path.append("/Users/macpro/Desktop/DM2")    ### *your* path to DM_lib.py      
import DM_lib as dm        ###                  ### "dm" is alias for DM_lib / for adressing definitions etc in "DM_lib.py"
############################## reload(dm)

rs.ShowGrid(show=0)
rs.ShowGridAxes(show=0)
rs.ViewDisplayMode(mode="Wireframe")
rs.EnableRedraw(0)

dm.PointRadius(displayModeX=0, rad=3, styl=3)                   ### displayModeX=0="Wireframe" / rad=size of points / styl=pointStyle (try 0..5) / default 3, 3
dm.printDisplay(state=1, scale=1, thickness=1, color="Display") ### state=0/1 = off/on / for showing printWidth etc

rs.DeleteObjects(rs.AllObjects())

allCoords = dm.setUp_hu_02( anzahl=4*132,  rotateSqu=random.uniform(-90,90) )
coordsCir=allCoords[0]
coordsSqu=allCoords[1]

##### check setup - just visualization of coords
##### don't execute  @ final version of homework

if 0: ### 0 for *your* final version !
    if 1:
        rs.AddPoints( coordsCir )
        rs.AddPoints( coordsSqu )
    if 0:
        rs.ObjectColor(dm.textDots(coordsCir), [111,0,11])
        rs.ObjectColor(dm.textDots(coordsSqu), [11,0,111])
    if 0:
        rs.AddCurve( coordsCir, 1)
        rs.AddCurve( coordsSqu, 1)
        for i in range( len(coordsSqu) ):
            p0  = coordsCir[i]
            p1  = coordsSqu[i]
            lin = rs.AddLine(p0, p1)
            rs.ObjectColor(lin, [222*(i!=0), 22*(i!=0), 222])
            rs.ObjectPrintWidth( lin, 1.0*(i==0) )
##### end check setup

#######################################
################ HERE YOU GO AS YOU GO:
dm.setTime()

### the circle
rs.AddCurve( points=coordsCir, degree=1)
### 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 += 1
        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





