
##############################
########Marilyn Monroe########




##############################
import rhinoscriptsyntax as rs
import random, time, sys, math, os   ###
#from itertools import combinations
#from itertools import permutations
import itertools
sys.path.append("P:/")     ###
sys.path.append("L:/")     ###
sys.path.append("P:/WWW/mraontu/dm2/")
import DM_lib as dm        ### reload(dm)
############################## 


rs.UnitSystem(4)                                        # meters = 4, cm = 3 etc
rs.ShowGrid(None, 0)                                    # grid > 0 = off
rs.ShowGridAxes(None, 0)                                # y/y/z axen display > 0/1 = off/on
rs.ViewDisplayMode(rs.CurrentView(), "wireframe")
rs.Command("cplane w t enter", 0)						
dm.PointRadius(displayModeX=0, rad=1, styl=3)
dm.printDisplay(0)                                      
rs.EnableRedraw(0)


#dm.newEmptyLayer("Marilyn", [0,120,220])
rs.Redraw()

def makeFigure( pnts=[], crv_degree=1, pos=[30.0, 0,0], divis=64, show=1, delIt=1, crv_name="singt", obj_color=[0,200,0]):
    coords = [ rs.VectorAdd(cor, pos) for cor in pnts ]
    crvID = rs.AddCurve(coords, crv_degree)
    rs.ObjectColor( crvID, obj_color )
    rs.ObjectName( crvID, crv_name )
    coords = rs.DivideCurve( crvID, divis, show )
    if delIt: rs.DeleteObject( crvID )
    return coords

anz = 18*7
showPts = 0
deg = 1
delIt = 0


#coords_1 = makeFigure( pnts=pnts_singt, crv_degree=deg, pos=[50.0, 10.0,0], divis=anz, show=showPts, delIt=delIt, crv_name="MM_singt", obj_color=[0,200,0])
#coords_2 = makeFigure( pnts=pnts_wind, crv_degree=deg, pos=[00.0, 10.0,0], divis=anz, show=showPts, delIt=delIt, crv_name="MM_wind", obj_color=[210,0,120])

dm.newEmptyLayer("PROJ_MM")
#dm.setCameraTarget( [3041.31517563, -2800.26096912, 607.17679033], [-502.90614144, -445.42106446, -343.98856543], lens=50.0, rota=0, upVec=[-0.18169718703862137,0.12072264915897345,0.9759160692407373] ) # ... danke, andi !

rs.LayerVisible("turn_figuren", 1)

if 1:
    rs.LayerVisible("Marilyn", 1)
    MM_0 = rs.ObjectsByName("spagat")[0]
    MM_1 = rs.ObjectsByName("pose_0")[0]
    MM_2 = rs.ObjectsByName("spagat_1")[0]
    MM_3 = rs.ObjectsByName("pose_1")[0]
    coords_0 = rs.DivideCurve(MM_0, anz, 0)
    coords_1 = rs.DivideCurve(MM_1, anz, 0)
    coords_2 = rs.DivideCurve(MM_2, anz, 0)
    coords_3 = rs.DivideCurve(MM_3, anz, 0)
    dm.exportCoordLists(list2export=[coords_0,coords_1,coords_2,coords_3], exportedListName='allCoords', path="P:/WWW/mraontu/dm2/", fileName='MM_coords')
rs.LayerVisible("Marilyn", 0)
rs.LayerVisible("turn_figuren", 0)
rs.LayerVisible("Default", 0)

######################
import MM_coords as mm
reload(mm)
######################



#print mm.allCoords[0][0]
coords_0 = mm.allCoords[0]
coords_1 = mm.allCoords[1]
coords_2 = mm.allCoords[2]
coords_3 = mm.allCoords[3]

if 1: ### just tst
    for coords in mm.allCoords:
        rs.AddCurve( coords, 1 )
        rs.Redraw()
        rs.Sleep(1000)
        rs.AddPoint( coords[0] )
        rs.Redraw()

