# [B]io Mess

### Gallery details

Dynamics + Python Research V.1 [07.June.2011] – via Dynamics + Python [12.July.2011]
Research and Development by Luis Quinones and Tom Wiscombe @ Emergent Architecture [thanks to Roland Snooks for the pull to mesh rs code]
“””A Series of Different Scripts which create Minimal Pathways between a set of curves. 3 Versions
A. Attraction Based on Distance Threshold between Each Curve Point
B. Same as A + Point Attractors which have their own influence
C. Same as A + B + Pull to Closest Mesh + Uses Mesh Vertex Color Information To Determine a threshold multiplier based on Luminance
Values of the closest Point on The Mesh”””

C. Full Bundling + Mesh Vertex Color Information + AttractorPoints + Pull 2 Mesh

### FULL PYTHON CODE

```"""
Script written by <Luis Quinones>
"""
import rhinoscriptsyntax as rs
import math
from System.Drawing import Color

def PointList(outputSelfORG,arrRebuildCount):
arrCrvPts = []
for i in range(len(outputSelfORG)):
rebuild = rs.RebuildCurve(outputSelfORG[i],2,arrRebuildCount)
arrCrvPtCount = rs.CurvePointCount(outputSelfORG[i])
samPoints = rs.CurvePoints(outputSelfORG[i])
for j in range(0,arrCrvPtCount):
arrCrvPts.append(samPoints[j])
return arrCrvPts
def MainSelfORG(Gens,Curves,Rebuild,arrRebuildCount,WELDACTION,MeshAction,dblRatio,Attract,AttractorPtsList,attPtThresh,dblRatioATT,strLayerNew,strObject,AttractorPoints):
if bool(MeshAction[1]) == True:
arrItems2 = [("Attraction Threshold",True),("Vector Move Scale Factor",False), ("Paint Affects Both",False), ("Rebuild_CURVES",False)]
arrOptionsBln2 = rs.CheckListBox(arrItems2,"CHOOSE","Paint_Influence")
if not arrOptionsBln2:
print "Options not array"
AttractorThreshold = arrOptionsBln2[0]
VectorTranslationScaling = arrOptionsBln2[1]
DoubleActionPaint = arrOptionsBln2[2]
CRVBUILD = arrOptionsBln2[3]
arrVerts = rs.MeshVertices(strObject)
color = rs.MeshVertexColors(strObject)
for x in range(len(Curves)):
rs.RebuildCurve(Curves[x],Rebuild,arrRebuildCount)
count = 0
for i in range(Gens):
arrTOPCRVS = []
arrBOTTCRVS = []
for j in range(len(Curves)):
arrNewPos = []
PointCount = rs.CurvePointCount(Curves[j])
arrCrvDivMain = rs.CurvePoints(Curves[j])
if bool(WELDACTION[1]) == True:
PointCount = PointCount - 2
arrCrvDiv = arrCrvDivMain[1:-1]
else:
arrCrvDiv = arrCrvDivMain
arrCrvStartPt = rs.CurveStartPoint(Curves[j])
arrCrvEndPt = rs.CurveEndPoint(Curves[j])
for k in range(PointCount):

arrCrvPts = []
if bool(MeshAction[1]) == True:
threshMult = ColorAction(arrVerts,color,arrCrvDiv[k])
if threshMult == 0 :
threshMult == 0 + 0.01
else:
threshMult = 1
if bool(MeshAction[1]) == True:
if bool(VectorTranslationScaling[1]) == True:
dblRatio2 = dblRatio*threshMult
newThreshold = Attract
if bool(MeshAction[1]) == True:
if bool(DoubleActionPaint[1]) == True:
dblRatio2 = dblRatio*threshMult
newThreshold = Attract * threshMult
if bool(AttractorPoints[1]) == True:
if not AttractorPtsList:
print "really"
indexClosestAtt = rs.PointArrayClosestPoint(AttractorPtsList,arrCrvDiv[k])
if not indexClosestAtt:
bambam = 0
attPt = AttractorPtsList[indexClosestAtt]
dist2 = rs.Distance(attPt,arrCrvDiv[k])
else:
dist2 = 1000000
if dist2 < attPtThresh :
attvector = rs.VectorCreate(attPt,arrCrvDiv[k])
attvector = rs.VectorScale(attvector,dblRatioATT)
else:
for L in range(len(Curves)):
if bool(MeshAction[1]) == True and bool(AttractorThreshold[1]) == True:
newThreshold = Attract * threshMult
dblRatio2 = dblRatio
else:
newThreshold = Attract
dblRatio2 = dblRatio
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])
crvPt = arrCrvPts[IndClosestCrv]
dist = rs.Distance(arrCrvDiv[k],crvPt)
if dist < newThreshold :
vector = rs.VectorCreate(crvPt,arrCrvDiv[k])
vector = rs.VectorScale(vector,dblRatio2)
else:
NewPosition = arrCrvDiv[k]
arrNewPos.append(NewPosition)
if bool(WELDACTION[1]) == True:
arrNewPos.insert(0,arrCrvStartPt)
arrNewPos.insert(PointCount+1,arrCrvEndPt)
rs.ObjectLayer(newcurve,strLayerNew)
rs.DeleteObject(Curves[j])
Curves[j] = newcurve
return Curves
def PullAction(srfArr,crvArr,threshold,snapThreshold,ratio):
for i in range(len(crvArr)):
arrSrfPts = []
rs.EnableObjectGrips(crvArr[i],enable = True)
gripCount = rs.ObjectGripCount(crvArr[i])
for j in range(gripCount):
gripPos = rs.ObjectGripLocation(crvArr[i],j)
count = 0
for k in range(len(srfArr)):
if rs.IsMesh(srfArr[k]):
meshPt = rs.MeshClosestPoint(srfArr[k],gripPos)
srfPt = meshPt[0]
else:
srfUV = rs.SurfaceClosestPoint(srfArr[k],gripPos)
srfPt = rs.EvaluateSurface(srfArr[k],srfUV)
arrSrfPts.append(srfPt)
count += 1
closeSrfInd = rs.PointArrayClosestPoint(arrSrfPts,gripPos)
srfPt = arrSrfPts[closeSrfInd]
dist3 = rs.Distance(gripPos,srfPt)
if dist3 < threshold :
vec = rs.VectorCreate(srfPt,gripPos)
if dist3 > snapThreshold :
vec = rs.VectorScale(vec,ratio)
rs.ObjectGripLocation(crvArr[i],j,newPos2)
def ColorAction(arrVerts,color,pos):
index = rs.PointArrayClosestPoint(arrVerts,pos)
result = color[index]
colorR = rs.ColorRedValue(result)
lum = colorR/255
return lum
def Main():
rs.MessageBox("SelfOrganizing Network_Built in Options for Attractors or Mesh Paint Attraction",0,"BUNDLING ACTION")
arrItems = [("Attractor Points?",False),("Use Mesh Vertex Colors as Driver?",True),("Weld Start & End Points?",True),("Pull Geo?",True)]
arrOptionsBln = rs.CheckListBox(arrItems,"CHOOSE","Attraction_Type")
AttractorPoints = arrOptionsBln[0]
MeshAction = arrOptionsBln[1]
WELDACTION = arrOptionsBln[2]
pullGeom = arrOptionsBln[3]
if not arrOptionsBln:
print "Options not array"
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#INPUTS
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////
Gens = rs.GetInteger("Number of Generations",2,2,14)
Curves = rs.GetObjects("Select Base Crvs",rs.filter.curve)
textLocPt = rs.GetPoint("Pick location to create settings text")
Attract = rs.GetReal("CurvePointAttractionThreshold", 150)
dblRatio = rs.GetReal("Distance For Vector To Move", 0.75)
arrRebuildCount = rs.GetInteger("Curve Rebuild CP Count", 40)
Rebuild = rs.GetInteger("Degree To Rebuild Curves", 2)
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////
if bool(pullGeom[1]) == True :
srfArr = rs.GetObjects("Meshes to pull to",0)
pullthreshold = 150
snapThreshold = 90
ratio = 1
if bool(MeshAction[1]) == True :
strObject = rs.GetObject("ColorMesh",filter = 32,select = False)
else:
strObject = 0
if bool(AttractorPoints[1]) == False:
attPtThresh = 0
dblRatioATT = 0
AttractorPtsList = []
else:
AttractorPts = rs.GetObjects("Attractor Points",rs.filter.point)
attPtThresh = rs.GetReal("AttractorPointThreshold", 40)
dblRatioATT = rs.GetReal("JUMP For Vector Towards ATTPT MOVE", .25)
AttractorPtsList = []
for z in range(len(AttractorPts)):
AttractorPtsList.append(rs.PointCoordinates(AttractorPts[z]))
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#TEXT OUTPUT VARIABLES
#//////////////////////////////////////////////////////////////////////////////////////////////////////////////
text = rs.AddText( " Gens = "+str(Gens)+ " AttTHRESH = " + str(Attract) + " PTTHRESH = " + str(attPtThresh) +
" VECTORMOVE = " + str(dblRatio) + " ATTPT VECTOR JUMP = " + str(dblRatioATT), textLocPt, height = 2, justification = 2)
outputSelfORG = MainSelfORG(Gens,Curves,Rebuild,arrRebuildCount,WELDACTION,MeshAction,dblRatio,Attract,AttractorPtsList,attPtThresh,dblRatioATT,strLayerNew,strObject,AttractorPoints)
if bool(pullGeom[1]) == True:
PullAction(srfArr,outputSelfORG,pullthreshold,snapThreshold,ratio)
Main()   ```
C. Bundling + Mesh Vertex Color Information + AttractorPoints + Pull 2 Mesh

