############################
### diag @ IAM @ DM2_w25 ###
### hu_03 setUp_ver00    ### see examples @ DM2_w23 hu_03 !
############################


##############################
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/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 )

rs.ShowGrid(show=0)
rs.ShowGridAxes(show=1)
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

dm.eAA()



### BASIC SETUP / mandatory input:
if 0:
    allInOne = 1
    allCoords = dm.coordsCub (what="F")
    allCoords = dm.coordsCub (edge_len=10, anz_pts=10, what="A", angle=random.uniform(0,360), axe=dm.randVec(-1,1), pos=[0,0,10], allInOne=allInOne)
    
    coordsSph = allCoords[0]
    coordsCub = allCoords[1]



##### check setup - just visualization of coords
##### don't execute  @ final version of homework
if 0:
    rs.AddPoints( coordsSph )
    
    if allInOne:
        rs.AddPoints( coordsCub )
    else:
        for i,coords in enumerate(coordsCub): 
            pts = rs.AddPoints( coords )
##### end check setup

#######################################
################ HERE YOU GO AS YOU GO:
dm.setTime()


#rs.AddPoint( [0,0,0] )
#rs.AddPoint( [1,0,0] )
#rs.AddPoint( [2,0,0] )
anzahl = 5
coords = []
for x in range(anzahl):
    for y in range(anzahl):
        for z in range(anzahl):
            #rs.AddPoint( [x,y,z] )
            coords.append([x,y,z])

coords = [ [x,y,z] for x in range(anzahl) for y in range(anzahl) for z in range(anzahl) ]

ang = random.uniform(-90,90)
axe = dm.randVec()
for i,cor in enumerate(coords):
    cor = rs.VectorRotate( cor, ang, axe ) ##|  VectorRotate(vector, angle_degrees, axis) 
    cor = rs.VectorAdd( cor, [0,0,15] ) ##|  VectorRotate(vector, angle_degrees, axis) 
    coords[i] = cor

coordsCub = coords[:]
rs.AddPoints( coordsCub )

p0 = [5,0,0]
#rs.AddPoint( p0 )
#rs.AddLine( [0,0,0], p0 )
for i in range(anzahl**4 ):
    pX = rs.VectorRotate( p0, 10.0*i, dm.randVec())
    #rs.AddPoint( pX )
    #rs.AddLine( [0,0,0], pX )

coordsSph = [ rs.VectorRotate( p0, random.uniform(0,360), dm.randVec()) for i in range(anzahl**3 ) ]
rs.AddPoints( coordsSph )
#rs.AddCurve( coordsSph )
coordsSph = sorted(coordsSph, key=lambda xxx: xxx[1]) ### that's essential !
#rs.AddCurve( coordsSph )
rs.ObjectColor(rs.AllObjects()[0], [22,22,222] )

connectList = []
for p0 in coordsSph:
    for p1 in coordsCub:
        connectList.append( [[p0,p1], rs.Distance(p0,p1)] )
print "connectList", len(connectList)

for i in range(100):
    p0 = connectList[i][0][0]
    p1 = connectList[i][0][1]
    rs.AddLine( p0, p1 )

print "points =", len(rs.ObjectsByType(1))

rs.Command("seldup enter", 0)
dm.getTime( 1 )
#################
#dm.eDup( 1 )
dm.zA( 0.9 ) ### zoom all minus 0.9