dm.getCameraTarget()
#dm.setCameraTarget( [-77.48685689, 11.77273249, 12.05421199], [17.20711797, 25.7546931, 14.05896983], lens=49.99999999, rota=0, upVec=[-0.020714654726424725,-0.003058605226544303,0.999780749971529] ) # ... danke, andi !
## cam 1
#dm.setCameraTarget( [-3151.51513522, -763.71493147, 419.74295749], [-582.27838656, -384.35640237, -47.55628417], lens=49.99999999, rota=0, upVec=[0.17518845445825773,0.02586730648051854,0.9841950456489659] ) # ... danke, andi !
#dm.setCameraTarget( [2282.27449924, -671.8852515, 454.02906213], [-361.78198394, 156.74870715, -257.41642053], lens=49.99999999, rota=0, upVec=[-0.23731190987082756,0.07437235496387741,0.9685823714329036] ) # ... danke, andi !
#dm.setCameraTarget( [3041.31517563, -2800.26096912, 607.17679033], [-502.90614144, -445.42106447, -343.98856543], lens=49.99999999, rota=0, upVec=[-0.1816971870388222,0.12072264915928207,0.9759160692406617] ) # ... danke, andi !
dm.setCameraTarget( [2938.58227795, -984.05925451, 193.50954948], [2938.58227795, 649.48487603, 193.50954948], lens=6.715e-05, rota=0, upVec=[0,0,1] ) # ... danke, andi !


allCoords = [coords_0, coords_1, coords_2, coords_3]#, coords_0]


if 0:
    captureIt  = 0
    keepFrames = 3
    framesProFigur = 25*1
    path = "L:/animatzi/MM_tst/"
    if not os.path.exists(path): os.makedirs(path)

    fac = 1/framesProFigur
    #allCoords = []
    for i in range(0, len(allCoords)-1):
        framNumber = 0
        coords_A = allCoords[i][:]
        coords_B = allCoords[i+1][:]
        #rs.AddLine( coords_A[0], coords_B[0] )
        for fram in range(0, framesProFigur+1):
            coords = [ dm.pntInbetween( coords_A[j], coords_B[j], fac*framNumber ) for j in range(anz) ] ### anz = points pro figur
            frameCrvs = rs.ObjectsByName("frameCrv")
            if len(frameCrvs) == keepFrames:
                rs.DeleteObjects(frameCrvs[-1:])
            coords.append(coords[0])
            crv = rs.AddCurve(coords, deg)
            rs.ObjectName(crv, "frameCrv")
            rs.Redraw()
            nam = dm.makeName("MM", frameNumber=framNumber+i*framesProFigur, anzahl=4, format='jpg')
            if captureIt:
                rs.Command("-viewCaptureToFile Width=960 Height=540 Scale=1 DrawCPlaneAxes=No TransparentBackground=No "+path+nam+" ", 0)
            framNumber +=1
            #print nam
            dm.esc()

    if 0:
        radius = 50 
        center = [200,0,0]
        dAng = 360.0 / (frames+0)
        for i, coords in enumerate(allCoords):
            coords.append(coords[0])
            coords = [rs.VectorAdd( cor, [0, radius, 0]) for cor in coords]
            coords = [rs.VectorRotate( cor, i*dAng, [0,0,1]) for cor in coords]
            coords = [rs.VectorAdd( cor, center) for cor in coords]
            Curve_180 = rs.AddCurve (coords, deg)
            rs.ObjectColor( Curve_180, [255,0,0] )
            rs.Redraw()
    


    
    
    if 0:
        fac = 1/steps
        allCoords = []
        for k in range(0,steps):
            facX = fac*k
            coords = []
            for j in range(anz):
                cor = dm.pntInbetween( coords_1[j], coords_2[j], facX )
                coords.append(cor)
            allCoords.append( coords )
    
    
    if 0:
        Angle = -180.0 / (steps+0)
        for i, coords in enumerate(allCoords):
            coords.append(coords[0])
            coords = [rs.VectorAdd( cor, [0, radius, 0]) for cor in coords]
            coords = [rs.VectorRotate( cor, i*Angle, [0,0,1]) for cor in coords]
            coords = [rs.VectorAdd( cor, center) for cor in coords]
            Curve_180 = rs.AddCurve (coords, deg)
            rs.ObjectColor( Curve_180, [255,0,0] )
if 0:
    dm.newEmptyLayer("Metal", [255,0,0])
    
    RotationCenter = [550.478522464829, 82960.335677139, 30]
    RotationAxis = [0, 0, 1]
    AngleIncrement = 4.5
    LineTemplate = rs.AddLine([550.478522464829, 82960.335677139, 30], [638.478522464829, 82960.335677139, 30.5])
    
    
    if 0:
        for _ in range(80):
            RotatedLine = rs.CopyObject(LineTemplate)
            rs.RotateObject(RotatedLine, RotationCenter, AngleIncrement, RotationAxis)
            LineTemplate = RotatedLine 
            
            
            
rs.LayerVisible("Default", 1)

rs.CurrentLayer("Default")
dm.printDisplay(1)






#print round(48/11, 2)
#print 48 - round(48/11, 2)
#print (48 - round(48/11, 2)) + round(48/11, 2)