import rhinoscriptsyntax as rs
“””
###########################################################################################
Script written by Luis Quinones & eb & flj
Script copyrighted by algorithmicdesign.net + [n]igma + studioBoom
Script version Sunday, June 25, 2011 1:07:59 PM
###########################################################################################
“””
import rhinoscriptsyntax as rs
import math
def Main():
Gens = 18
#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”, 40)
attPtThresh = rs.GetReal(“AttractorPointThreshold”, 20)
dblRatio = rs.GetReal(“Distance For Vector To Move”, 1)
attractorMag = rs.GetReal(“Magnitude of the attractor”, 1)
#Rebuild = rs.GetInteger(“Degree To Rebuild Curves”, 3)
Rebuild = 3
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])
for k in range(PointCount):
arrCrvPts = []
indexClosestAtt = rs.PointArrayClosestPoint(AttractorPtsList,arrCrvDiv[k])
attPt = AttractorPtsList[indexClosestAtt]
dist2 = rs.Distance(attPt,arrCrvDiv[k])
vecToAttr = [0,0,0]
if dist2 < attPtThresh :
#NewPosition = attPt
vecToAttr = rs.VectorCreate(attPt, arrCrvDiv[k])
vecToAttr = rs.VectorUnitize(vecToAttr)
vecToAttr = rs.VectorScale(vecToAttr,dblRatio*attractorMag)
count = 0
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 = “,IndClosestCr
crvPt = arrCrvPts[IndClosestCrv]
#print crvPt
dist = rs.Distance(arrCrvDiv[k],crvPt)
vector = [0,0,0]
if dist < Attract :
vector = rs.VectorCreate(crvPt,arrCrvDiv[k])
vector = rs.VectorScale(vector,dblRatio)
NewPosition = rs.VectorAdd(vector,arrCrvDiv[k])
NewPosition = rs.VectorAdd(vecToAttr,NewPosition)
arrNewPos.append(NewPosition)
newcurve = rs.AddCurve(arrNewPos,Rebuild)
rs.DeleteObject(Curves[j])
#rs.ObjectColor(newcurve,[j,j,j])
Curves[j] = newcurve
Main()