############################
### diag @ IAM @ DM2_w25 ###
### hu_03 setUp_ver01    ### 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("C:/Verena/3. Semester/DM2/3. HUE- Uebung/")### *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.AppearanceColor(item=0, color=[222, 222, 22])               ### item=0 => backgroundColor [R,G,B]
rs.UnitSystem(unit_system=3)                                    ### 2..mm / 3..cm / 4..m etc >> printDisplay scale !

dm.PointRadius(displayModeX=0, rad=2, 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 << UnitSystem

rs.EnableRedraw(0)
dm.eAA()                                    ### erase Absolutly All - includes locked, hidden etc objects 



### BASIC SETUP / mandatory input / dm.setUp_hu_03(..):

### arguments @ dm.setUp_hu_03(..):

### allInOne 0: coords of slices / faces / edges / meridians etc in *separate* (sub_)lists
### allInOne 1: all cube_coords and all sphere_coords in *jeweils* 1 (one !) list

### what = "A" : A.ll coords 
### what = "E" : E.dge's coords of cube / meridians of sphere / in 12 separate lists
### what = "F" : F.ace's coords of cube / meridians of sphere / in  6 separate lists

###  all other : arguments/defaults as defined @ library

allInOne  = 1

### DEFAULT arguments:
### allCoords = dm.setUp_hu_03(edge_len=random.uniform(8,16), anz_pts=random.randint(8,16), what="A", angle=random.uniform(-360, 360), axe=dm.randVec(), pos=[0,0,random.uniform(8,16)], allInOne=allInOne, verbose=1)
allCoords = dm.setUp_hu_03(edge_len=random.uniform(8,16), anz_pts=random.randint(8,16), what="A", angle=random.uniform(-360, 360), axe=dm.randVec(), pos=[0,0,random.uniform(8,16)], allInOne=allInOne, verbose=1)

### here YOU mite set YOUR favorite arguments:
#allCoords = dm.setUp_hu_03(edge_len=10, anz_pts=5, what="f", angle=random.uniform(-360, 360)*0, axe=randVec(), pos=[0,0,10], allInOne=allInOne, verbose=1)


######################## dont't touch
coordsSph = allCoords[0]
coordsCub = allCoords[1]
########################


# das setup erzeugt zwei mengen von punkten
'''
' check setup - just visualization of setUp >> dont execute @ final version of homework <<                                      '
'''
if 0:
    if allInOne == 0:
        pts = rs.AddPoints( coordsSph )
        # coordsSph ist fuer Punkte die zu einer spherischen form gehoeren
        rs.AddGroup("sph"), rs.AddObjectsToGroup(pts, "sph")
        rs.ObjectColor( pts, [255,200,000])
        pts = rs.AddPoints( coordsCub )
        rs.AddGroup("cub"), rs.AddObjectsToGroup(pts, "cub")
        rs.ObjectColor( pts, [100,200,255])
    else:
        # coordsCub ist fuer Punkte die zu einer kubischen Form gehoeren
        for i,coords in enumerate(coordsCub): 
            pts = rs.AddPoints( coords )
            rs.AddGroup("cub"+str(i)), rs.AddObjectsToGroup(pts, "cub"+str(i))
            rs.ObjectColor(pts, [10*random.randint(1,25), 10*random.randint(1,25),  10*random.randint(1,25)] )
        if len(coordsSph) < 7:
            for i, coords in enumerate(coordsSph):
                pts = rs.AddPoints( coords )
                rs.AddGroup("sph"+str(i)), rs.AddObjectsToGroup(pts, "sph"+str(i))
                rs.ObjectColor(pts, [10*random.randint(15,20), 10*random.randint(15,20),  10*random.randint(1,10)] )
        if len(coordsSph) > 6:
            pts = rs.AddPoints( coordsSph )
            rs.AddGroup("sph"), rs.AddObjectsToGroup(pts, "sph")
            rs.ObjectColor(pts, [10*random.randint(15,20), 10*random.randint(15,20),  10*random.randint(2,2)] )
            # es entsteht ein gelblicher kreis und ein blauer wuerfel
            # meine ausgangssituation
'''              
' end check setup                                                                                                                   ' 
'''


#######################################
################ HERE YOU GO AS YOU GO:
    # beziehung von kreis und wuerfel
    # definieren von farben
    
rs.ViewDisplayMode(mode = "Wireframe")
dm.printDisplay(state=1, scale=1, thickness=2, color = "Display")

color_cube = [0, 120, 255] #blau
color_sphere = [0, 255, 100] #gruen
color_lines = [255, 150, 100] #rosa
color_mix = [255, 255, 120] #gelb

# punkte verschieben
coordsCub_shifted = [[x, y, z - 20] for x, y, z in coordsCub] #wuerfel nach unten
coordsSph_shifted = [[x, y, z + 20] for x, y, z in coordsSph] #kugel nach unten


# punkte zeichnen verschoben wuerfel
pts_cub = rs.AddPoints(coordsCub_shifted)
rs.ObjectColor(pts_cub, color_cube)
rs.AddGroup("mycube"), rs.AddObjectsToGroup(pts_cub, "myCube")

#punkte einzeichnen kugel verschoben
pts_sph = rs.AddPoints(coordsSph_shifted)
rs.ObjectColor(pts_sph, color_sphere)
rs.AddGroup("mySphere"), rs.AddObjectsToGroup(pts_sph, "mysphere")

#verbindungen bzw verbindungslinien zwischen cube und sphere fuer mehr struktur
anz = min(len(coordsCub_shifted), len(coordsSph_shifted))
for i in range(anz):
    line = rs.AddLine(coordsCub_shifted[i], coordsSph_shifted[i])
    rs.ObjectColor(line, color_lines)
    rs.ObjectPrintColor(line, color_lines) #erzwingt die anzeige der farbei bei befehl printDisplay linien farbig sichtbar
# bessere struktur kurve aus jedem zweiten cube punkt
if len(coordsCub_shifted) > 4:
    mid_points = coordsCub_shifted[::2] #jeder zweite punkt
    curve = rs.AddInterpCurve(mid_points, degree=2)
    rs.ObjectColor(curve, color_lines)
    rs.ObjectPrintColor(curve, color_lines)
    
### zwischenpunkte
mix_pts = []
for i in range(anz):
    x1, y1, z1 = coordsCub_shifted[i]
    x2, y2, z2 = coordsSph_shifted[i]
    # punkte zwischen cube und sphere mittelwerte dafuer formeln mit x y z 
    mix = [(x1 + x2) / 2, (y1 + y2) / 2, (z1 + z2) / 2]
    mix_pts.append(mix)

pts_mix = rs.AddPoints(mix_pts)
rs.ObjectColor(pts_mix, color_mix)
rs.AddGroup("mix"), rs.AddObjectsToGroup(pts_mix, "mix")







#################
#dm.eDup( 1 )
# ansicht anpassen leichter zoom
dm.zA( 0.9 ) ### zoom all minus 0.9



