logo

BUNDLING_AND_ATTRACTOR POINTS

"""
Script written by Luis Quinones
www.luisquinonesdesign.com
www.computationalmatter.com
Script version Tuesday, 28 June 2011 20:18:46
"""
import rhinoscriptsyntax as rs
import math
Gens = rs.GetInteger("Number of Generations",6,1)
Curves = rs.GetObjects("Select Base Crvs",rs.filter.curve)
AttractorPts = rs.GetObjects("Attractor Points",rs.filter.point)
Attract = rs.GetReal("CurvePointAttractionThreshold")
attPtThresh = rs.GetReal("AttractorPointThreshold")
dblRatio = rs.GetReal("Distance For Vector To Move")
Rebuild = rs.GetInteger("Degree To Rebuild Curves")
AttractorPtsList = []
for z in range(len(AttractorPts)):
    AttractorPtsList.append(rs.PointCoordinates(AttractorPts[z]))
for i in range(Gens): 
        for j in range(len(Curves)):
            arrNewPos = []
            PointCount = rs.CurvePointCount(Curves[j])
            arrCrvDiv = rs.CurvePoints(Curves[j])          
            if arrCrvDiv:
                print "BOOM"
            else: 
                print "Nope"                
            for k in range(PointCount):             
                arrCrvPts = []               
                if not AttractorPtsList:                    
                    print "really"                    
                indexClosestAtt = rs.PointArrayClosestPoint(AttractorPtsList,arrCrvDiv[k])
                attPt = AttractorPtsList[indexClosestAtt]
                dist2 = rs.Distance(attPt,arrCrvDiv[k])                
                if dist2 < attPtThresh :                   
                    NewPosition = attPt               
                else:                   
                    for L in range(len(Curves)):                                              
                        if j != L :                            
                            arrCrvParam = rs.CurveClosestPoint(Curves[L],arrCrvDiv[k])                            
                            crvPt = rs.EvaluateCurve(Curves[L],arrCrvParam)                            
                            arrCrvPts.append(crvPt)                            
                    IndClosestCrv = rs.PointArrayClosestPoint(arrCrvPts,arrCrvDiv[k])
                    #print "NextClosestIndex = ",IndClosestCrv
                    crvPt = arrCrvPts[IndClosestCrv]
                    #print crvPt                    
                    dist = rs.Distance(arrCrvDiv[k],crvPt)                   
                    if dist < Attract :                      
                        vector = rs.VectorCreate(crvPt,arrCrvDiv[k])
                        vector = rs.VectorScale(vector,dblRatio)
                        NewPosition = rs.VectorAdd(vector,arrCrvDiv[k])                        
                    else:                        
                        NewPosition = arrCrvDiv[k]                                            
                arrNewPos.append(NewPosition)          
            newcurve = rs.AddCurve(arrNewPos,Rebuild)
            rs.DeleteObject(Curves[j])
            #rs.ObjectColor(newcurve,[j,j,j])
            Curves[j] = newcurve 
  • Share