##############################
###  DM2_w24  hu_03_setUp  ###
###  _diag  /  2024 10 17  ###
##############################
import rhinoscriptsyntax as rs
import random, time, sys   ###                                              
sys.path.append("P:/WWW/limafi/dm2")     ### add path where "DM_lib.py" can be found !!!                                              
import DM_lib as dm        ### reload(dm)    
##############################   

rs.UnitSystem(3)                       
rs.ShowGrid(view=None, show=0)
rs.ShowGridAxes(view=None, show=0)
rs.ViewDisplayMode(view=None, mode="Wireframe")
rs.EnableRedraw(0)
dm.PointRadius(displayModeX=0, rad=3, styl=1)
rs.DeleteObjects(rs.AllObjects())


######################################           
anz = random.choice( range(2**4, 2**8, 4) )
dm.allCoords = dm.setUp_hu_03( anz )
coordsCir = dm.allCoords[0]  ### calling def from DM_lib to get *new* set of coords
coordsCub = dm.allCoords[1]  ### calling def from DM_lib to get *new* set of coords
######################################

randomVec = [random.uniform(-30,30) for i in range(3)]
coordsCub = [rs.VectorRotate(cor, randomVec[0], randomVec) for cor in coordsCub]
coordsCir = [rs.VectorRotate(cor, randomVec[0], randomVec) for cor in coordsCir]
siz = rs.Distance( coordsCub[0],  coordsCub[1] ) ### edge length of cubus

#dm.textDots( coordsCub )
#rs.AddCurve( coordsCub, 1 )
#rs.AddCurve( coordsCir, 1 )
#dm.textDots( coordsCir )

anz = len(coordsCub)
print "*** anz =", anz
print "*** siz =", round(siz, 2), "/ edge lenght =", round(siz, 2),"*",int(anz/4),"=", round(siz*anz/4, 2)
print "*** **********\n"


### just demo ### just demo  >> remove it <<
if 1: 

    vecX = rs.VectorSubtract( coordsCub[1],  coordsCub[0] )
    vecY = rs.VectorSubtract( coordsCub[-1],  coordsCub[0] )
    vecZ = dm.normVec3pnts(coordsCub[0], coordsCub[1], coordsCub[-1]) ### unitVector / length = 1.0
    vecZ = rs.VectorScale( vecZ, siz )
    
    ptA = coordsCub[0]
    ptB = rs.VectorAdd( ptA, rs.VectorScale( vecX, anz/4) )
    ptC = rs.VectorAdd( ptB, rs.VectorScale( vecY, anz/4) )
    ptD = rs.VectorAdd( ptC, rs.VectorScale( vecX, -anz/4) )
    
    ptE = rs.VectorAdd( ptA, rs.VectorScale( vecZ, anz/4) )
    ptF = rs.VectorAdd( ptB, rs.VectorScale( vecZ, anz/4) )
    ptG = rs.VectorAdd( ptC, rs.VectorScale( vecZ, anz/4) )
    ptH = rs.VectorAdd( ptD, rs.VectorScale( vecZ, anz/4) )

    baseCrv = rs.AddCurve( [ptA, ptB, ptC, ptD, ptA], 1 ) 
    topCrv  = rs.AddCurve( [ptE, ptF, ptG, ptH, ptE], 1 ) 
#    for i,car in enumerate(["A","B","C","D","E","F","G","H"]):
#        rs.AddTextDot( car, [ptA, ptB, ptC, ptD,ptE, ptF, ptG, ptH][i] )

    rs.ZoomExtents()
    dirX = rs.CurveArrows (rs.AddLine(ptA, ptB), 2)
    dirY = rs.CurveArrows (rs.AddLine(ptA, ptD), 2)
    dirZ = rs.CurveArrows (rs.AddLine(ptA, ptE), 2)
    rs.ObjectColor(rs.AllObjects()[2], [200,20,20] )
    rs.ObjectColor(rs.AllObjects()[1], [20,200,20] )
    rs.ObjectColor(rs.AllObjects()[0], [20,20,200] )

if 1:
    coords = rs.DivideCurve(baseCrv, anz, 0)
    coords += rs.DivideCurve(topCrv, anz, 0)
    #rs.DeleteObjects( [baseCrv, topCrv] )
    
    cen = dm.pntInbetween(ptA, ptG)
    ran = random.uniform(4,16)
    for i,cor in enumerate(coords):
        vec = rs.VectorSubtract( cor, cen )
        unitVec = rs.VectorUnitize( vec )
        scalVec = rs.VectorScale( unitVec, siz*anz/ran)
        circPnt = rs.VectorAdd( cen, scalVec )
        if i%2==0:
            rs.AddLine( cor, circPnt )
        rs.ObjectColor( rs.AddPoint( circPnt ), [200,20,200] )
    
    coords = []
    for i in range(1001):
        scalVec = rs.VectorRotate( scalVec, random.uniform(-90,90), [random.uniform(-1,1) for i in range(3)])
        coords.append( rs.VectorAdd( cen, scalVec ) )
    rs.AddPoints( coords )

### just demo ### just demo  >> remove it <<

### here we go:


################
rs.ZoomExtents()
