#####################################
### DM2_w22 # AGruber@tugraz.at   ###
### hu_02_setup # alice_and_bob   ###
#####################################

##############################
import rhinoscriptsyntax as rs
import random
##############################

rs.UnitSystem(4)                       
rs.ShowGrid(view=None, show=0)
rs.ShowGridAxes(view=None, show=1)
rs.EnableRedraw(1)
rs.ViewDisplayMode(view=None, mode="Ghosted")
rs.Command("-printDisplay State=On enter", 0)

rs.ShowObjects(rs.AllObjects())
rs.DeleteObjects( rs.AllObjects() )
rs.CurrentLayer("Default")


print "\t   ********\**/************"
print "\t  **********\/entanglement"
print "\t my quantum /\***********"
print "\t***********/**\*********\n\n",



layNam = "MY_SETUP"
rs.CurrentLayer(rs.AddLayer(layNam))
rs.LayerPrintColor(layNam, [100,100,100])
rs.LayerPrintWidth(layNam, 1.0)

#______base vectors
randi = 100
vecA  = [ random.uniform(-randi,randi), random.uniform(-randi,randi), random.uniform(-randi,-randi*1.5) ]
vecB  = [ random.uniform(-randi,randi), random.uniform(-randi,randi), random.uniform( randi, randi*1.5) ]

def myCoords( a=random.uniform(50,300), mov=vecA ):
    coords = [[0,0,0], [a,0,0], [a,a,0], [0,a,0]]
    rotXYZ = [ random.uniform(-30,30), random.uniform(-30,30), random.uniform(-30,30) ]
    #for i in range( len(coords) ): coords[i] = rs.VectorAdd(coords[i], mov)
    for i in range( len(coords) ):
        coords[i] = rs.VectorAdd(coords[i], mov)
        coords[i] = rs.VectorRotate(coords[i], 30, rotXYZ)
    return coords


coords_a = myCoords(random.uniform(50,300), vecA)
coords_b = myCoords(random.uniform(50,300), vecB)
rs.AddPoints( coords_a+coords_b )
rs.AddCurve ( coords_a+coords_b, 1)
rs.ZoomExtents()
for i,cor in enumerate(coords_a+coords_b): rs.ObjectColor(rs.AddTextDot(str(i-(i>3)*4), cor), [200,0,200])
rs.Sleep(1000)



##############################here you go:
##########################################
##########################################
layNam = "MY_PROJECT"
rs.CurrentLayer(rs.AddLayer(layNam))
rs.LayerPrintColor(layNam, [200,100,100])
rs.LayerVisible("MY_SETUP", 0)

rs.ZoomExtents()
rs.Command("-printDisplay State=Off enter", 0)
rs.CurrentLayer("Default")

#hinzufuegen von rechteck oben und unten
curve_1 = rs.AddCurve([coords_a[0],coords_a[1],coords_a[2],coords_a[3],coords_a[0]],1)
curve_2 = rs.AddCurve([coords_b[0],coords_b[1],coords_b[2],coords_b[3],coords_b[0]],1)

#sicherstellen dass immer ein gegenueberliegender Punkt vorhanden ist
counter = 30
if (counter%2) != 0:
    counter = counter + 1
    print counter
else:
    print counter


#Punkte entlang der rechtecke erzeugen
points_1 = rs.DivideCurve(curve_1,counter,create_points=1)
points_2 = rs.DivideCurve(curve_2,counter,create_points=1)



#punkt von unterem rechteck mit gegenueberliegenden punkt im oberen verbinden
for p in range(counter-1):
    if p <= 9:
        con_p1 = int(p+(counter/2))
        print con_p1
        rs.AddCurve([points_1[p],points_2[con_p1]],1)
    else:
        con_p2 = int(p-(counter/2))
        print con_p2
        rs.AddCurve([points_1[p],points_2[con_p2]],1)




##############################here you end
##########################################
##########################################






######################
#______4_lazy_experts:
if 0:
    import time
    rs.ZoomExtents()
    rs.Command("-zoom Factor 0.95 enter", 0)
    rs.Redraw()
    from datetime import datetime
    #print str(datetime.now())[0:19]
    #print datetime.now().strftime('%a %b  / %d.%m.%Y um %Huhr und %Mmin und %Ssec')
    #print time.ctime()
    
    if 0: ### capture images to P:\
        path = "P:/ue_02/images/" ### if there is no folder like this: check your desktop 
        name = "tst"
        rs.Command("-viewCaptureToFile Width=480  Height=360  Scale=1.5 TransparentBackground=Yes "+path+name, 0)
        name = name+"_"+str(int(time.time()))+".jpg"
        rs.Command("-viewCaptureToFile Width=480  Height=360  Scale=2 DrawGrid=No  DrawWorldAxes=No  DrawCPlaneAxes=No TransparentBackground=No  "+path+name, 0)
        print path+name


