#######################################
### DM2_w22 # AGruber@tugraz.at     ###
### hu_03_startUp # infra_4_6371km  ### 
#######################################

##############################
import rhinoscriptsyntax as rs
import random, math, time
##############################

rs.UnitSystem(5)                                        # km = 5, meters = 4, cm = 3 etc
rs.Command("-groundplane Options On=No enter enter", 0) # groundplane > off
rs.ShowGrid(view=None, show=0)
rs.ShowGridAxes(view=None, show=1)
rs.EnableRedraw(0)
rs.ViewDisplayMode(view=None, mode="Wireframe")
rs.Command("-printDisplay State=Off enter", 0)

##############################
rs.ShowObjects(rs.AllObjects())
rs.DeleteObjects( rs.AllObjects() )
##############################
radiusX = rX = 6371          # km, erdradius
##############################

############################################
### a sphere and a cube / centered @ [0,0,0] - the size of the world :)
############################################

crv_x = rs.AddCurve( [ [rX, rX, -rX], [rX, rX, rX], [rX, -rX, rX], [rX, -rX, -rX], [rX, rX, -rX] ] ,1)
crv_y = rs.AddCurve( [ [rX, rX, -rX], [rX, rX, rX], [-rX, rX, rX], [-rX, rX, -rX], [rX, rX, -rX] ] ,1)
crv_z = rs.AddCurve( [ [rX, -rX, rX], [rX, rX, rX], [-rX, rX, rX], [-rX, -rX, rX], [rX, -rX, rX] ] ,1)

if 1:
    anzahl = random.randint(8, 8**2)
    print "*** anzahl", anzahl
    coords_x = rs.DivideCurve(crv_x, anzahl, 0)
    coords_y = rs.DivideCurve(crv_y, anzahl, 0)
    coords_z = rs.DivideCurve(crv_z, anzahl, 0)
    
    rs.DeleteObjects( rs.ObjectsByType( 4 ))        ## kill curves
    
    cubeCoords = coords_x+coords_y+coords_z
    print "*** lenx =", len(cubeCoords),
    cubeCoords = rs.CullDuplicatePoints( cubeCoords )
    print ">>", len(cubeCoords), ".. culled/ausgesondert :)"
    rs.AddPoints( cubeCoords )
    rs.AddCurve( cubeCoords )
    

    coords = []
    for cor in cubeCoords:
        uniVec = rs.VectorUnitize( cor )
        radVec = rs.VectorScale( uniVec, radiusX )
        coords.append( radVec )
        #rs.AddPoint( radVec )
        #rs.AddLine( radVec, cor )
    
    rs.AddPoints( coords)
    rs.AddCurve( coords )
    
    rs.ZoomExtents()

##############################here you go:
##########################################
##########################################








##############################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 "\tdate",
    print time.ctime(), "==",
    print time.time(), "seconds since 1 January 1970"
    
    if 1: ### capture images to P:\
        path = "P:/hu_03/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