### PYTHON CODE

```"""
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
from System.Drawing import Color

def PullAction(srfArr,crvArr,threshold,snapThreshold,ratio):

for i in range(len(crvArr)):

arrSrfPts = []
rs.EnableObjectGrips(crvArr[i],enable = True)
gripCount = rs.ObjectGripCount(crvArr[i])

for j in range(gripCount-1):

gripPos = rs.ObjectGripLocation(crvArr[i],j)
count = 0

for k in range(len(srfArr)):

if rs.IsMesh(srfArr[k]):
meshPt = rs.MeshClosestPoint(srfArr[k],gripPos)
srfPt = meshPt[0]

else:

srfUV = rs.SurfaceClosestPoint(srfArr[k],gripPos)
srfPt = rs.EvaluateSurface(srfArr[k],srfUV)
arrSrfPts.append(srfPt)
count += 1

closeSrfInd = rs.PointArrayClosestPoint(arrSrfPts,gripPos)
srfPt = arrSrfPts[closeSrfInd]
dist3 = rs.Distance(gripPos,srfPt)

if dist3 < threshold :
vec = rs.VectorCreate(srfPt,gripPos)
if dist3 > snapThreshold :
vec = rs.VectorScale(vec,ratio)
rs.ObjectGripLocation(crvArr[i],j,newPos2)

def ColorAction(centroid,gripPos,ave):
index = rs.PointArrayClosestPoint(centroid,gripPos)
closestTest = centroid[index]
result = ave[index]
#print result
return result

def Main():

rs.MessageBox("SelfOrganizing Network_Built in Options for Attractors or Mesh Paint Attraction",0,"BUNDLING ACTION")
arrItems = [("AttractorPoints",False),("Want Some Mesh Action",False),("Wanna Pull It to Something",False)]
#arrDefaults = [False,False,False]
arrOptionsBln = rs.CheckListBox(arrItems,"CHOOSE","Attraction_Type")
if not arrOptionsBln:
print "Options not array"
AttractorPoints = arrOptionsBln[0]
print AttractorPoints[1]
MeshAction = arrOptionsBln[1]
print MeshAction
pullGeom = arrOptionsBln[2]
print pullGeom

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")

if bool(pullGeom[1]) == True :
srfArr = rs.GetObjects("Meshes to pull to",0)
pullthreshold = rs.GetReal("Set Thresh for mesh attractor")
snapThreshold = rs.GetReal("Set Snap Threshold")
ratio = rs.GetReal("Ratio of Distance to move")
if bool(MeshAction[1]) == True :
strObject = rs.GetObject("ColorMesh",filter = 32,select = False)

if bool(AttractorPoints[1]) == False:
print "ATTRACTOR False"
attPtThresh = 0
else:

print "ATTRACTOR True"

if bool(MeshAction[1]) == True:
arrFaces = rs.MeshFaces(strObject,True)
color = rs.MeshVertexColors(strObject)
faceVerts = [0]
centroid = []
ave = []
if arrFaces:
i = 0
count2 = 0
while(i < len(arrFaces)):

arrFace = arrFaces[i],arrFaces[i+1],arrFaces[i+2],arrFaces[i+3]
if arrFace[2][0] == arrFace[3][0] and arrFace[2][1] == arrFace[3][1] and arrFace[2][2] == arrFace[3][2] :

arrHLS = rs.ColorRGBToHLS(color[count2]),rs.ColorRGBToHLS(color[count2+1]),rs.ColorRGBToHLS(color[count2+2]),rs.ColorRGBToHLS(color[count2+2])
sum = arrHLS[0][2] + arrHLS[1][2] + arrHLS[2][2]
ave2 = (sum/3)
if ave2 < 0.2:
ave2 = 0
ave.append(ave2)
faceVerts[0] = [0,1,2,2]
meshVerts = arrFace
if mesh :
centroid.append(rs.MeshAreaCentroid(mesh))
else:
print "did not make mesh"
rs.DeleteObject(mesh)
count2 += 3

else:
arrHLS = rs.ColorRGBToHLS(color[count2]),rs.ColorRGBToHLS(color[count2+1]),rs.ColorRGBToHLS(color[count2+2]),rs.ColorRGBToHLS(color[count2+3])
sum = arrHLS[0][2] + arrHLS[1][2] + arrHLS[2][2] + arrHLS[3][2]
ave2 = (sum/4)

if ave2 < 0.2:
ave2 = 0
ave.append(ave2)
faceVerts[0] = [0,1,2,3]
meshVerts = arrFace
if mesh:
centroid.append(rs.MeshAreaCentroid(mesh))
else:
print "did not make mesh"
rs.DeleteObject(mesh)
count2 += 4
i +=4
if len(centroid) != len(ave):
print "# of aves does != # of points"

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 bool(MeshAction[1]) == True:
threshMult = ColorAction(centroid,arrCrvDiv[k],ave)
if threshMult == 0 :
threshMult == 0 + 0.01
else:
threshMult = 1
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)):
newThreshold = Attract * threshMult
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 < newThreshold :
vector = rs.VectorCreate(crvPt,arrCrvDiv[k])
vector = rs.VectorScale(vector,dblRatio)
else:
NewPosition = arrCrvDiv[k]
arrNewPos.append(NewPosition)
rs.ObjectLayer(newcurve,strLayerNew)
rs.DeleteObject(Curves[j])
#rs.ObjectColor(newcurve,[j,j,j])
Curves[j] = newcurve
basecrvs = rs.ObjectsByLayer(strLayerNew)
if bool(pullGeom[1]) == True:
PullAction(srfArr,basecrvs,pullthreshold,snapThreshold,ratio)
Main()
Update
```
A . Bundling SOLO

