#############################
### 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("C:/Verena/3. Semester/DM2/2. HUE- Uebung/")     ### *your* path to DM_lib.py                                            
sys.path.append("P:/WWW/TUGonlineUsernam/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)


# veranderungen muessen auch hier erfolgen da rhino sonst keine farben uebernimmt
# shaded und rendered

# hier beginnt der setup teil befehle die relevant fuer das projekt sind
rs.ShowGrid(show=0)
rs.ShowGridAxes(show=0)
rs.ViewDisplayMode(mode = "Wireframe")
# wireframe bedeutet dass nur drahtlinien angezeigt werden und keine objektfarben
rs.ViewDisplayMode(mode = "Shaded")
# fuer farben oder rendered
rs.ViewDisplayMode(mode = "Rendered")
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) ) # macht linien dicker und duenner vor allem wichtig fuer farben
##### end check setup

#######################################
################ HERE YOU GO AS YOU GO:
# ab hier duerfen Veraenderungen vorgenommen werden

dm.setTime()

### the circle
rs.AddCurve( points=coordsCir, degree=1)
### the square
rs.AddCurve( coordsSqu, 1)

rs.AddText("focus on the good", (0,0,0), height=0.5)

### 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
# Veraenderung Farbverlauf
# farbverlauf erzeugt eine farbpalette von rot bis blau
allColors = []
for i in range(anzahl):
    r = int(255*(i/float(anzahl))) # von null weg bis zweihundertfuenfundfuenfzig
    g = 50 # bleibt 
    b = int(255*(1-i/float(anzahl))) # sinkt von zweihundertfuenfundfuenfzig bis null
    allColors.append([r,g,b])


# faerben von Linien
for i in range(anzahl):
    rs.ObjectColorSource(allLines[i], 0) # farbe auf by object umstellen beide befehle erforderlich
    rs.ObjectColor(allLines[i], allColors[i]) # farbe vergeben wird nur angezeigt wenn rhino die farbe by object zeigt 

# Rechtecke an Linienenden 
for i, line in enumerate (allLines):
    color = allColors[i]
    start_pt = rs.CurveStartPoint(line)
    rect = rs.AddRectangle(rs.MovePlane(rs.WorldXYPlane(),start_pt),2,1) # zeichnet rechteck mit breite zwei und hoehe eins wird durch moveplane an die position einer linie verschoben bzw start der linie
    rs.ObjectColorSource(rect, 0)
    rs.ObjectColor(rect, color)

dm.getTime( verbose=1 )
rs.Command("-zoom extents enter -zoom Factor 0.9 enter", 0) # change zoom for better framing







