###############
### DM2_w24 ###
### sorting ###
###############

##############################
import rhinoscriptsyntax as rs
import random, math, sys
sys.path.append("P:/WWW/limafi/dm2")     ###
import DM_lib as dm        ### reload(dm)
###################

dm.eA()

rX  = math.pi
anz = 1001
coords = [ random.sample([ rX*([-1,1][random.randint(0,1)]), random.uniform(-rX,rX), random.uniform(-rX,rX)], 3) for i in range(anz) ]
coords = [ rs.VectorRotate([rX,0,0], random.uniform(0,360), dm.randVec(-1,1)) for i in range(anz) ]
rs.AddPoints( coords )


if 1:
    cor = [ rX*[-1,1][random.randint(0,1)], random.uniform(-rX,rX), random.uniform(-rX,rX)]
    cor = "a n d i G"
    print "cor", cor
    cor = cor.split() ## split => string to list !
    print "cor", cor
    print "random.sample( cor, 3)", random.sample( cor, 3) ### random.sample: returns a list that contains a certain number of the items from a list
    print "random.sample( cor, 2)", random.sample( cor, 2)
    print "random.sample( cor, 1)", random.sample( cor, 1)

if 0:
    rs.DeleteObjects( rs.ObjectsByType(1+4+8192)) ### 1points, 3=curves, 8192=txtDots
    coords = coords[0:101]
    rs.AddCurve( coords, 1 )
    coords = sorted(coords, key=lambda corX: corX[0])
    dm.textDots(coords)
    rs.ObjectColor( rs.AddCurve( coords, 2 ), [200,0,0] )

if 0:
    rs.DeleteObjects( rs.ObjectsByType(1+4+8192)) ### 1points, 3=curves, 8192=txtDots
    deg = 7 ### max = 11 !
    #rs.ObjectColor( rs.AddCurve( sorted(coords, key=lambda keyX: keyX[0]), deg ), [200,0,0] )
    rs.ObjectColor( rs.AddCurve( sorted(coords, key=lambda keyX: keyX[1]), deg ), [0,200,0] )
    rs.ObjectColor( rs.AddCurve( sorted(coords, key=lambda keyX: keyX[2]), deg ), [0,0,200] )
rs.ZoomExtents()