### PYTHON CODE

```"""
Script written by Luis Quinones
www.luisquinonesdesign.com
www.computationalmatter.com
Script version Monday, 21 March 2011 20:18:46
"""
"""each grip point checks its position on the mesh
find the corresponding color value that is closest to it
that color value 0-1 determines the multiplier for the threshold"""

import rhinoscriptsyntax as rs
from System.Drawing import Color

def Main():
crvArr = rs.GetObjects("Crvs",filter = 4)
gens = rs.GetInteger("Generations",4)
threshold = rs.GetReal("AttractionThreshold",80)
for i in range(gens):
for j in range(len(crvArr)):
rs.EnableObjectGrips(crvArr[j],enable = True)
gripCount = rs.ObjectGripCount(crvArr[j])
for k in range(gripCount-1):
gripPos = rs.ObjectGripLocation(crvArr[j],k)
count = 0
for m in range(len(crvArr)):
crvParam = rs.CurveClosestPoint(crvArr[m],gripPos)
crvPt = rs.EvaluateCurve(crvArr[m],crvParam)
dist = rs.Distance(crvPt,gripPos)
#print newThreshold
if dist < threshold and j != m :
if count == 0:
closestDist = dist
closestVec = rs.VectorCreate(crvPt,gripPos)
count += 1
else:
if dist < closestDist:
closestDist = dist
closestVec = rs.VectorCreate(crvPt,gripPos)
#closestVec = rs.VectorScale(closestVec,threshMult)
count += 1
if count == 0:
closestVec = 0,0,0
rs.ObjectGripLocation(crvArr[j],k,newPos)
rs.EnableObjectGrips(crvArr[j],False)
Main()
Update
```
B . Bundling + AttractorPoints

### PYTHON CODE

```"""
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)
else:
NewPosition = arrCrvDiv[k]
arrNewPos.append(NewPosition)