<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>algorithmic design</title>
	<link>http://code.algorithmicdesign.net</link>
	<description>algorithmic design</description>
	<pubDate>Tue, 07 Feb 2012 18:09:18 +0000</pubDate>
	<generator>http://code.algorithmicdesign.net</generator>
	<language>en</language>
	
		
	<item>
		<title>woolNet</title>
				
		<link>http://code.algorithmicdesign.net/woolNet</link>

		<comments>http://code.algorithmicdesign.net/following/code.algorithmicdesign.net/woolNet</comments>

		<pubDate>Tue, 07 Feb 2012 18:09:18 +0000</pubDate>

		<dc:creator>algorithmic design</dc:creator>
		
		<category><![CDATA[python, grasshopper, projects, encodedmatter]]></category>

		<guid isPermaLink="false">2762337</guid>

		<description>&#60;img src="http://payload23.cargocollective.com/1/0/9123/2762337/project_title_img_1000.jpg" width="1000" height="400" width_o="1000" height_o="400" src_o="http://payload23.cargocollective.com/1/0/9123/2762337/project_title_img_o.jpg" data-mid="14015393"  border="0" align="left"/&#62;descriptionSelf-organized systems are alwyas part of nature. This system is one of the most efficient structures. Moreover they bring natural patterns in design fields. They can be basically defined with the process of self-organization where a structure or pattern appears in a system without a central authority or external element imposing it through planning.

This is an experiment with curves which were designed and then subjected to attraction by some points-as-attractors. Curves were affected not only by each other but also by points. Increasing and decreasing some adjustments such as maximum number of points, minimum or maximum attraction radius gave us a variety of self-organized results, structures and patterns.

Based on this system we designed a model which indicates this structure and would adapt to the environment of the Wates House. Firstly, we created a bunch of curves. These lines shape the structure. Moreover each component has its own character which is non-linear. Therefore combining them will give us a group of chaotic mass together with ordered behavior.

For more information &#38; the code behind the work visit this tutorial

design team : Fatemeh Khatami, Pegah Jalaly, Pinar Calisir, Secil Zontur
ENCODED MATTER, BARTLETT 2012
Instructor: Ezio Blasetti

boards&#60;img src="http://payload23.cargocollective.com/1/0/9123/2762337/woolNet_1_thumb.jpg" width="200" height="282" width_o="200" height_o="282" src_o="http://payload23.cargocollective.com/1/0/9123/2762337/woolNet_1_thumb_o.jpg" data-mid="14014929"  border="0" align="left"/&#62;&#60;img src="http://payload23.cargocollective.com/1/0/9123/2762337/woolNet_2_thumb.jpg" width="200" height="282" width_o="200" height_o="282" src_o="http://payload23.cargocollective.com/1/0/9123/2762337/woolNet_2_thumb_o.jpg" data-mid="14014940"  border="0" align="left"/&#62;&#60;img src="http://payload23.cargocollective.com/1/0/9123/2762337/woolNet_3_thumb.jpg" width="200" height="283" width_o="200" height_o="283" src_o="http://payload23.cargocollective.com/1/0/9123/2762337/woolNet_3_thumb_o.jpg" data-mid="14014950"  border="0" align="left"/&#62;&#60;img src="http://payload23.cargocollective.com/1/0/9123/2762337/woolNet_4_thumb.jpg" width="200" height="282" width_o="200" height_o="282" src_o="http://payload23.cargocollective.com/1/0/9123/2762337/woolNet_4_thumb_o.jpg" data-mid="14014955"  border="0" align="left"/&#62;</description>
		
		<excerpt></excerpt>

		<!--<wfw:commentRss></wfw:commentRss>-->

		<media:thumbnail url="http://payload23.cargocollective.com/1/0/9123/2762337/prt_1328638151.jpg" />

	</item>
		
		
	<item>
		<title>MultiState 1d Cellular Automata</title>
				
		<link>http://code.algorithmicdesign.net/MultiState-1d-Cellular-Automata</link>

		<comments>http://code.algorithmicdesign.net/following/code.algorithmicdesign.net/MultiState-1d-Cellular-Automata</comments>

		<pubDate>Tue, 07 Feb 2012 13:37:02 +0000</pubDate>

		<dc:creator>algorithmic design</dc:creator>
		
		<category><![CDATA[rhinoscript]]></category>

		<guid isPermaLink="false">900991</guid>

		<description>&#60;img src="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_1_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_1_o.jpg" data-mid="4610491"  border="0" align="left"/&#62;&#60;img src="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_2_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_2_o.jpg" data-mid="4610492"  border="0" align="left"/&#62;&#60;img src="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_3_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_3_o.jpg" data-mid="4610493"  border="0" align="left"/&#62;&#60;img src="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_4_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_4_o.jpg" data-mid="4610495"  border="0" align="left"/&#62;&#60;img src="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_5_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_5_o.jpg" data-mid="4610497"  border="0" align="left"/&#62;&#60;img src="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_6_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_6_o.jpg" data-mid="4610499"  border="0" align="left"/&#62;&#60;img src="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_7_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_7_o.jpg" data-mid="4610501"  border="0" align="left"/&#62;&#60;img src="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_8_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/900991/CellularAutomataHead_8_o.jpg" data-mid="4610502"  border="0" align="left"/&#62;
Multistate Cellular AutomataOption Explicit
'Script written by Ezio Blasetti
'Script copyrighted by algorithmicdesign.net

Call Main()
Sub Main()
	Dim arrNewObjs : arrNewObjs = array("Nothing")
	
	Dim intGenerations : intGenerations = Rhino.GetSettings(Rhino.InstallFolder &#38; "MultiStateCA.ini", "ca", "Generations")
	If IsNull(intGenerations)  Then intGenerations  = 100     Else intGenerations  = CInt (intGenerations)
	Dim intLength	   : intLength      = Rhino.GetSettings(Rhino.InstallFolder &#38; "MultiStateCA.ini", "ca", "Length")
	If IsNull(intLength)       Then intLength       = 100     Else intLength       = CInt (intLength)
	Dim intStates	   : intStates      = Rhino.GetSettings(Rhino.InstallFolder &#38; "MultiStateCA.ini", "ca", "States")
	If IsNull(intStates)       Then intStates       = 3       Else intStates       = CInt (intStates)	
	Dim intNeighbors   : intNeighbors   = Rhino.GetSettings(Rhino.InstallFolder &#38; "MultiStateCA.ini", "ca", "Neighbors")
	If IsNull(intNeighbors)    Then intNeighbors    = 3       Else intNeighbors    = CInt (intNeighbors)
	Dim dblLambda      : dblLambda      = Rhino.GetSettings(Rhino.InstallFolder &#38; "MultiStateCA.ini", "ca", "Lambda")
	If IsNull(dblLambda)       Then dblLambda       = .3      Else dblLambda       = CDbl (dblLambda)

	Dim arrRules, strResult, arrOpenRules, arrOptions(11), strFile, blnChangeRules : blnChangeRules = VbTrue
	Dim strG : strG = MakeRandomString(intLength, intStates)
	Do
		Rhino.EnableRedraw vbFalse
		Rhino.DeleteObjects arrNewObjs
		If blnChangeRules Then arrRules = makeRules(intStates, intNeighbors,dblLambda)
		rhino.Print "computing...please wait."
		arrNewObjs = ComputeAndArray(intGenerations, intLength, intStates, intNeighbors, dblLambda, arrRules, strG)
		Call fixColorsOfLayers(intStates)
		If IsNull(arrNewObjs) Then arrNewObjs = Array("Nothing")
		Rhino.EnableRedraw vbTrue
		rhino.Print "done."

		arrOptions(0)  = "Generations_" &#38; CStr(Int(intGenerations))  
		arrOptions(1)  = "Length_"      &#38; CStr(Int(intLength))
		arrOptions(2)  = "States_"      &#38; CStr(Int(intStates))
		arrOptions(3)  = "Neighbors_"   &#38; CStr(Int(intNeighbors))
		arrOptions(4)  = "Lambda_"      &#38; CStr(Int(dblLambda*10))
		arrOptions(5)  = "New"
		arrOptions(6)  = "RandomString"
		arrOptions(7)  = "SingleDot"
		arrOptions(8)  = "Open"
		arrOptions(9)  = "Save"
		arrOptions(10) = "Accept"
		arrOptions(11) = "Quit"
		strResult = Rhino.GetString("MultiStateCA; Current Lambda Is: (" &#38; dblLambda &#38; ")", "Accept", arrOptions)
		If IsNull(strResult) Then strResult = "Quit"
		If IsNumeric(strResult) Then
			dblLambda = Abs(CDbl(strResult))
		Else
			Select Case UCase(Left(strResult, 3))
				Case "GEN"
					strResult = Rhino.GetInteger("Specify the number of generations", intGenerations, 5)
					If Not IsNull(strResult) Then intGenerations = CInt(strResult)
				Case "LEN"
					strResult = Rhino.GetInteger("Specify length of the initial string", intLength, 10)
					If Not IsNull(strResult) Then intLength      = CInt(strResult)
					strG = MakeRandomString(intLength, intStates)
				Case "STA"
					strResult = Rhino.GetInteger("Specify the number of states", intStates, 2)
					If Not IsNull(strResult) Then intStates      = CInt(strResult)
					strG = MakeRandomString(intLength, intStates)
					blnChangeRules = VbTrue
				Case "NEI"
					strResult = Rhino.GetInteger("Specify the number of neighbors", intNeighbors, 2)
					If Not IsNull(strResult) Then intNeighbors   = CInt(strResult)
					blnChangeRules = VbTrue
				Case "LAM"
					strResult = Rhino.GetReal("Specify the Lambda parameter", dblLambda, 0,1)
					If Not IsNull(strResult) Then dblLambda   	 = CDbl(strResult)
					blnChangeRules = VbTrue
				Case "NEW"
					blnChangeRules = VbTrue
				Case "RAN"
					strG = MakeRandomString(intLength, intStates)
					blnChangeRules = VbFalse
				Case "SIN"
					strG = MakeString(intLength, intStates)
					blnChangeRules = VbFalse
				Case "OPE"
					strFile      = Rhino.OpenFileName ("Open", "Cellular Automata Rules (*.ca)&#124;*.ca&#124;&#124;")
					If Not IsNull(strFile) Then 
						arrOpenRules = OpenRules(strFile)
						intStates    = arrOpenRules(0)
						intNeighbors = arrOpenRules(1)
						dblLambda    = arrOpenRules(2)
						arrRules     = array(arrOpenRules(3), arrOpenRules(4))
						blnChangeRules = VbFalse
					End If
				Case "SAV"
					strFile      = Rhino.SaveFileName ("Save", "Cellular Automata Rules (*.ca)&#124;*.ca&#124;&#124;")
					Call SaveRules(intStates, dblLambda, arrRules, strFile)
				Case "ACC"
					Rhino.EnableRedraw vbFalse
					Rhino.DeleteObjects arrNewObjs
					rhino.Print "calculating...please wait."
					arrNewObjs = ComputeAndArray(intGenerations, intLength, intStates, intNeighbors, dblLambda, arrRules, strG)
					Rhino.EnableRedraw vbTrue
					Exit Do
				Case "QUI"
					Rhino.DeleteObjects arrNewObjs
					Exit Sub
			End Select
		End If
		rhino.command "clearundo "
	Loop
	
	Rhino.SaveSettings Rhino.InstallFolder &#38; "MultistateCA.ini", "ca", "Generations", CStr(intGenerations)
	Rhino.SaveSettings Rhino.InstallFolder &#38; "MultistateCA.ini", "ca", "Length"     , CStr(intLength     )
	Rhino.SaveSettings Rhino.InstallFolder &#38; "MultistateCA.ini", "ca", "States"     , CStr(intStates     )
	Rhino.SaveSettings Rhino.InstallFolder &#38; "MultistateCA.ini", "ca", "Neighbors"  , CStr(intNeighbors  )
	Rhino.SaveSettings Rhino.InstallFolder &#38; "MultistateCA.ini", "ca", "Lambda"     , CStr(dblLambda     )
	
	'Dim arrRules : arrRules = makeRules(5, 3,.2)
	'Dim strFile  : strFile = Rhino.SaveFileName ("Save", "Cellular Automata Rules (*.ca)&#124;*.ca&#124;&#124;")
	'Call SaveRules(intStates, dblLambda, arrRules, strFile)
	
	'Call ComputeAndArray(30, 30, 5, 3,.2, arrRules)
End Sub

Function ComputeAndArray(intGenerations, intLength, intStates, intNeighbors, dblLambda, arrRules, strG)
	ComputeAndArray = Null
	If Not IsNumeric(intGenerations) Then Exit Function
	Dim arrComputedCA()
	Dim i, strChar, k
	k=0
	Call addLayers4States(intStates)
	For i=intGenerations-1 To 0 Step -1
		rhino.EnableRedraw vbFalse
		Dim arrTokens : arrTokens = Rhino.Strtok (strG, ",")
		Dim j : j=0
		For Each strChar In arrTokens
			ReDim Preserve arrComputedCA(k)
			'arrComputedCA(k) = rhino.addpoint   (array(i,j,0))
			'arrComputedCA(k) = Rhino.AddTextDot (strChar, array(i,j,0))
			'arrComputedCA(k) = Rhino.AddSrfPt   (array(array((j-0.5),(i-0.5),0),array((j-0.5),(i+0.5),0),array((j+0.5),(i+0.5),0),array((j+0.5),(i-0.5),0)))
			arrComputedCA(k) = addMeshQuad(array(array((j-0.5),(i-0.5),0),array((j-0.5),(i+0.5),0),array((j+0.5),(i+0.5),0),array((j+0.5),(i-0.5),0)))
			Call Rhino.ObjectLayer (arrComputedCA(k), strChar)
			j=j+1
			k=k+1
		Next
		rhino.EnableRedraw vbTrue
		strG = NextGeneration (strG, arrRules, intNeighbors)
	Next
	ComputeAndArray = arrComputedCA
End Function

Function MakeRandomString(intLength, intStates)
	MakeRandomString = Null
	Dim strReturn : strReturn = ""
	Dim i
	For i=0 To intLength
		strReturn = strReturn &#38; "," &#38; CStr(Round((rnd)*(intStates)-0.5))
	Next
	MakeRandomString = strReturn
End Function

Function MakeString(intHowLong, intStates)
	MakeString = Null
	If Not IsNumeric(intHowLong) Then Exit Function
	Dim str, i
	str = ""
	For i=0 To intHowLong
		If i(intHowLong/2) Then
			str = str &#38; "," &#38; "0"
		Else
			str = str &#38; "," &#38; CStr(intStates-1)
		End If
	Next
	MakeString = str
End Function

Function NextGeneration (strGen, arrRules, intNeighbors)
	NextGeneration = Null
	If IsNull(strGen) Then Exit Function
	
	Dim arrInputs  : arrInputs  = arrRules(0)
	Dim arrOutputs : arrOutputs = arrRules(1)
	'Dim intNeighbors : intNeighbors = Ubound(arrInputs(0))
	Dim arrTokens, strCharacter, strPrevChar, strNextChar, strNextGen
         
	strNextGen = ""

	arrTokens = Rhino.Strtok (strGen, ",")
	
	Dim i : i = 0
	For Each strCharacter In arrTokens
		Dim strTest : strTest = ""
		Dim j
		For j=0 To intNeighbors-1
			'here dont try to understand
			If i-Int(intNeighbors/2)+j &#60; 0 Then
				strTest = strTest + arrTokens(Ubound(arrTokens) + i-Int(intNeighbors/2)+j + 1)
			ElseIf i-Int(intNeighbors/2)+j &#62; Ubound(arrTokens) Then
				strTest = strTest + arrTokens(i-Int(intNeighbors/2)+j - Ubound(arrTokens) - 1)
			Else
				strTest = strTest + arrTokens(i-Int(intNeighbors/2)+j)
			End If
		Next
		For j=0 To Ubound(arrInputs)
			Dim arrInput  : arrInput  = arrInputs(j)
			Dim k, strRule : strRule = ""
			For k=0 To Ubound(arrInput)
				strRule = strRule &#38; CStr(arrInput(k))
			Next
			'print strTest &#38; "=" &#38;  strRule
			If strTest = strRule Then
				strNextGen = strNextGen &#38; "," &#38; arrOutputs(j)
			End If
		Next
		i=i+1
	Next
	NextGeneration = strNextGen
End Function

Sub addLayers4States(intStates)
	Dim i
	For i=0 To intStates-1
		Dim strLayer : strLayer = Rhino.AddLayer(i, rgb(255-(i*255/(intStates-1)),255-(i*255/(intStates-1)),255-(i*255/(intStates-1))))
		If Not IsNull(strLayer) Then
			Dim intMaterialIndex : intMaterialIndex = Rhino.AddMaterialToLayer (strLayer)
			Call Rhino.MaterialColor (intMaterialIndex , rgb(255-(i*255/(intStates-1)),255-(i*255/(intStates-1)),255-(i*255/(intStates-1))))
		End If
	Next
End Sub

Sub fixColorsOfLayers(intStates)
	Dim i
	For i=0 To intStates-1
		Call Rhino.LayerColor (i, rgb(255-(i*255/(intStates-1)),255-(i*255/(intStates-1)),255-(i*255/(intStates-1))))
		Dim intMaterialIndex : intMaterialIndex = Rhino.AddMaterialToLayer (i)
		Call Rhino.MaterialColor (intMaterialIndex , rgb(255-(i*255/(intStates-1)),255-(i*255/(intStates-1)),255-(i*255/(intStates-1))))
	Next
End Sub


Function MakeRules(intStates, intNeighbors, dblLambda)
	
	Dim arrInputs  : arrInputs  = MakeRuleInput (intStates, intNeighbors)
	Dim arrOutputs : arrOutputs = MakeRuleOutput(intStates, intNeighbors, dblLambda)
	MakeRules = array(arrInputs, arrOutputs)
End Function

Function MakeRuleInput(intStates, intNeighbors)
	
	Dim Max : Max = intStates^intNeighbors-1
	ReDim arrReturn(Max)
	Dim i,j
	For i=0 To Max
		Dim count : count = 0
		ReDim arrTemp(intNeighbors-1)
		For j=intNeighbors-1 To 0 Step -1
			'Next Line Is Business
			arrTemp(count)=Int(i/(intStates^j))Mod IntStates
			count = count+1
		Next
		arrReturn(Max-i)=arrTemp
		'Print arrReturn(Max-i)(0) &#38; " " &#38; arrReturn(Max-i)(1) &#38; " " &#38; arrReturn(Max-i)(2)
	Next
	MakeRuleInput = arrReturn
End Function

Function MakeRuleOutput(intStates, intNeighbors, dblLambda)
	Dim Max : Max = intStates^intNeighbors - 1
	ReDim arrReturn(Max)
	Dim i
	For i=0 To Max
		arrReturn(i) = Floor(rnd*intStates)
		If rnd &#60; dblLambda Then arrReturn(i) = 0
		'Print arrReturn(i)
	Next
	MakeRuleOutput = arrReturn
End Function

Function addMeshQuad(arrPoints)
	Dim arrFaceVertices(0)
	arrFaceVertices(0) = Array(0,1,2,3)
	addMeshQuad = Rhino.AddMesh (arrPoints, arrFaceVertices)
End Function

Sub SaveRules(intStates, dblLambda, arrRules, strFile)

	Dim arrInputs    : arrInputs    = arrRules(0)
	Dim arrOutputs   : arrOutputs   = arrRules(1)
	Dim intNeighbors : intNeighbors = Ubound(arrInputs(0))+1
	
	
	Call Rhino.SaveSettings (strFile, "Setup", "NumberOfStates"   , CStr(intStates)   )
	Call Rhino.SaveSettings (strFile, "Setup", "NumberOfNeighbors", CStr(intNeighbors))
	Call Rhino.SaveSettings (strFile, "Setup", "Lambda"           , CStr(dblLambda)   )
	
	Dim i
	For i=0 To Ubound(arrInputs)
		Dim arrInput    : arrInput = arrInputs(i)
		Dim j, strInput : strInput = ""
		For j=0 To Ubound(arrInput)
			If Not j=0 Then
				strInput = strInput &#38; "," &#38; arrInput(j)
			Else
				strInput = arrInput(j)
			End If
			print j
		Next
		Call Rhino.SaveSettings (strFile, "Rules", strInput, CStr(arrOutputs(i)))
	Next
	
End Sub

Function OpenRules(strFile)

	Dim intStates    : intStates    = CInt(Rhino.GetSettings (strFile, "Setup", "NumberOfStates"   ))
	Dim intNeighbors : intNeighbors = CInt(Rhino.GetSettings (strFile, "Setup", "NumberOfNeighbors"))
	Dim dblLambda    : dblLambda    = CDbl(Rhino.GetSettings (strFile, "Setup", "Lambda"           ))
	
	Dim arrSettings  : arrSettings  = Rhino.GetSettings (strFile, "Rules")   
	Dim arrInputs    : arrInputs    = arrSettings
	Dim arrOutputs   : arrOutputs   = arrSettings
	
	Dim i,j
	For i=0 To Ubound(arrSettings)
		'print arrSettings(i)
		Dim arrTokens : arrTokens = Rhino.Strtok (arrSettings(i), ",")
		Dim arrTemp   : arrTemp   = arrTokens
		For j=0 To Ubound(arrTokens)
			arrTemp(j) = CInt(arrTokens(j))
			'print arrTemp(j)
		Next
		arrInputs(i) = arrTemp
	Next
	
	For i=0 To Ubound(arrSettings)
		arrOutputs(i) = CInt(Rhino.GetSettings (strFile, "Rules", arrSettings(i)))
		'print arrOutputs(i)
	Next
	
	OpenRules = array(intStates, intNeighbors, dblLambda, arrInputs, arrOutputs)
	
End Function

Copy Objects To Meshes
Use this script to copy your components to the quad meshes created by the script above:
Option Explicit
Call Main()
Sub Main()
'ask the user to select the objectS to copy
     Dim arrObjects : arrObjects = Rhino.GetObjects("please select the objects to copy")
'get all the point OBJECTS from the layer "Points"
     Dim arrMeshes : arrMeshes = Rhino.ObjectsByLayer ("2")
 Call Rhino.EnableRedraw (False)
'loop through all the point objects
Dim i
For i=0 To Ubound(arrMeshes)
      'use the rhino.pointCoordinates method
      'to store the xyz of the current point OBJECT
      Dim arrEnd : arrEnd = Rhino.MeshAreaCentroid(arrMeshes(i))
      Dim arrStart : arrStart = array(0,0,0)
      'copy the objects from 0,0,0 to the current point (coordinates)
      Call Rhino.CopyObjects (arrObjects , arrStart , arrEnd)
'end the loop
Next
   Call Rhino.EnableRedraw (True)
End Sub</description>
		
		<excerpt></excerpt>

		<!--<wfw:commentRss></wfw:commentRss>-->

		<media:thumbnail url="http://payload.cargocollective.com/1/0/9123/900991/prt_1294135994.jpg" />

	</item>
		
		
	<item>
		<title>Recursive Subdivision Tiling</title>
				
		<link>http://code.algorithmicdesign.net/Recursive-Subdivision-Tiling</link>

		<comments>http://code.algorithmicdesign.net/following/code.algorithmicdesign.net/Recursive-Subdivision-Tiling</comments>

		<pubDate>Tue, 07 Feb 2012 13:36:54 +0000</pubDate>

		<dc:creator>algorithmic design</dc:creator>
		
		<category><![CDATA[rhinoscript]]></category>

		<guid isPermaLink="false">900961</guid>

		<description>&#60;img src="http://payload.cargocollective.com/1/0/9123/900961/RecursiveSubdivisionHead_00_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/900961/RecursiveSubdivisionHead_00_o.jpg" data-mid="4316747"  border="0" align="left"/&#62;
PseudoCodeRecursive Subdivision Tiling

' From Tilings Encyclopedia: In general, even restricted to mathematics, the term substitutioncan have several meanings. In connection with tilings, it describes a simple but powerful method to produce tilings with many interesting properties. The main idea is to use a finite set of building blocks {T1, T2 ... Tm} (the prototiles), an expanding linear map Q (the inflation factor) and a rule, how to dissect each scaled tile QTi into copies of the original prototiles T1, T2…Tm This information can be encoded in terms of parametrized tiles and affine maps (see example below), or, more appealing, in a diagram.

' This code will work for any subdivision tiling made of polylines with 1 ruleset of substitution.
' The code will need a geometric example of the tiling and some polylines to be applied to, as inputs.

' Define Main Subroutine
	' Get User Input:
	' Get the Number of Generations (integer, how many times to subdivide)
	' Get the Ruleset (array, one by one the identifiers of the polylines of the ruleset)
	' Get the Starting Tiles to Subdivide (array, the identifiers of the polylines we wish to subdivide) 

	' Subdivide the Starting Tiles:
	' Loop Through the Starting Tiles
	'	Call the Tile function (custom function, input: the number of generations, the ruleset as an array of polylines, the current starting tile)
	' End Loop
' End Main Subroutine

' This function takes a tile as a polyline and creates a number of new polylines - tiles inside it
' Define Custom Function Tile (3 inputs: the current generation as integer, the ruleset as an array of polylines, the tile to subdivide - the target)

	' If the current generation is greater than zero (count backwards) Then
	' 	Get the Array of Points from the basic tile of the ruleset (array, the coordinates of all the points of the base polyline of the ruleset)
	' 	Get an Array of Points from the target tile (array, the coordinates of all the points of the tile to subdivide)
	' 	Orient the tiles from the base polyline to the target and copy
	' 	Calculate the appropriate scale factor to apply to the new created tiles by dividing the distance between two coordinates in the basic tile of the ruleset and the corresponding ones of the target tile
	' 	Scale the new created tiles by the appropriate factor
	' 	Loop through each of the new created tiles
	' 			If + some condition (this will create differentiation in the overall pattern) Then
	'				Note: This is where the Tile Function Calls itself
	'				Call the Tile Function (custom function, input: the current generation minus one, the ruleset as an array of polylines, the current new tile)
	' 			End If
	' 	End Loop
	' End If
' End Tile Function


Recursive SphinxOption Explicit
'Script written by Roland Snooks
'Script copyrighted by kokkugia
Call Main()
Sub Main()
	' user input: gens, array with 5 tiles, array starting objs
	Dim intGens : intGens = Rhino.GetReal("how many generations", 6)
	Dim arrObjs(4)
	arrObjs(0) = Rhino.GetObject("select large tile", 4)
	arrObjs(1) = Rhino.GetObject("select small tile 1", 4)
	arrObjs(2) = Rhino.GetObject("select small tile 2", 4)
	arrObjs(3) = Rhino.GetObject("select small tile 3", 4)
	arrObjs(4) = Rhino.GetObject("select small tile 4", 4)
	
	Dim startObjs : startObjs = Rhino.GetObjects("select starting tiles to subdivide", 4)
	' loop through starting objs
	Dim i
	For i = 0 To UBound(startObjs)
		' call the tile function
		Call tile(arrObjs, intGens, startObjs(i))
	Next
End Sub

Function tile(arrObjs, intGens, targetObj)
	' if condition
	If intGens &#62; 0 Then
		' get arr of pts on base obj
		Dim arrBaseVtx : arrBaseVtx = Rhino.PolylineVertices(arrobjs(0))	
		' get arr of pts on target obj
		Dim arrTargetVtx : arrTargetVtx = Rhino.PolylineVertices(targetObj)
		' orient the objs
		Dim arrNewObjs : arrNewObjs = Rhino.OrientObjects(arrObjs, arrBaseVtx, arrTargetVtx, 1)
		' scale objs
		'd2/d1
		Dim dblScale : dblScale =  Rhino.Distance(arrTargetVtx(0), arrTargetVtx(1)) / Rhino.Distance(arrBaseVtx(0), arrBaseVtx(1))
		Call Rhino.ScaleObjects(arrNewObjs, arrTargetVtx(0), Array(dblScale, dblScale, dblScale))
		' call itself
		Dim i
		For i = 1 To Ubound(arrNewObjs)
			' loop through the number of small tiles
			If rnd &#62; 0.2 Then
				Call tile(arrObjs, intGens-1, arrNewObjs(i))
			End If	
		Next
	End If
End Function


Recursive Sphinx with 2 rulesOption Explicit
'Script written by Roland Snooks
'Script copyrighted by kokkugia

Call Main()
Sub Main()
	' user input: gens, array with 5 tiles, array starting objs
	Dim intGens : intGens = Rhino.GetReal("how many generations", 6)
	Dim nest1 : nest1 = Rhino.GetInteger("how many tiles in nest 1", 7)
	ReDim arrObjs1(nest1)
	For i = 0 To nest1
		arrObjs1(i) = Rhino.GetObject("select nest i tile" &#38; i, 4)
	Next 
	
	Dim nest2 : nest2 = Rhino.GetInteger("how many tiles in nest 2", 6)
	ReDim arrObjs2(nest2)
	For i = 0 To nest2
		arrObjs2(i) = Rhino.GetObject("select nest 2 tile" &#38; i, 4)
	Next 
	
	Dim startObjs : startObjs = Rhino.GetObjects("select starting tiles to subdivide", 4)
	' loop through starting objs
	Dim i
	For i = 0 To UBound(startObjs)
		' call the tile function
		Call tile(arrObjs1, arrObjs2, intGens, startObjs(i))
	Next
End Sub

Function tile(arrObjs1, arrObjs2, intGens, targetObj)
	Dim arrBaseVtx, arrNewObjs
	' if condition
	If intGens &#62; 0 Then
		' get arr of pts on target obj
		Dim arrTargetVtx : arrTargetVtx = Rhino.PolylineVertices(targetObj)
		
		' orient the objs
		' decide which tile next to use
		If Rhino.ObjectLayer(targetObj) = "nest1" Then
			' get arr of pts on base obj	
			arrBaseVtx = Rhino.PolylineVertices(arrobjs1(0))
			arrNewObjs = Rhino.OrientObjects(arrObjs1, arrBaseVtx, arrTargetVtx, 1)
		Else
			' get arr of pts on base obj	
			arrBaseVtx = Rhino.PolylineVertices(arrobjs2(0))
			arrNewObjs = Rhino.OrientObjects(arrObjs2, arrBaseVtx, arrTargetVtx, 1)	
		End if
		' scale objs
		'd2/d1
		Dim dblScale : dblScale =  Rhino.Distance(arrTargetVtx(0), arrTargetVtx(1)) / Rhino.Distance(arrBaseVtx(0), arrBaseVtx(1))
		Call Rhino.ScaleObjects(arrNewObjs, arrTargetVtx(0), Array(dblScale, dblScale, dblScale))
		'	Call Rhino.MoveObjects(arrNewObjs, array(0,0,0), array(0,0,intGens))
		' call itself
		Dim i
		For i = 1 To Ubound(arrNewObjs)
			' loop through the number of small tiles
			If rnd &#62; 0.2 Then
				Call tile(arrObjs1, arrObjs2, intGens-1, arrNewObjs(i))
			End If	
		Next
	End If
End Function
&#60;img src="http://payload.cargocollective.com/1/0/9123/900961/RecursiveSubdivisionHead_01_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/900961/RecursiveSubdivisionHead_01_o.jpg" data-mid="4316748"  border="0" align="left"/&#62;
Ammann Tiling Create
Option Explicit
'Script written by Ezio Blasetti
'Script copyrighted by algorithmicdesign.net

Call Main()
Sub Main()
	Dim n : n = Rhino.GetReal("please give the scale n for the tile (it can be negative too)", 0) 
	Dim strType : strType = Rhino.GetString("please type the type of tile you want", "A", array("A","B","C") )
	Call addAmmannA3(strType, n)
	'Dim phi : phi = (sqr(5)+1)/2 'f
	'Call rhino.addline (array(0,0,0), array(phi^(-1),0,0))
End Sub

Function addAmmannA3(strType, n)	
	Dim phi : phi = (sqr(5)+1)/2 'f
	Dim str
	If strType = "A" Then
		'                        f^n+1
		'                     5 _______4
		'                      &#124;       &#124;
		'                      &#124;       &#124;
		'                      &#124;       &#124; -----f^n+1
		'                      &#124;      3&#124;____2
		'                      &#124;          ^ &#124;
		'                f^n+3 &#124;        f^n &#124;
		'                      &#124;            &#124;
		'                      &#124;            &#124; f^n+2
		'                      &#124;            &#124;
		'                      &#124;____________&#124; 
		'                    0,6   f^n+2   1
		ReDim arrPoints(6)
		arrPoints(0) = array( 0,        0,        0)
		arrPoints(1) = array( phi^(n+2),0,        0)
		arrPoints(2) = array( phi^(n+2),phi^(n+2),0)
		arrPoints(3) = array( phi^(n+1),phi^(n+2),0)
		arrPoints(4) = array( phi^(n+1),phi^(n+3),0)
		arrPoints(5) = array( 0,        phi^(n+3),0)
		arrPoints(6) = array( 0,        0,        0)
		str = rhino.AddPolyline(arrPoints)
		Call Rhino.AddLayer(strType)
		Call Rhino.ObjectLayer(str, strType)
		Call Rhino.ObjectName(str,n)
		addAmmannA3 = str
	ElseIf strType = "B" Then
		'                        f^n+1
		'                     5 _______4
		'                      &#124;       &#124;
		'             f^n+1 -  &#124;       &#124;
		'       7______________&#124;6      &#124;
		'       &#124;       ^              &#124; -----f^n+2
		'       &#124;     f^n+2            &#124;
		'       &#124;                      &#124;
		' f^n+2 &#124;                     3&#124;____2
		'       &#124;                        ^  &#124;
		'       &#124;          2f^n+2       f^n &#124; f^n+1
		'       &#124;______________.____________&#124;
		'       8            0,9            1
		ReDim arrPoints(9)
		arrPoints(0) = array(  0		 ,0        ,0)
		arrPoints(1) = array(  phi^(n+2) ,0,        0)
		arrPoints(2) = array(  phi^(n+2) ,phi^(n+1),0)
		arrPoints(3) = array(  phi^(n+1) ,phi^(n+1),0)
		arrPoints(4) = array(  phi^(n+1) ,phi^(n+3),0)
		arrPoints(5) = array(  0         ,phi^(n+3),0)
		arrPoints(6) = array(  0         ,phi^(n+2),0)
		arrPoints(7) = array(-(phi^(n+2)),phi^(n+2),0)
		arrPoints(8) = array(-(phi^(n+2)),0        ,0)
		arrPoints(9) = array(  0		 ,0        ,0)
		'arrPoints(0) = array(0,0,0)
		'arrPoints(1) = array(2*phi^(n+2),0,0)
		'arrPoints(2) = array(2*phi^(n+2),phi^(n+1),0)
		'arrPoints(3) = array(phi^(n+3),phi^(n+1),0)
		'arrPoints(4) = array(phi^(n+3),phi^(n+3),0)
		'arrPoints(5) = array(phi^(n+2),phi^(n+3),0)
		'arrPoints(6) = array(phi^(n+2),phi^(n+2),0)
		'arrPoints(7) = array(0,phi^(n+2),0)
		'arrPoints(8) = array(0,0,0)
		str = rhino.AddPolyline(arrPoints)
		Call Rhino.AddLayer(strType)
		Call Rhino.ObjectLayer(str, strType)
		Call Rhino.ObjectName(str,n)
		addAmmannA3 = str
	ElseIf strType = "C" Then
		'                        f^n+1
		'                     5 _______4
		'             f^n+1 -  &#124;       &#124;
		'                   &#124;  &#124;       &#124;
		'               7___v__&#124;6      &#124;
		'       f^n -   &#124;              &#124; -----f^n+2
		'               &#124;__9           &#124;
		'               8  &#124;           &#124;
		' 	             ^ &#124;          3&#124;____2
		'            f^n-1 &#124;             ^  &#124;
		'   f^n+1 ------   &#124;            f^n &#124; f^n+1
		'                  &#124;___.____________&#124;
		'                 10  0,11  f^n+2   1
		ReDim arrPoints(11)
		arrPoints(0) = array(  0		 ,0        ,0)
		arrPoints(1) = array(  phi^(n+2) ,0        ,0)
		arrPoints(2) = array(  phi^(n+2) ,phi^(n+1),0)
		arrPoints(3) = array(  phi^(n+1) ,phi^(n+1),0)
		arrPoints(4) = array(  phi^(n+1) ,phi^(n+3),0)
		arrPoints(5) = array(  0         ,phi^(n+3),0)
		arrPoints(6) = array(  0         ,phi^(n+2),0)
		arrPoints(7) = array(-(phi^(n+1)),phi^(n+2),0)
		arrPoints(8) = array(-(phi^(n+1)),phi^(n+1),0)
		arrPoints(9) = array(-(phi^n)    ,phi^(n+1),0)
		arrPoints(10)= array(-(phi^n)    ,0        ,0)
		arrPoints(11)= array(  0		 ,0        ,0)
		str = rhino.AddPolyline(arrPoints)
		Call Rhino.AddLayer(strType)
		Call Rhino.ObjectLayer(str, strType)
		Call Rhino.ObjectName(str,n)
		addAmmannA3 = str
	End If
End Function

Ammann Tiling Subdivide
Option Explicit
'Script written by Ezio Blasetti
'Script not copyrighted by algorithmicdesign.net
'Script version Thursday, March 19, 2009 2:22:35 PM

Call Main()
Sub Main()
	Dim arrParents : arrParents = Rhino.GetObjects("please give me the tile to subdivide",4)
	Dim strParent
	Call Rhino.AddLayer("used")
	For Each strParent In arrParents
		Call SubdivideAmmannA3(strParent)
		Call Rhino.ObjectLayer(strParent,"used")
	Next
End Sub

Function SubdivideAmmannA3(strParent)
	SubdivideAmmannA3 = Null
	Dim strType : strType = Ucase(Left(Rhino.ObjectLayer(strParent),1))
	Dim n		: n		  = Rhino.ObjectName (strParent)
	Dim arrParentReference : arrParentReference = array(Rhino.PolylineVertices(strParent)(0),_
		Rhino.PolylineVertices(strParent)(1),Rhino.PolylineVertices(strParent)(5))
	Dim arrGlobalReference : arrGlobalReference = GetGlobalReference(n)
	Dim arrTarget, i
	If strType = "A" Then
		ReDim arrKids(1)	
		arrKids(0) = addAmmannA3("A",n-1)
		arrTarget  = GetTargetPointsForSubDivision(strType, "A", 0, n)
		Call Rhino.OrientObject (arrKids(0), arrGlobalReference, arrTarget)	
		Call Rhino.OrientObject (arrKids(0), arrGlobalReference, arrParentReference)
		arrKids(1) = addAmmannA3("B",n-1)
		arrTarget  = GetTargetPointsForSubDivision(strType, "B", 0, n)
		Call Rhino.OrientObject (arrKids(1), arrGlobalReference, arrTarget)	
		Call Rhino.OrientObject (arrKids(1), arrGlobalReference, arrParentReference)
	ElseIf strType = "B" Then
		ReDim arrKids(3)
		For i = 0 To 2
			arrKids(i) = addAmmannA3("A",n-1)
			arrTarget  = GetTargetPointsForSubDivision(strType, "A", i, n)
			Call Rhino.OrientObject (arrKids(i), arrGlobalReference, arrTarget)	
			Call Rhino.OrientObject (arrKids(i), arrGlobalReference, arrParentReference)
		Next
		arrKids(3) = addAmmannA3("C",n-1)
		arrTarget  = GetTargetPointsForSubDivision(strType, "C", 3, n)
		Call Rhino.OrientObject (arrKids(3), arrGlobalReference, arrTarget)	
		Call Rhino.OrientObject (arrKids(3), arrGlobalReference, arrParentReference)
	ElseIf strType = "C" Then
		ReDim arrKids(2)
		For i = 0 To 1
			arrKids(i) = addAmmannA3("A",n-1)
			arrTarget  = GetTargetPointsForSubDivision(strType, "A", i, n)
			Call Rhino.OrientObject (arrKids(i), arrGlobalReference, arrTarget)	
			Call Rhino.OrientObject (arrKids(i), arrGlobalReference, arrParentReference)
		Next
		arrKids(2) = addAmmannA3("C",n-1)
		arrTarget  = GetTargetPointsForSubDivision(strType, "C", 3, n)
		Call Rhino.OrientObject (arrKids(2), arrGlobalReference, arrTarget)	
		Call Rhino.OrientObject (arrKids(2), arrGlobalReference, arrParentReference)
	End If
	SubdivideAmmannA3 = arrKids
	
End Function

Function GetTargetPointsForSubDivision(strParentType, strKidType, intKid, n)
	GetTargetPointsForSubDivision = Null
	Dim phi : phi = (sqr(5)+1)/2 'f
	Dim arrReferencePts(2)
	If 	     strParentType = "A" And strKidType = "A" Then
		arrReferencePts(0) = array( phi^(n+2),0        ,0)
		arrReferencePts(1) = array( phi^(n+2),phi^(n+2),0)
		arrReferencePts(2) = array( 0        ,0	       ,0)
		GetTargetPointsForSubDivision = arrReferencePts
	ElseIf   strParentType = "A" And strKidType = "B" Then
		arrReferencePts(0) = array( 0	     ,phi^(n+2),0)
		arrReferencePts(1) = array( 0        ,0	       ,0)
		arrReferencePts(2) = array( phi^(n+1),phi^(n+2),0)
		GetTargetPointsForSubDivision = arrReferencePts
	ElseIf   strParentType = "B" And strKidType = "A" Then
		If     intKid = 0 Then
			arrReferencePts(0) = array(-(phi^(n+2)),0        ,0)
			arrReferencePts(1) = array( 0          ,0	     ,0)
			arrReferencePts(2) = array(-(phi^(n+2)),phi^(n+2),0)
			GetTargetPointsForSubDivision = arrReferencePts
		ElseIf intKid = 1 Then
			arrReferencePts(0) = array( phi^(n+2) ,0,         0)
			arrReferencePts(1) = array( phi^(n+2) ,phi^(n+1) ,0)
			arrReferencePts(2) = array( 0	      ,0         ,0)
			GetTargetPointsForSubDivision = arrReferencePts
		ElseIf intKid = 2 Then
			arrReferencePts(0) = array(  phi^(n+1) ,phi^(n+3),0)
			arrReferencePts(1) = array(  0         ,phi^(n+3),0)
			arrReferencePts(2) = array(  phi^(n+1) ,phi^(n+1),0)
			GetTargetPointsForSubDivision = arrReferencePts
		End If
	ElseIf   strParentType = "B" And strKidType = "C" Then
		arrReferencePts(0) = array(  0         ,phi^(n+2),0)
		arrReferencePts(1) = array(-(phi^(n+2)),phi^(n+2),0)
		arrReferencePts(2) = array(  0		   ,0        ,0)
		GetTargetPointsForSubDivision = arrReferencePts
	ElseIf   strParentType = "C" And strKidType = "A" Then
		If     intKid = 0 Then
			arrReferencePts(0) = array( phi^(n+2) ,0,         0)
			arrReferencePts(1) = array( phi^(n+2) ,phi^(n+1) ,0)
			arrReferencePts(2) = array( 0	      ,0         ,0)
			GetTargetPointsForSubDivision = arrReferencePts
		ElseIf intKid = 1 Then
			arrReferencePts(0) = array(  phi^(n+1) ,phi^(n+3),0)
			arrReferencePts(1) = array(  0         ,phi^(n+3),0)
			arrReferencePts(2) = array(  phi^(n+1) ,phi^(n+1),0)
			GetTargetPointsForSubDivision = arrReferencePts
		End If
	ElseIf   strParentType = "C" And strKidType = "C" Then
		arrReferencePts(0) = array(  0         ,phi^(n+2),0)
		arrReferencePts(1) = array(-(phi^(n+2)),phi^(n+2),0)
		arrReferencePts(2) = array(  0		   ,0        ,0)
		GetTargetPointsForSubDivision = arrReferencePts
	End If
End Function

Function GetGlobalReference(n)
	GetGlobalReference = Null
	Dim phi : phi = (sqr(5)+1)/2 'f
	Dim arrReferencePts(2)
	arrReferencePts(0) = array( 0,        0,        0)
	arrReferencePts(1) = array( phi^(n+2),0,        0)
	arrReferencePts(2) = array( 0,        phi^(n+3),0)
	GetGlobalReference = arrReferencePts
End Function

Function addAmmannA3(strType, n)	
	Dim phi : phi = (sqr(5)+1)/2 'f
	Dim str
	If strType = "A" Then
		'                        f^n+1
		'                     5 _______4
		'                      &#124;       &#124;
		'                      &#124;       &#124;
		'                      &#124;       &#124; -----f^n+1
		'                      &#124;      3&#124;____2
		'                      &#124;          ^ &#124;
		'                f^n+3 &#124;        f^n &#124;
		'                      &#124;            &#124;
		'                      &#124;            &#124; f^n+2
		'                      &#124;            &#124;
		'                      &#124;____________&#124; 
		'                    0,6   f^n+2   1
		ReDim arrPoints(6)
		arrPoints(0) = array( 0,        0,        0)
		arrPoints(1) = array( phi^(n+2),0,        0)
		arrPoints(2) = array( phi^(n+2),phi^(n+2),0)
		arrPoints(3) = array( phi^(n+1),phi^(n+2),0)
		arrPoints(4) = array( phi^(n+1),phi^(n+3),0)
		arrPoints(5) = array( 0,        phi^(n+3),0)
		arrPoints(6) = array( 0,        0,        0)
		str = rhino.AddPolyline(arrPoints)
		Call Rhino.AddLayer(strType)
		Call Rhino.ObjectLayer(str, strType)
		Call Rhino.ObjectName(str,n)
		addAmmannA3 = str
	ElseIf strType = "B" Then
		'                        f^n+1
		'                     5 _______4
		'                      &#124;       &#124;
		'             f^n+1 -  &#124;       &#124;
		'       7______________&#124;6      &#124;
		'       &#124;       ^              &#124; -----f^n+2
		'       &#124;     f^n+2            &#124;
		'       &#124;                      &#124;
		' f^n+2 &#124;                     3&#124;____2
		'       &#124;                        ^  &#124;
		'       &#124;          2f^n+2       f^n &#124; f^n+1
		'       &#124;______________.____________&#124;
		'       8            0,9            1
		ReDim arrPoints(9)
		arrPoints(0) = array(  0		 ,0        ,0)
		arrPoints(1) = array(  phi^(n+2) ,0,        0)
		arrPoints(2) = array(  phi^(n+2) ,phi^(n+1),0)
		arrPoints(3) = array(  phi^(n+1) ,phi^(n+1),0)
		arrPoints(4) = array(  phi^(n+1) ,phi^(n+3),0)
		arrPoints(5) = array(  0         ,phi^(n+3),0)
		arrPoints(6) = array(  0         ,phi^(n+2),0)
		arrPoints(7) = array(-(phi^(n+2)),phi^(n+2),0)
		arrPoints(8) = array(-(phi^(n+2)),0        ,0)
		arrPoints(9) = array(  0		 ,0        ,0)
		'arrPoints(0) = array(0,0,0)
		'arrPoints(1) = array(2*phi^(n+2),0,0)
		'arrPoints(2) = array(2*phi^(n+2),phi^(n+1),0)
		'arrPoints(3) = array(phi^(n+3),phi^(n+1),0)
		'arrPoints(4) = array(phi^(n+3),phi^(n+3),0)
		'arrPoints(5) = array(phi^(n+2),phi^(n+3),0)
		'arrPoints(6) = array(phi^(n+2),phi^(n+2),0)
		'arrPoints(7) = array(0,phi^(n+2),0)
		'arrPoints(8) = array(0,0,0)
		str = rhino.AddPolyline(arrPoints)
		Call Rhino.AddLayer(strType)
		Call Rhino.ObjectLayer(str, strType)
		Call Rhino.ObjectName(str,n)
		addAmmannA3 = str
	ElseIf strType = "C" Then
		'                        f^n+1
		'                     5 _______4
		'             f^n+1 -  &#124;       &#124;
		'                   &#124;  &#124;       &#124;
		'               7___v__&#124;6      &#124;
		'       f^n -   &#124;              &#124; -----f^n+2
		'               &#124;__9           &#124;
		'               8  &#124;           &#124;
		' 	         ^ &#124;          3&#124;____2
		'            f^n-1 &#124;             ^  &#124;
		'   f^n+1 ------   &#124;            f^n &#124; f^n+1
		'                  &#124;___.____________&#124;
		'                 10  0,11  f^n+2   1
		ReDim arrPoints(11)
		arrPoints(0) = array(  0		 ,0        ,0)
		arrPoints(1) = array(  phi^(n+2) ,0        ,0)
		arrPoints(2) = array(  phi^(n+2) ,phi^(n+1),0)
		arrPoints(3) = array(  phi^(n+1) ,phi^(n+1),0)
		arrPoints(4) = array(  phi^(n+1) ,phi^(n+3),0)
		arrPoints(5) = array(  0         ,phi^(n+3),0)
		arrPoints(6) = array(  0         ,phi^(n+2),0)
		arrPoints(7) = array(-(phi^(n+1)),phi^(n+2),0)
		arrPoints(8) = array(-(phi^(n+1)),phi^(n+1),0)
		arrPoints(9) = array(-(phi^n)    ,phi^(n+1),0)
		arrPoints(10)= array(-(phi^n)    ,0        ,0)
		arrPoints(11)= array(  0		 ,0        ,0)
		str = rhino.AddPolyline(arrPoints)
		Call Rhino.AddLayer(strType)
		Call Rhino.ObjectLayer(str, strType)
		Call Rhino.ObjectName(str,n)
		addAmmannA3 = str
	End If
End Function
</description>
		
		<excerpt></excerpt>

		<!--<wfw:commentRss></wfw:commentRss>-->

		<media:thumbnail url="http://payload.cargocollective.com/1/0/9123/900961/prt_1294134922.jpg" />

	</item>
		
		
	<item>
		<title>Navigate Mesh</title>
				
		<link>http://code.algorithmicdesign.net/Navigate-Mesh</link>

		<comments>http://code.algorithmicdesign.net/following/code.algorithmicdesign.net/Navigate-Mesh</comments>

		<pubDate>Tue, 07 Feb 2012 13:35:36 +0000</pubDate>

		<dc:creator>algorithmic design</dc:creator>
		
		<category><![CDATA[rhinoscript]]></category>

		<guid isPermaLink="false">991727</guid>

		<description>Navigate Mesh
Option Explicit

Call Main()
Sub Main
    Dim strmesh : strmesh = Rhino.GetObject("select the mesh to navigate",32)
    'Dim dblCubeSize : dblCubeSize = Rhino.GetReal("Define the bounds of the random points", 10)
    'Dim dblThres   : dblThres   = Rhino.GetReal("define the neighborhood",2)
    
    Dim arrStrAttr : arrStrAttr = Rhino.GetObjects("select the attractor",1)
    Dim i
    reDim arrAttr(Ubound(arrStrAttr))
    For i=0 To Ubound(arrStrAttr)
        arrAttr(i) = Rhino.PointCoordinates(arrStrAttr(i))
    Next
    Dim arrpoints : arrPoints = Rhino.MeshVertices (strMesh)
    'reDim arrPoints(-1)
    'For i=0 To 100
    'reDim Preserve arrpoints(Ubound(arrpoints)+1)
    'arrpoints(Ubound(arrPoints)) = array(rnd*dblCubeSize,rnd*dblCubeSize,rnd*dblCubeSize)
    'Call Rhino.Addpoint (arrpoints(Ubound(arrPoints)))
    'Next

    Dim arrPt0
    Dim arrPt1

    For i=0 To Ubound(arrpoints)
        arrpt0 = arrpoints(i)
        Dim indexAttr : indexAttr = Rhino.PointArrayClosestPoint(arrAttr,arrPt0)
        Dim arrClosestAttr : arrClosestAttr = arrAttr(indexAttr)
        Dim arrneighborsIndex : arrneighborsIndex = MeshVtxAdjacentVtxs (strMesh, i, false, false)
        ReDim arrNeighbors(Ubound(arrneighborsIndex))
        Dim j
		For j=0 To Ubound(arrneighborsIndex)
			arrNeighbors(j) = arrpoints(arrneighborsIndex(j))
		Next
        'reDim arrneighbors(-1)
        'Dim j
        'For j=0 To Ubound(arrpoints)
            'If Not i=j Then
               'If Rhino.Distance(arrPt0,arrPoints(j))</description>
		
		<excerpt></excerpt>

		<!--<wfw:commentRss></wfw:commentRss>-->

		<media:thumbnail url="http://payload.cargocollective.com/1/0/9123/991727/prt_1308945073.jpg" />

	</item>
		
		
	<item>
		<title>Simple Agent Class</title>
				
		<link>http://code.algorithmicdesign.net/Simple-Agent-Class</link>

		<comments>http://code.algorithmicdesign.net/following/code.algorithmicdesign.net/Simple-Agent-Class</comments>

		<pubDate>Tue, 07 Feb 2012 13:35:34 +0000</pubDate>

		<dc:creator>algorithmic design</dc:creator>
		
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">1455356</guid>

		<description>Simple Point Moving Along the X
import rhinoscriptsyntax as rs

class Agent():
    
    def __init__(self, POS, VEC, POINTID):
        #here we initiate the class by matching the inputs to the variables in the class
        self.pos = POS
        self.vec = VEC
        self.pointID = POINTID
        #here we print a little message that everything went well just for fun
        print "made an agent"
    def move(self):
        #updates the position list of the agent
        self.pos = rs.VectorAdd(self.pos, self.vec)
        #delete the old point object in rhino space
        rs.DeleteObject(self.pointID)
        #make a new point object in rhino soace and store its new ID
        self.pointID = rs.AddPoint(self.pos)
        #here we print a little message that everything went well just for fun
        print "i moved"
        
def Main():
    #ask the user to select a point
    pointGUID = rs.GetObject("Pick some points to make agents on",  rs.filter.point)
    #use that point to calculate its coordinates
    coord = rs.PointCoordinates(pointGUID)
    #call the __init__ funciton to create a new agent &#62; and give your new agent a name, "myAgent"
    myAgent = Agent(coord,[1,0,0], pointGUID)
    #call the custom method move using . 10 times
    for i in range(10):
            myAgent.move()

Main()

Simple Points Moving Along the X
import rhinoscriptsyntax as rs

class Agent():
    
    def __init__(self, POS, VEC, POINTID):
        self.pos = POS
        self.vec = VEC
        self.pointID = POINTID
        print "made an agent"

    def move(self):
        self.pos = rs.VectorAdd(self.pos, self.vec)
        rs.DeleteObject(self.pointID)
        self.pointID = rs.AddPoint(self.pos)
        

def Main():
    
    pointGUIDs = rs.GetObjects("Pick some points to make agents on",  rs.filter.point)
    
    agentPopulation = []
    
    for pointGUID in pointGUIDs:
        coord = rs.PointCoordinates(pointGUID)
        agentPopulation.append( Agent(coord,[1,0,0], pointGUID) )

    for i in range(100):
        for agent in agentPopulation:
            agent.move()


Main()

Points Moving in X Direction with Trails

import rhinoscriptsyntax as rs

class Agent():
    
    def __init__(self, POS, VEC, POINTID):
        #here we initiate the class by matching the inputs to the variables in the class
        self.pos = POS
        self.vec = VEC
        self.pointID = POINTID
        #here we make a new list to contain all previous positions for the trail
        self.trailPts = []
        #save the current position as the first point in the trail
        self.trailPts.append(self.pos)
        #here we make a new variable to contan the ID string of the trail
        self.trailID = ""
        print "made an agent"

    def move(self):
        #updates the position list of the agent
        self.pos = rs.VectorAdd(self.pos, self.vec)
        #store the new position in the trail list
        self.trailPts.append(self.pos)
        #delete the old point object in rhino space
        rs.DeleteObject(self.pointID)
        #make a new point object in rhino soace and store its new ID
        self.pointID = rs.AddPoint(self.pos)
        
    def drawTrail(self):
        #delete the old trail curve
        rs.DeleteObject(self.trailID)
        #make a new trail curve from the trailPts list
        self.trailID = rs.AddCurve(self.trailPts)
        

def Main():
    #get some points from the user to use as agent positions
    pointGUIDs = rs.GetObjects("Pick some points to make agents on",  rs.filter.point)
    #######################
    #start a list of agents
    agentPopulation = []

    #setup the list of agents
    for pointGUID in pointGUIDs:
        coord = rs.PointCoordinates(pointGUID)
        #we start an instance of agent 
        agentPopulation.append( Agent(coord,[1,0,0], pointGUID) )

    #move the agents 10 steps
    for i in range(10):
        
        for agent in agentPopulation:
            #move each agent 
            agent.move()
            #draw trail of each agent
            agent.drawTrail()

Main()

Agent Class
import rhinoscriptsyntax as rs

class Attractor():
    def __init__(self,POS,POINTID,MAGNITUDE):
        #here we initiate the class by matching the inputs to the variables in the class
        self.pos = POS
        self.pointID = POINTID
        self.mag = MAGNITUDE

    def getInfluenceVec(self, agent):
        #create a vector between the current agent and the current attractor
        newVec = rs.VectorCreate(self.pos,agent.pos)
        #unitize keep the direction of the vector but makes the length equal to 1
        newVec = rs.VectorUnitize(newVec)
        dist = rs.Distance(self.pos,agent.pos)
        #scale the vector according to the magnitude of the attractor (and the distance from it)
        newVec = rs.VectorScale(newVec,self.mag/dist)
        return newVec

class Agent():

    def __init__(self, POS, VEC, POINTID):
        #here we initiate the class by matching the inputs to the variables in the class
        self.pos = POS
        self.vec = VEC
        self.pointID = POINTID
        #here we make a new list to contain all previous positions for the trail
        self.trailPts = []
        #save the current position as the first point in the trail
        self.trailPts.append(self.pos)
        #here we make a new variable to contan the ID string of the trail
        self.trailID = ""
        #print "made an agent"
        

    def update(self, attractorPopulation, agentPopulation):
        #update the vector of the agent
        self.updateVecAttr(attractorPopulation)
        #move each agent
        self.move()
        #draw trail of each agent
        self.drawTrail()
        #self.drawNetwork(agentPopulation)



    def move(self):
        #updates the position list of the agent
        self.pos = rs.VectorAdd(self.pos, self.vec)
        #store the new position in the trail list
        self.trailPts.append(self.pos)
        if len(self.trailPts)&#62;30:  ##### change the 30 to control the length of the trails
            self.trailPts.pop(0)
        #delete the old point object in rhino space
        rs.DeleteObject(self.pointID)
        #make a new point object in rhino soace and store its new ID
        self.pointID = rs.AddPoint(self.pos)

    def drawTrail(self):
        #delete the old trail curve
        if self.trailID:
            rs.DeleteObject(self.trailID)
        #make a new trail curve from the trailPts lis
        self.trailID = rs.AddCurve(self.trailPts)



    def updateVecAttr(self,attractorPopulation):
        #loop through the attractors in the attractorPopulation
        for myAttractor in attractorPopulation :
            vec = myAttractor.getInfluenceVec(self)
            #add the new vector to the current vector (self.vec)
            self.vec = rs.VectorAdd(self.vec,vec)



    def drawNetwork(self, myAgents):
        for myAgent in myAgents :
            dist = rs.Distance(myAgent.pos,self.pos)
            if dist</description>
		
		<excerpt></excerpt>

		<!--<wfw:commentRss></wfw:commentRss>-->

		<media:thumbnail url="http://payload.cargocollective.com/1/0/9123/1455356/prt_1308756932.jpg" />

	</item>
		
		
	<item>
		<title>Recursive Aggregation Mesh</title>
				
		<link>http://code.algorithmicdesign.net/Recursive-Aggregation-Mesh</link>

		<comments>http://code.algorithmicdesign.net/following/code.algorithmicdesign.net/Recursive-Aggregation-Mesh</comments>

		<pubDate>Tue, 07 Feb 2012 13:35:13 +0000</pubDate>

		<dc:creator>algorithmic design</dc:creator>
		
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">1658758</guid>

		<description>&#60;img src="http://payload.cargocollective.com/1/0/9123/1658758/aggregation_1000_1000.jpg" width="1000" height="400" width_o="1000" height_o="400" src_o="http://payload.cargocollective.com/1/0/9123/1658758/aggregation_1000_o.jpg" data-mid="8139444"  border="0" align="left"/&#62;
Introduction to Classes - Component Classimport rhinoscriptsyntax as rs
"""
Script written by Ezio Blasetti
Script copyrighted by algorithmicdesign.net
Script version Sunday, June 25, 2011 1:07:59 PM
###########################################################################################
This is a simple recursive aggregation example with use of python classes.
It takes as an input four points which define the initial component (seed)
"""
class Component():
    #setup the init function
    def __init__(self, COORDs):
        self.coordinates = COORDs
    #setup a render function
    def render(self):
        #make a copy of the self.coordinates list
        coords4Polyline = self.coordinates[:]
        #append the firt point in th list to close the polyline
        coords4Polyline.append(self.coordinates[0])
        #add the polyline to the document
        self.id = rs.AddPolyline(coords4Polyline)
        
        
def Main():
    #ask the user to select few points and get their guids
    pointGUIDs = rs.GetObjects("Select the points of the seed component",  rs.filter.point)
    #start a list to store the coordinates of those points
    coordinates = []
    #loop through the guids and append their coordinates in the list
    for pointGUID in pointGUIDs: #set up the list of agent
       coordinates.append( rs.PointCoordinates(pointGUID) ) #get POSITION
    #initiate the component class
    myComponent = Component(coordinates)
    #render-draw your component in rhino space
    myComponent.render()
    
Main()
Component Class - Mesh Renderimport rhinoscriptsyntax as rs
"""
Script written by Ezio Blasetti
Script copyrighted by algorithmicdesign.net
Script version Sunday, June 25, 2011 1:07:59 PM
###########################################################################################
This is a simple recursive aggregation example with use of python classes.
It takes as an input four points which define the initial component (seed)
"""
class Component():
    #setup the init function
    def __init__(self, COORDs):
        self.coordinates = COORDs
    #setup a render function
    def renderPolyline(self):
        #make a copy of the self.coordinates list
        coords4Polyline = self.coordinates[:]
        #append the firt point in th list to close the polyline
        coords4Polyline.append(self.coordinates[0])
        #add the polyline to the document
        self.id = rs.AddPolyline(coords4Polyline)
    def render(self):
        #in order to render the component as a mesh we'll need two lists
        #the coordinates list and the face vertices list which looks like this
        faceVertices = [[0,1,2,3]]
        self.id = rs.AddMesh(self.coordinates, faceVertices)
        
def Main():
    #ask the user to select few points and get their guids
    pointGUIDs = rs.GetObjects("Select the 4 points of the seed component",  rs.filter.point)
    #given that we'll be drawing the component as a mesh quad, make sure the user gave as exactly 4 points
    while len(pointGUIDs)!=4:
        if len(pointGUIDs)4 :
            print "you gave me more than 4 points, I'll use the first 4 and the rest of them will be ommited"
            pointGUIDs = pointGUIDs[0:4]
    #start a list to store the coordinates of those points
    coordinates = []
    #loop through the guids and append their coordinates in the list
    for pointGUID in pointGUIDs: #set up the list of agent
       coordinates.append( rs.PointCoordinates(pointGUID) ) #get POSITION
    #initiate the component class
    myComponent = Component(coordinates)
    #render-draw your component in rhino space
    myComponent.render()
    
Main()
Aggregate Class before Recursionimport rhinoscriptsyntax as rs
"""
Script written by Ezio Blasetti
Script copyrighted by algorithmicdesign.net
Script version Sunday, June 25, 2011 1:07:59 PM
###########################################################################################
This is a simple recursive aggregation example with use of python classes.
It takes as an input four points which define the initial component (seed)
"""
class Component():
    #setup the init function
    def __init__(self, COORDs):
        self.coordinates = COORDs
    #setup a render function
    def renderPolyline(self):
        #make a copy of the self.coordinates list
        coords4Polyline = self.coordinates[:]
        #append the firt point in th list to close the polyline
        coords4Polyline.append(self.coordinates[0])
        #add the polyline to the document
        self.id = rs.AddPolyline(coords4Polyline)
    def render(self):
        #in order to render the component as a mesh we'll need two lists
        #the coordinates list and the face vertices list which looks like this
        faceVertices = [[0,1,2,3]]
        self.id = rs.AddMesh(self.coordinates, faceVertices)

class Aggregate():
    def __init__(self, COORDs):
        #start a list of components
        self.currentGeneration = []
        #append the first - seed component in the list
        self.currentGeneration.append( Component(COORDs) )
        #render-draw your component in rhino space
        self.currentGeneration[0].render()
        
        
def Main():
    #ask the user to select few points and get their guids
    pointGUIDs = rs.GetObjects("Select the 4 points of the seed component",  rs.filter.point)
    #given that we'll be drawing the component as a mesh quad, make sure the user gave as exactly 4 points
    while len(pointGUIDs)!=4:
        if len(pointGUIDs)4 :
            print "You gave me more than 4 points, I'll use the first 4 and the rest of them will be ommited"
            pointGUIDs = pointGUIDs[0:4]
    #start a list to store the coordinates of those points
    coordinates = []
    #loop through the guids and append their coordinates in the list
    for pointGUID in pointGUIDs: #set up the list of agent
       coordinates.append( rs.PointCoordinates(pointGUID) ) #get POSITION
    #initiate the aggregate class
    myAggregate = Aggregate(coordinates)
    
Main()
Recursive Aggregate Class &#124; addComponent function - hardcodedimport rhinoscriptsyntax as rs
"""
Script written by Ezio Blasetti
Script copyrighted by algorithmicdesign.net
Script version Sunday, June 25, 2011 1:07:59 PM
###########################################################################################
This is a simple recursive aggregation example with use of python classes.
It takes as an input four points which define the initial component (seed)
"""
class Component():
    #setup the init function
    def __init__(self, COORDs):
        self.coordinates = COORDs
    #setup a render function
    def renderPolyline(self):
        #make a copy of the self.coordinates list
        coords4Polyline = self.coordinates[:]
        #append the firt point in th list to close the polyline
        coords4Polyline.append(self.coordinates[0])
        #add the polyline to the document
        self.id = rs.AddPolyline(coords4Polyline)
    def render(self):
        #in order to render the component as a mesh we'll need two lists
        #the coordinates list and the face vertices list which looks like this
        faceVertices = [[0,1,2,3]]
        self.id = rs.AddMesh(self.coordinates, faceVertices)

class Aggregate():
    def __init__(self, COORDs):
        #start a list of components
        self.currentGeneration = []
        #append the first - seed component in the list
        self.currentGeneration.append( Component(COORDs) )
        #render-draw your component in rhino space
        self.currentGeneration[0].render()
        
    def aggregate(self):
        #this function will aggregate every component in the current generation
        #and once its done, will shift the contents of the "new generation" to
        #the currentGeneration list (will prepare for the next time it will be called)
        self.newGeneration = []
        #loop through every component in the current generation
        for curComponent in self.currentGeneration:
            #have it make kids and append them in the nextGeneration list
            self.newGeneration.append( self.addComponent(curComponent) )
            #render the last kid produced
            self.newGeneration[-1].render()
        #replace the contents of the currentGeneration list with the newly created kids
        self.currentGeneration = self.newGeneration[:]
        
    def addComponent(self, curComponent, sharedVertices = [1,2]):
        #sharedVertices is a list of two integers from 0 to 3
        #indicating the direction in which to add the component according to this scheme
        """
        3 ___ 2          3 ___2___            ___              ___3___ 2
         &#124;   &#124;            &#124;   &#124;   &#124;          &#124;   &#124;            &#124;   &#124;   &#124;
        0&#124;___&#124;1          0&#124;___1___&#124;         3&#124;___&#124;2           &#124;___0___&#124;1
         &#124;   &#124;                               &#124;   &#124;
         &#124;___&#124;                              0&#124;___&#124;1
        
        adding to 0-1    adding to 1-2    adding to 2-3      adding to 3-0
        """
        #we are going to assume this list for now to be [1,2]
        #start a new list to contain the vertices of the component to be created
        newCoordinates = []
        #append the shared vertices
        newCoordinates.append( curComponent.coordinates[ 2 ] )
        newCoordinates.append( curComponent.coordinates[ 1 ] )
        #compute the 3rd vertex - extension of the second with a vector from [0] to [1]
        vec = rs.VectorCreate(curComponent.coordinates[1] ,curComponent.coordinates[0])
        temp = rs.VectorAdd(curComponent.coordinates[1],vec)
        #and append it in the list
        newCoordinates.append(temp)
        #compute the 4th vertex - extension of the third with a vector from [3] to [2]
        vec = rs.VectorCreate(curComponent.coordinates[2] ,curComponent.coordinates[3])
        temp = rs.VectorAdd(curComponent.coordinates[2],vec)
        #and append it in the list
        newCoordinates.append(temp)
        #return the newly created component
        return Component(newCoordinates)
        
        
def Main():
    #ask the user to select few points and get their guids
    pointGUIDs = rs.GetObjects("Select the 4 points of the seed component",  rs.filter.point)
    #given that we'll be drawing the component as a mesh quad, make sure the user gave as exactly 4 points
    while len(pointGUIDs)!=4:
        if len(pointGUIDs)4 :
            print "You gave me more than 4 points, I'll use the first 4 and the rest of them will be ommited"
            pointGUIDs = pointGUIDs[0:4]
    #start a list to store the coordinates of those points
    coordinates = []
    #loop through the guids and append their coordinates in the list
    for pointGUID in pointGUIDs: #set up the list of agent
       coordinates.append( rs.PointCoordinates(pointGUID) ) #get POSITION
    #initiate the aggregate class
    myAggregate = Aggregate(coordinates)
    #ask the user how many generations to produce (how many times to aggregate)
    generations = rs.GetInteger("how many generations", 5, 1, 10)
    #loop for ammount of generations
    for i in range(generations):
        #run the aggregate function to produce the next generation
        myAggregate.aggregate()
    
Main()
Recursive Aggregation &#124; addComponent function parametricimport rhinoscriptsyntax as rs
"""
Script written by Ezio Blasetti
Script copyrighted by algorithmicdesign.net
Script version Sunday, June 25, 2011 1:07:59 PM
###########################################################################################
This is a simple recursive aggregation example with use of python classes.
It takes as an input four points which define the initial component (seed)
"""
class Component():
    #setup the init function
    def __init__(self, COORDs):
        self.coordinates = COORDs
    #setup a render function
    def renderPolyline(self):
        #make a copy of the self.coordinates list
        coords4Polyline = self.coordinates[:]
        #append the firt point in th list to close the polyline
        coords4Polyline.append(self.coordinates[0])
        #add the polyline to the document
        self.id = rs.AddPolyline(coords4Polyline)
    def render(self):
        #in order to render the component as a mesh we'll need two lists
        #the coordinates list and the face vertices list which looks like this
        faceVertices = [[0,1,2,3]]
        self.id = rs.AddMesh(self.coordinates, faceVertices)

class Aggregate():
    def __init__(self, COORDs):
        #start a list of components
        self.currentGeneration = []
        #append the first - seed component in the list
        self.currentGeneration.append( Component(COORDs) )
        #render-draw your component in rhino space
        self.currentGeneration[0].render()
        
    def aggregate(self):
        #this function will aggregate every component in the current generation
        #and once its done, will shift the contents of the "new generation" to
        #the currentGeneration list (will prepare for the next time it will be called)
        self.newGeneration = []
        #loop through every component in the current generation
        for curComponent in self.currentGeneration:
            #have it make kids and append them in the nextGeneration list
            #this is where you can define the rules of the recursive aggregation
            self.newGeneration.append( self.addComponent(curComponent, [2,3], 15) )
            #render the last kid produced
            self.newGeneration[-1].render()
            self.newGeneration.append( self.addComponent(curComponent, [1,2], -45) )
            #render the last kid produced
            self.newGeneration[-1].render()
        #replace the contents of the currentGeneration list with the newly created kids
        self.currentGeneration = self.newGeneration[:]
        
    def addComponent(self, curComponent, sharedVertices, angle):
        #sharedVertices is a list of two integers from 0 to 3
        #indicating the direction in which to add the component according to this scheme
        """
        3 ___ 2          3 ___2___            ___              ___3___ 2
         &#124;   &#124;            &#124;   &#124;   &#124;          &#124;   &#124;            &#124;   &#124;   &#124;
        0&#124;___&#124;1          0&#124;___1___&#124;         3&#124;___&#124;2           &#124;___0___&#124;1
         &#124;   &#124;                               &#124;   &#124;
         &#124;___&#124;                              0&#124;___&#124;1
        
        adding to 0-1    adding to 1-2    adding to 2-3      adding to 3-0
        if shared vertices is [0,1] &#62; the vectors we need are from [3] to [0] and from [2] to [1]
        if shared vertices is [1,2] &#62; the vectors we need are from [0] to [1] and from [3] to [2]
        if shared vertices is [2,3] &#62; the vectors we need are from [1] to [2] and from [0] to [3]
        if shared vertices is [3,0] &#62; the vectors we need are from [1] to [0] and from [2] to [3]
        """
        #the angle variable will determine the rotation around the axis of the shared edge
        #start a new list to contain the vertices of the component to be created
        newCoordinates = []
        #store the shared coordinates
        firstSharedVTX  = curComponent.coordinates[ sharedVertices[1] ]
        secondSharedVTX = curComponent.coordinates[ sharedVertices[0] ]
        #store the vtxs for the vectors
        if sharedVertices[0]==0:
            vtxForFirstVec = curComponent.coordinates[ 3 ]
        else :
            vtxForFirstVec = curComponent.coordinates[ sharedVertices[0] - 1 ]
        if sharedVertices[1]==3:
            vtxForSecondVec = curComponent.coordinates[ 0 ]
        else :
            vtxForSecondVec = curComponent.coordinates[ sharedVertices[1] + 1 ]
        
        #create the axis - vector for rotation
        axis = rs.VectorCreate( secondSharedVTX, firstSharedVTX )
        
        #append the shared vertices
        newCoordinates.append( firstSharedVTX )
        newCoordinates.append( secondSharedVTX )
        #compute the 3rd vertex - extension of the second with the vtx for the 1st vector
        vec = rs.VectorCreate( secondSharedVTX, vtxForFirstVec )
        #rotate the vector
        vec = rs.VectorRotate( vec, angle, axis )
        #add it to the point
        temp = rs.VectorAdd( secondSharedVTX, vec )
        #and append it in the list
        newCoordinates.append(temp)
        #compute the 4th vertex - extension of the first with the vtx for the2nd vector
        vec = rs.VectorCreate( firstSharedVTX , vtxForSecondVec )
        #rotate the vector
        vec = rs.VectorRotate( vec, angle, axis )
        #add it to the point
        temp = rs.VectorAdd( firstSharedVTX, vec )
        #and append it in the list
        newCoordinates.append(temp)
        #return the newly created component
        return Component(newCoordinates)
        
        
def Main():
    #ask the user to select few points and get their guids
    pointGUIDs = rs.GetObjects("Select the 4 points of the seed component",  rs.filter.point)
    #given that we'll be drawing the component as a mesh quad, make sure the user gave as exactly 4 points
    while len(pointGUIDs)!=4:
        if len(pointGUIDs)4 :
            print "You gave me more than 4 points, I'll use the first 4 and the rest of them will be ommited"
            pointGUIDs = pointGUIDs[0:4]
    #start a list to store the coordinates of those points
    coordinates = []
    #loop through the guids and append their coordinates in the list
    for pointGUID in pointGUIDs: #set up the list of agent
       coordinates.append( rs.PointCoordinates(pointGUID) ) #get POSITION
    #initiate the aggregate class
    myAggregate = Aggregate(coordinates)
    #ask the user how many generations to produce (how many times to aggregate)
    generations = rs.GetInteger("how many generations", 5, 1, 10)
    #loop for ammount of generations
    for i in range(generations):
        #run the aggregate function to produce the next generation
        myAggregate.aggregate()
    
Main()
Recursive Conditional Aggregation &#124; A,B,C Rules import rhinoscriptsyntax as rs
"""
Script written by Ezio Blasetti
Script copyrighted by algorithmicdesign.net
Script version Sunday, June 25, 2011 1:07:59 PM
###########################################################################################
This is an advanced - conditional recursive aggregation example with use of python classes.
It takes as an input four points which define the initial component (seed)
"""
class Component():
    #setup the init function
    def __init__(self, COORDs, TYPE):
        self.coordinates = COORDs
        self.type = TYPE
    #setup a render function
    def renderPolyline(self):
        #make a copy of the self.coordinates list
        coords4Polyline = self.coordinates[:]
        #append the firt point in th list to close the polyline
        coords4Polyline.append(self.coordinates[0])
        #add the polyline to the document
        self.id = rs.AddPolyline(coords4Polyline)
    def render(self):
        #in order to render the component as a mesh we'll need two lists
        #the coordinates list and the face vertices list which looks like this
        faceVertices = [[0,1,2,3]]
        self.id = rs.AddMesh(self.coordinates, faceVertices)
        if self.type == "A":
            rs.ObjectColor(self.id, [255,0,0])
        elif self.type == "B":
            rs.ObjectColor(self.id, [255,80,80])
        elif self.type == "C":
            rs.ObjectColor(self.id, [255,160,160])

class Aggregate():
    def __init__(self, COORDs):
        #start a list of components
        self.currentGeneration = []
        #append the first - seed component in the list
        self.currentGeneration.append( Component(COORDs , "A") )
        #render-draw your component in rhino space
        self.currentGeneration[0].render()
        
    def aggregate(self):
        #this function will aggregate every component in the current generation
        #and once its done, will shift the contents of the "new generation" to
        #the currentGeneration list (will prepare for the next time it will be called)
        self.newGeneration = []
        #loop through every component in the current generation
        for curComponent in self.currentGeneration:
            #have it make kids and append them in the nextGeneration list
            #this is where you can define the rules of the recursive aggregation
            # A goes to B with a 0 degree angle
            if curComponent.type == "A":
                self.newGeneration.append( self.addComponent(curComponent, [1,2], 0, "B") )
                #render the last kid produced
                self.newGeneration[-1].render()
            # B goes to C with a -45 degree angle
            elif curComponent.type == "B":
                self.newGeneration.append( self.addComponent(curComponent, [2,3], 60, "C") )
                #render the last kid produced
                self.newGeneration[-1].render()
            # C goes to A with a -15 degree angle and to B with a 45 degree angle
            elif curComponent.type == "C":
                self.newGeneration.append( self.addComponent(curComponent, [2,3], -60, "A") )
                #render the last kid produced
                self.newGeneration[-1].render()
                self.newGeneration.append( self.addComponent(curComponent, [3,0], 0, "B") )
                #render the last kid produced
                self.newGeneration[-1].render()
        #replace the contents of the currentGeneration list with the newly created kids
        self.currentGeneration = self.newGeneration[:]
        
    def addComponent(self, curComponent, sharedVertices, angle, kidType):
        #sharedVertices is a list of two integers from 0 to 3
        #indicating the direction in which to add the component according to this scheme
        """
        3 ___ 2          3 ___2___            ___              ___3___ 2
         &#124;   &#124;            &#124;   &#124;   &#124;          &#124;   &#124;            &#124;   &#124;   &#124;
        0&#124;___&#124;1          0&#124;___1___&#124;         3&#124;___&#124;2           &#124;___0___&#124;1
         &#124;   &#124;                               &#124;   &#124;
         &#124;___&#124;                              0&#124;___&#124;1
        
        adding to 0-1    adding to 1-2    adding to 2-3      adding to 3-0
        if shared vertices is [0,1] &#62; the vectors we need are from [3] to [0] and from [2] to [1]
        if shared vertices is [1,2] &#62; the vectors we need are from [0] to [1] and from [3] to [2]
        if shared vertices is [2,3] &#62; the vectors we need are from [1] to [2] and from [0] to [3]
        if shared vertices is [3,0] &#62; the vectors we need are from [1] to [0] and from [2] to [3]
        """
        #the angle variable will determine the rotation around the axis of the shared edge
        #start a new list to contain the vertices of the component to be created
        newCoordinates = []
        #store the shared coordinates
        firstSharedVTX  = curComponent.coordinates[ sharedVertices[1] ]
        secondSharedVTX = curComponent.coordinates[ sharedVertices[0] ]
        #store the vtxs for the vectors
        if sharedVertices[0]==0:
            vtxForFirstVec = curComponent.coordinates[ 3 ]
        else :
            vtxForFirstVec = curComponent.coordinates[ sharedVertices[0] - 1 ]
        if sharedVertices[1]==3:
            vtxForSecondVec = curComponent.coordinates[ 0 ]
        else :
            vtxForSecondVec = curComponent.coordinates[ sharedVertices[1] + 1 ]
        
        #create the axis - vector for rotation
        axis = rs.VectorCreate( secondSharedVTX, firstSharedVTX )
        
        #append the shared vertices
        newCoordinates.append( firstSharedVTX )
        newCoordinates.append( secondSharedVTX )
        #compute the 3rd vertex - extension of the second with the vtx for the 1st vector
        vec = rs.VectorCreate( secondSharedVTX, vtxForFirstVec )
        #rotate the vector
        vec = rs.VectorRotate( vec, angle, axis )
        #add it to the point
        temp = rs.VectorAdd( secondSharedVTX, vec )
        #and append it in the list
        newCoordinates.append(temp)
        #compute the 4th vertex - extension of the first with the vtx for the2nd vector
        vec = rs.VectorCreate( firstSharedVTX , vtxForSecondVec )
        #rotate the vector
        vec = rs.VectorRotate( vec, angle, axis )
        #add it to the point
        temp = rs.VectorAdd( firstSharedVTX, vec )
        #and append it in the list
        newCoordinates.append(temp)
        #return the newly created component
        return Component(newCoordinates, kidType)
        
        
def Main():
    #ask the user to select few points and get their guids
    pointGUIDs = rs.GetObjects("Select the 4 points of the seed component",  rs.filter.point)
    #given that we'll be drawing the component as a mesh quad, make sure the user gave as exactly 4 points
    while len(pointGUIDs)!=4:
        if len(pointGUIDs)4 :
            print "You gave me more than 4 points, I'll use the first 4 and the rest of them will be ommited"
            pointGUIDs = pointGUIDs[0:4]
    #start a list to store the coordinates of those points
    coordinates = []
    #loop through the guids and append their coordinates in the list
    for pointGUID in pointGUIDs: #set up the list of agent
       coordinates.append( rs.PointCoordinates(pointGUID) ) #get POSITION
    #initiate the aggregate class
    myAggregate = Aggregate(coordinates)
    #ask the user how many generations to produce (how many times to aggregate)
    generations = rs.GetInteger("how many generations", 15, 1, 30)
    #loop for ammount of generations
    for i in range(generations):
        #run the aggregate function to produce the next generation
        myAggregate.aggregate()
    
Main()</description>
		
		<excerpt></excerpt>

		<!--<wfw:commentRss></wfw:commentRss>-->

		<media:thumbnail url="http://payload.cargocollective.com/1/0/9123/1658758/prt_1309313047.jpg" />

	</item>
		
		
	<item>
		<title>Recursive Subdivision Mesh</title>
				
		<link>http://code.algorithmicdesign.net/Recursive-Subdivision-Mesh</link>

		<comments>http://code.algorithmicdesign.net/following/code.algorithmicdesign.net/Recursive-Subdivision-Mesh</comments>

		<pubDate>Tue, 07 Feb 2012 13:35:10 +0000</pubDate>

		<dc:creator>algorithmic design</dc:creator>
		
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">1643720</guid>

		<description>&#60;img src="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_1000_400_1_1000.jpg" width="1000" height="400" width_o="1000" height_o="400" src_o="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_1000_400_1_o.jpg" data-mid="8066974"  border="0" align="left"/&#62;&#60;img src="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_1000_400___1000.jpg" width="1000" height="400" width_o="1000" height_o="400" src_o="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_1000_400___o.jpg" data-mid="8066971"  border="0" align="left"/&#62;&#60;img src="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_1000_400_0_1000.jpg" width="1000" height="400" width_o="1000" height_o="400" src_o="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_1000_400_0_o.jpg" data-mid="8066972"  border="0" align="left"/&#62;import rhinoscriptsyntax as rs

class broccoli():
    
    def __init__(self,seedMeshGUID):
        self.id = seedMeshGUID
        print "made a broccoli with id: " + str(self.id)

def Main():
    mesh = rs.GetObject("select a mesh to make a broccoli",rs.filter.mesh)
    ###################################################################
    myBroccoli = broccoli(mesh)
Main()

&#60;img src="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_0_1000.jpg" width="1000" height="300" width_o="1000" height_o="300" src_o="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_0_o.jpg" data-mid="10098493"  border="0" align="left"/&#62;import rhinoscriptsyntax as rs

class broccoli():
    
    def __init__(self,seedMeshGUID):
        self.id = seedMeshGUID
        print "made a broccoli with id: " + str(self.id)
        #here we store other information we'll need later into a few more variables
        self.vtxs = rs.MeshVertices(self.id)
        self.fVtxs = rs.MeshFaceVertices(self.id)
        self.normals = rs.MeshFaceNormals(self.id)
    
    def newPoint4Subd(self, faceIndex, vecScale):
        #this function returns the centroid point of a face in the mesh
        #displaced via the normal of that face for a vecScale
        centroids = rs.MeshFaceCenters(self.id)
        vec = rs.VectorUnitize(self.normals[faceIndex])
        vec = rs.VectorScale(vec,vecScale)
        return rs.PointAdd(centroids[faceIndex],vec)

def Main():
    mesh = rs.GetObject("select a mesh to make a broccoli",rs.filter.mesh)
    ###################################################################
    myBroccoli = broccoli(mesh)
    ###################################################################
    #let's make a point using the function inside the broccoli class
    rs.AddPoint( myBroccoli.newPoint4Subd(0,5) )
Main()

&#60;img src="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_1_1000.jpg" width="1000" height="300" width_o="1000" height_o="300" src_o="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_1_o.jpg" data-mid="10098495"  border="0" align="left"/&#62;import rhinoscriptsyntax as rs

class broccoli():
    
    def __init__(self,seedMeshGUID):
        self.id = seedMeshGUID
        print "made a broccoli with id: " + str(self.id)
        #here we store other information we'll need later into a few more variables
        self.vtxs = rs.MeshVertices(self.id)
        self.fVtxs = rs.MeshFaceVertices(self.id)
        self.normals = rs.MeshFaceNormals(self.id)
    
    def newPoint4Subd(self, faceIndex, vecScale):
        #this function returns the centroid point of a face in the mesh
        #displaced via the normal of that face for a vecScale
        centroids = rs.MeshFaceCenters(self.id)
        vec = rs.VectorUnitize(self.normals[faceIndex])
        vec = rs.VectorScale(vec,vecScale)
        return rs.PointAdd(centroids[faceIndex],vec)
        
    def subdivideFace(self, faceIndex, scale):
        #this function returns a new mesh -pyramid- for a given faceIndex of a mesh
        
        #here we initiate two new lists to contain the vertices and faceVertices of the pyramid
        newMeshVTXs = []
        newMeshFaceVTXs = []
        #################################################
        faceToSubdivide = self.fVtxs[faceIndex]
        #here we call a custom function to calculate the new vertex from the centroid
        centroidPt = self.newPoint4Subd(faceIndex, scale)
        #we append in the vertex list the vertices of the parent face
        newMeshVTXs.append(self.vtxs[faceToSubdivide[0]])
        newMeshVTXs.append(self.vtxs[faceToSubdivide[1]])
        newMeshVTXs.append(self.vtxs[faceToSubdivide[2]])
        #and the newly calculated centroid
        newMeshVTXs.append(centroidPt)
        #here we append the faceVertices of the new pyramid
        newMeshFaceVTXs.append((3,0,1))
        newMeshFaceVTXs.append((3,1,2))
        newMeshFaceVTXs.append((3,2,0))
        #we make the new mesh -pyramid- and return its GUID
        return rs.AddMesh(newMeshVTXs, newMeshFaceVTXs)

def Main():
    mesh = rs.GetObject("select a mesh to make a broccoli",rs.filter.mesh)
    ###################################################################
    myBroccoli = broccoli(mesh)
    ###################################################################
    #let's make a pyramid using the function inside the broccoli class
    myBroccoli.subdivideFace(0,5)
Main()

&#60;img src="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_2_1000.jpg" width="1000" height="300" width_o="1000" height_o="300" src_o="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_2_o.jpg" data-mid="10098497"  border="0" align="left"/&#62;import rhinoscriptsyntax as rs

class broccoli():
    
    def __init__(self,seedMeshGUID):
        self.id = seedMeshGUID
        print "made a broccoli with id: " + str(self.id)
        #here we store other information we'll need later into a few more variables
        self.vtxs = rs.MeshVertices(self.id)
        self.fVtxs = rs.MeshFaceVertices(self.id)
        self.normals = rs.MeshFaceNormals(self.id)
    
    def newPoint4Subd(self, faceIndex, vecScale):
        #this function returns the centroid point of a face in the mesh
        #displaced via the normal of that face for a vecScale
        centroids = rs.MeshFaceCenters(self.id)
        vec = rs.VectorUnitize(self.normals[faceIndex])
        vec = rs.VectorScale(vec,vecScale)
        return rs.PointAdd(centroids[faceIndex],vec)
        
    def subdivideFace(self, faceIndex, scale):
        #this function returns a new mesh -pyramid- for a given faceIndex of a mesh
        #here we initiate two new lists to contain the vertices and faceVertices of the pyramid
        newMeshVTXs = []
        newMeshFaceVTXs = []
        #################################################
        faceToSubdivide = self.fVtxs[faceIndex]
        #here we call a custom function to calculate the new vertex from the centroid
        centroidPt = self.newPoint4Subd(faceIndex, scale)
        #we append in the vertex list the vertices of the parent face
        newMeshVTXs.append(self.vtxs[faceToSubdivide[0]])
        newMeshVTXs.append(self.vtxs[faceToSubdivide[1]])
        newMeshVTXs.append(self.vtxs[faceToSubdivide[2]])
        #and the newly calculated centroid
        newMeshVTXs.append(centroidPt)
        #here we append the faceVertices of the new pyramid
        newMeshFaceVTXs.append((3,0,1))
        newMeshFaceVTXs.append((3,1,2))
        newMeshFaceVTXs.append((3,2,0))
        #we make the new mesh -pyramid- and return its GUID
        return rs.AddMesh(newMeshVTXs, newMeshFaceVTXs)
        
    def subdivide(self, scale):
        #this function will loop through all the faces of the mesh and subdivide them
        faceCount = len(self.fVtxs)
        rs.EnableRedraw(False)
        for i in range(faceCount):
            #this is where we make the new pyramids for each face
            self.subdivideFace(i, scale)
        rs.EnableRedraw(True)

def Main():
    mesh = rs.GetObject("select a mesh to make a broccoli",rs.filter.mesh)
    ###################################################################
    myBroccoli = broccoli(mesh)
    ###################################################################
    #let's make few pyramids using the function inside the broccoli class
    myBroccoli.subdivide(5)
Main()

&#60;img src="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_3_1000.jpg" width="1000" height="300" width_o="1000" height_o="300" src_o="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_3_o.jpg" data-mid="10098500"  border="0" align="left"/&#62;import rhinoscriptsyntax as rs

class broccoli():
    
    def __init__(self,seedMeshGUID):
        self.id = seedMeshGUID
        print "made a broccoli with id: " + str(self.id)
        #here we store other information we'll need later into a few more variables
        self.vtxs = rs.MeshVertices(self.id)
        self.fVtxs = rs.MeshFaceVertices(self.id)
        self.normals = rs.MeshFaceNormals(self.id)
        self.childrenIDs = []
    
    def newPoint4Subd(self, faceIndex, vecScale):
        #this function returns the centroid point of a face in the mesh
        #displaced via the normal of that face for a vecScale
        centroids = rs.MeshFaceCenters(self.id)
        vec = rs.VectorUnitize(self.normals[faceIndex])
        vec = rs.VectorScale(vec,vecScale)
        return rs.PointAdd(centroids[faceIndex],vec)
        
    def subdivideFace(self, faceIndex, scale):
        #this function returns a new mesh -pyramid- for a given faceIndex of a mesh
        #here we initiate two new lists to contain the vertices and faceVertices of the pyramid
        newMeshVTXs = []
        newMeshFaceVTXs = []
        #################################################
        faceToSubdivide = self.fVtxs[faceIndex]
        #here we call a custom function to calculate the new vertex from the centroid
        centroidPt = self.newPoint4Subd(faceIndex, scale)
        #we append in the vertex list the vertices of the parent face
        newMeshVTXs.append(self.vtxs[faceToSubdivide[0]])
        newMeshVTXs.append(self.vtxs[faceToSubdivide[1]])
        newMeshVTXs.append(self.vtxs[faceToSubdivide[2]])
        #and the newly calculated centroid
        newMeshVTXs.append(centroidPt)
        #here we append the faceVertices of the new pyramid
        newMeshFaceVTXs.append((3,0,1))
        newMeshFaceVTXs.append((3,1,2))
        newMeshFaceVTXs.append((3,2,0))
        #we make the new mesh -pyramid- and return its GUID
        return rs.AddMesh(newMeshVTXs, newMeshFaceVTXs)
        
    def subdivide(self, scale):
        #this function will loop through all the faces of the mesh and subdivide them
        faceCount = len(self.fVtxs)
        rs.EnableRedraw(False)
        for i in range(faceCount):
            #this is where we make the new pyramids for each face
            self.childrenIDs.append(self.subdivideFace(i, scale))
        #this is where we join all the pyramids in one mesh
        self.joinChildren()
        rs.EnableRedraw(True)
        
    def joinChildren(self):
        #this function will join all the meshes in the self.childrenIDs:
        #which means it will create a new mesh whih contains all the vertices and faces
        #of those meshes and delete the old ones. This function basically calculates (sorts out) the two lists
        #required to make a mesh, namely the mesh vertices and the mesh faceVertices. 
        #Example:
        #mesh0VTXs           = [[0,0,0],[1,0,0],[0,1,0],[0,0,1]]
        #mesh0FaceVTXs       = [[3,0,1],[3,1,2],[3,2,0]]
        #mesh1VTXs           = [[0,0,0],[-1,0,0],[0,1,0],[0,0,-1]]
        #mesh1FaceVTXs       = [[3,0,1],[3,1,2],[3,2,0]]
        #Result:
        #mesh0and1VTXs       = [[0,0,0],[1,0,0],[0,1,0],[0,0,1],[0,0,0],[-1,0,0],[0,1,0],[0,0,-1]]
        #mesh0and1FaceVTXs   = [[3, 0, 1],[3, 1, 2],[3, 2, 0],[7, 0, 5],[7, 5, 2],[7, 2, 0]]
        #here we initiate two new lists to contain the vertices and faceVertices of the new 'sum' mesh
        newMeshVTXs = []
        newMeshFaceVTXs = []
        arrayOfMeshes = self.childrenIDs
        #for every mesh in the array of meshes to join
        for currentMesh in arrayOfMeshes:
            #we store its vertices in a list
            meshVTXs = rs.MeshVertices(currentMesh)
            #and extend the list of the new vertices by adding all of these vertices inside
            newMeshVTXs.extend(meshVTXs)
            #we store the faceVertices of the current mesh in a list
            meshFaceVTXs = rs.MeshFaceVertices(currentMesh)
            #we loop through each face in faceVertices list
            for face in meshFaceVTXs:
                #start a new list for the adjusted face
                newFace = []
                #loop through each index (vertex) in the current face
                for index in face:
                    #find the right index for the current vertex and append it in the newFace list
                    newFace.append(newMeshVTXs.index(meshVTXs[index]))
                #append the newFace in the list of new faces
                newMeshFaceVTXs.append(newFace)
        #delete the old meshes
        rs.DeleteObjects(arrayOfMeshes)
        #restart the children list
        self.childrenIDs = []
        #delete the parent mesh
        rs.DeleteObject(self.id)
        #add the new mesh - joined children
        self.id = rs.AddMesh(newMeshVTXs, newMeshFaceVTXs)
        #return true since everything went good
        return True

def Main():
    mesh = rs.GetObject("select a mesh to make a broccoli",rs.filter.mesh)
    ###################################################################
    myBroccoli = broccoli(mesh)
    ###################################################################
    #let's make few pyramids using the function inside the broccoli class
    myBroccoli.subdivide(5)
Main()

&#60;img src="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_4_1000.jpg" width="1000" height="300" width_o="1000" height_o="300" src_o="http://payload.cargocollective.com/1/0/9123/1643720/broccoli_4_o.jpg" data-mid="10098504"  border="0" align="left"/&#62;import rhinoscriptsyntax as rs
"""
Script written by Ezio Blasetti
Script copyrighted by algorithmicdesign.net
Script version Sunday, June 25, 2011 1:07:59 PM
###########################################################################################
This is a simple recursive subdivision example with use of python classes.
It takes as an input a single mesh, the recursive limmit &#38; a scale for the recursive vector
"""
class broccoli():
    def __init__(self, seedMeshGUID):
        #here we initiate the class by matching the inputs to the variables in the class
        self.id = seedMeshGUID
        #here we make sure that the mesh is made only of triangles
        if rs.MeshQuadCount(self.id)&#62;0:
            rs.MeshQuadsToTriangles(self.id)
        #here we store other information we'll need later into a few more variables
        self.vtxs = rs.MeshVertices(self.id)
        self.fVtxs = rs.MeshFaceVertices(self.id)
        self.normals = rs.MeshFaceNormals(self.id)
        self.childrenIDs = []
    
    def newPoint4Subd(self, faceIndex, vecScale):
        #this function returns the centroid point of a face in the mesh
        #displaced via the normal of that face for a vecScale
        centroids = rs.MeshFaceCenters(self.id)
        vec = rs.VectorUnitize(self.normals[faceIndex])
        vec = rs.VectorScale(vec,vecScale)
        return rs.PointAdd(centroids[faceIndex],vec)
    
    def subdivideFace(self, faceIndex, scale):
        """
        this function returns a new mesh -pyramid- for a given faceIndex of a mesh
        """
        #here we initiate two new lists to contain the vertices and faceVertices of the pyramid
        newMeshVTXs = []
        newMeshFaceVTXs = []
        #################################################
        faceToSubdivide = self.fVtxs[faceIndex]
        #here we call a custom function to calculate the new vertex from the centroid
        centroidPt = self.newPoint4Subd(faceIndex, scale)
        #we append in the vertex list the vertices of the parent face
        newMeshVTXs.append(self.vtxs[faceToSubdivide[0]])
        newMeshVTXs.append(self.vtxs[faceToSubdivide[1]])
        newMeshVTXs.append(self.vtxs[faceToSubdivide[2]])
        #and the newly calculated centroid
        newMeshVTXs.append(centroidPt)
        #here we append the faceVertices of the new pyramid
        newMeshFaceVTXs.append((3,0,1))
        newMeshFaceVTXs.append((3,1,2))
        newMeshFaceVTXs.append((3,2,0))
        #we make the new mesh -pyramid- and return its GUID
        return rs.AddMesh(newMeshVTXs, newMeshFaceVTXs)
        
    def subdivide(self, scale):
        """
        this function will loop through all the faces of the mesh and subdivide them
        """
        faceCount = len(self.fVtxs)
        rs.EnableRedraw(False)
        #flip = 1
        for i in range(faceCount):
            #scale = scale*flip
            #this is where we make the new pyramids for each face
            self.childrenIDs.append(self.subdivideFace(i, scale))
            #flip = flip*(-1)
        #this is where we join all the pyramids in one mesh
        self.joinChildren()
        rs.EnableRedraw(True)
        #here we update the information of vtxs,faces,normals in the class variables
        self.vtxs = rs.MeshVertices(self.id)
        self.fVtxs = rs.MeshFaceVertices(self.id)
        self.normals = rs.MeshFaceNormals(self.id)
        
    def joinChildren(self):
        """
        this function will join all the meshes in the self.childrenIDs:
        which means it will create a new mesh whih contains all the vertices and faces
        of those meshes and delete the old ones. This function basically calculates (sorts out) the two lists
        required to make a mesh, namely the mesh vertices and the mesh faceVertices. 
        Example:
        mesh0VTXs           = [[0,0,0],[1,0,0],[0,1,0],[0,0,1]]
        mesh0FaceVTXs       = [[3,0,1],[3,1,2],[3,2,0]]
        mesh1VTXs           = [[0,0,0],[-1,0,0],[0,1,0],[0,0,-1]]
        mesh1FaceVTXs       = [[3,0,1],[3,1,2],[3,2,0]]
        Result:
        mesh0and1VTXs       = [[0,0,0],[1,0,0],[0,1,0],[0,0,1],[0,0,0],[-1,0,0],[0,1,0],[0,0,-1]]
        mesh0and1FaceVTXs   = [[3, 0, 1],[3, 1, 2],[3, 2, 0],[7, 0, 5],[7, 5, 2],[7, 2, 0]]
        """
        #here we initiate two new lists to contain the vertices and faceVertices of the new 'sum' mesh
        newMeshVTXs = []
        newMeshFaceVTXs = []
        arrayOfMeshes = self.childrenIDs
        #for every mesh in the array of meshes to join
        for currentMesh in arrayOfMeshes:
            #we store its vertices in a list
            meshVTXs = rs.MeshVertices(currentMesh)
            #and extend the list of the new vertices by adding all of these vertices inside
            newMeshVTXs.extend(meshVTXs)
            #we store the faceVertices of the current mesh in a list
            meshFaceVTXs = rs.MeshFaceVertices(currentMesh)
            #we loop through each face in faceVertices list
            for face in meshFaceVTXs:
                #start a new list for the adjusted face
                newFace = []
                #loop through each index (vertex) in the current face
                for index in face:
                    #find the right index for the current vertex and append it in the newFace list
                    newFace.append(newMeshVTXs.index(meshVTXs[index]))
                #append the newFace in the list of new faces
                newMeshFaceVTXs.append(newFace)
        #delete the old meshes
        rs.DeleteObjects(arrayOfMeshes)
        #restart the children list
        self.childrenIDs = []
        #delete the parent mesh
        rs.DeleteObject(self.id)
        #add the new mesh - joined children
        self.id = rs.AddMesh(newMeshVTXs, newMeshFaceVTXs)
        #return true since everything went good
        return True
    
def main():
    mesh = rs.GetObject()
    x = rs.GetInteger("Enter the number of recursion: ", 4, 1, 8)
    scale = rs.GetInteger("Enter the starting scale of vector: ", 3)
    ###################################################################
    myBroccoli = broccoli(mesh)
    ###################################################################
    for i in range(x):
        myBroccoli.subdivide(scale/(i+1))

main()
</description>
		
		<excerpt></excerpt>

		<!--<wfw:commentRss></wfw:commentRss>-->

		<media:thumbnail url="http://payload.cargocollective.com/1/0/9123/1643720/prt_1309020521.jpg" />

	</item>
		
		
	<item>
		<title>Self Organizing Curves</title>
				
		<link>http://code.algorithmicdesign.net/Self-Organizing-Curves</link>

		<comments>http://code.algorithmicdesign.net/following/code.algorithmicdesign.net/Self-Organizing-Curves</comments>

		<pubDate>Tue, 07 Feb 2012 13:34:56 +0000</pubDate>

		<dc:creator>algorithmic design</dc:creator>
		
		<category><![CDATA[rhinoscript, python, grasshopper]]></category>

		<guid isPermaLink="false">966684</guid>

		<description>&#60;img src="http://payload.cargocollective.com/1/0/9123/966684/frei-otto-banner_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/966684/frei-otto-banner_o.jpg" data-mid="4966056"  border="0" align="left"/&#62;Frei Otto Wool Experiment import rhinoscriptsyntax as rs

Gens = rs.GetInteger("Number of Iterations",6,1)
Curves = rs.GetObjects("Select Base Crvs",rs.filter.curve)
thres = rs.GetReal("CurvePointAttractionThreshold")
dblRatio = rs.GetReal("Distance For Vector To Move")

for i in range(Gens): 
    for j in range(len(Curves)):      
        arrNewPoints = []
        currentPoints = rs.CurvePoints(Curves[j])           
        for k in range(len(currentPoints)):               
            closestPtsOnOtherCrvs = []                                                
            count = 0                    
            for l in range(len(Curves)):                                               
                if j != l :                           
                    param = rs.CurveClosestPoint(Curves[l],currentPoints[k])                          
                    crvPt = rs.EvaluateCurve(Curves[l],param)
                    closestPtsOnOtherCrvs.append(crvPt)                            
            IndexClosestCrv = rs.PointArrayClosestPoint(closestPtsOnOtherCrvs,currentPoints[k])
            closestPoint = closestPtsOnOtherCrvs[IndexClosestCrv]                 
            dist = rs.Distance(currentPoints[k],closestPoint)                    
            if dist &#60; thres :                        
                vector = rs.VectorCreate(closestPoint,currentPoints[k])
                vector = rs.VectorScale(vector,dblRatio)
                NewPosition = rs.PointAdd(vector,currentPoints[k])
            else:                        
                NewPosition = currentPoints[k]                                                
            arrNewPoints.append(NewPosition)
        newCurve = rs.AddCurve(arrNewPoints)
        rs.DeleteObject(Curves[j])
        Curves[j] = newCurve 
Frei Otto Wool Experiment + Relaxationimport rhinoscriptsyntax as rs
import random
#Script written by Ezio Blasetti
#Script copyrighted by algorithmicdesign.net
#Script version Saturday, January 22, 2011 11:30:40 AM

def RelaxCurve(strCrv, howMuch, strBool):
    arrPts    = rs.CurvePoints(strCrv)
    arrNewPts = []
    if strBool == "yes" :
        intStart = 0
        intEnd   = len(arrPts) - 1
    else :
        arrNewPts.append(arrPts[0])
        intStart = 1
        intEnd   = len(arrPts) - 2
    for i in range(intStart,intEnd):
        if i != 0 :
            arrVector0 = rs.VectorCreate(arrPts[i-1],arrPts[i])
        else:
            arrVector0 = array[0,0,0]
        if i!=len(arrPts)-1 :
            arrVector1 = rs.VectorCreate(arrPts[i+1],arrPts[i])
        else:
            arrVector1 = array[0,0,0]
        arrSumVec = rs.VectorAdd(arrVector0, arrVector1)
        arrSumVec = rs.VectorScale(arrSumVec,howMuch)
        arrNewPts.append( rs.PointAdd(arrPts[i], arrSumVec) )
    rs.DeleteObject(strCrv)
    if strBool == "no":
        arrNewPts.append(arrPts[-1])
    return rs.AddCurve(arrNewPts)

def Main():
    arrCrvs     = rs.GetObjects("select some crvs",4)
    dblThres    = rs.GetReal   ("please type the threshold of affection",10)
    dblStep     = rs.GetReal   ("please type the scale of each step",0.1)
    strBool     = rs.GetString ("move the start and end points", "no", ["yes","no"])
    strBlnAdj   = rs.GetString ("adjust scale of vectors during attraction", "yes", ["yes","no"])
    strBoolrnd  = rs.GetString ("break the symmetry with a bit of rnd", "yes", ["yes","no"])	
    strBlnRelax = rs.GetString ("relax the crvs during attraction", "yes", ["yes","no"])
    strCopies   = rs.GetString ("make copies of curves", "no", ["yes","no"])
    arrAllCrvPts = []
    for crv in arrCrvs:
        arrAllCrvPts.append( rs.CurvePoints(crv) )
    if strBlnAdj == "yes" :
            adjScaleAtStart = dblThres
    else:
            adjScaleAtStart = 1  
    intContinue = 10
    while intContinue&#62;-1:
        print("computing " + str(100 - intContinue*10) + "% done")
        rs.EnableRedraw (False)
        arrNewCrvs = []
        arrNewAllCrvPts = []
        for i in range (len(arrCrvs)):
            arrPtsOnICrv = arrAllCrvPts[i]
            if strBool == "yes" :
                intStart = 0
                intEnd   = len(arrPtsOnICrv) - 1
            else:
                intStart = 1
                intEnd   = len(arrPtsOnICrv) - 2
            for j in range(intStart,intEnd):
                arrVector = [0,0,0]
                count = 0
                for k in range(len(arrCrvs)):
                    arrPtsOnKCrv = arrAllCrvPts[k]
                    for e in range(len(arrPtsOnKCrv)):
                        dblDistance = rs.Distance(arrPtsOnICrv[j], arrPtsOnKCrv[e])
                        if dblDistance &#60; dblThres :
                            arrCurrentVec = rs.VectorCreate(arrPtsOnKCrv[e],arrPtsOnICrv[j])
                            arrVector = rs.VectorAdd(arrVector,arrCurrentVec)
                            count += 1
                if count!=0 :
                    arrVector = rs.VectorDivide(arrVector,count)
                    if strBoolrnd == "yes" :
                        rnd = random.random()
                        arrVector = rs.VectorScale(arrVector,dblStep*rnd*adjScaleAtStart)
                    else:
                        arrVector = rs.VectorScale(arrVector,dblStep*adjScaleAtStart)
                arrPtsOnICrv[j] = rs.VectorAdd(arrPtsOnICrv[j], arrVector)
            arrNewCrvs.append( rs.AddCurve(arrPtsOnICrv) )
            arrNewAllCrvPts.append( arrPtsOnICrv )
        if strCopies == "no" :
            rs.DeleteObjects(arrCrvs)
        arrCrvs = arrNewCrvs
        if adjScaleAtStart&#62;1 :
            adjScaleAtStart = adjScaleAtStart-10/dblThres  
        for i in range(len(arrCrvs)):
            arrCrvs[i] = RelaxCurve(arrCrvs[i], dblStep*2, strBool)
        rs.EnableRedraw(True)
        if intContinue &#60; 1 :
            strStop = rs.GetString ("enough", "no", ["yes","no"])
            if strStop == "yes" : 
                rs.EnableRedraw(True)
                inContinue = -1
            else:
                intContinue = 10
        intContinue = intContinue - 1
Main()Frei Otto Wool Experiment + Relaxation in VbOption Explicit
'Script written by Ezio Blasetti
'Script copyrighted by algorithmicdesign.net
'Script version Saturday, January 22, 2011 11:30:40 AM

Call Main()
Sub Main()
	Dim arrCrvs     : arrCrvs     = Rhino.GetObjects("select some crvs",4)
	Dim dblThres    : dblThres    = Rhino.GetReal   ("please type the threshold of affection",10)
	Dim dblStep     : dblStep     = Rhino.GetReal   ("please type the scale of each step",0.1)
	Dim strBool     : strBool     = Rhino.GetString ("move the start and end points", "no", array("yes","no"))
	Dim strBlnAdj   : strBlnAdj   = Rhino.GetString ("adjust scale of vectors during attraction", "yes", array("yes","no"))
	Dim strBoolrnd  : strBoolrnd  = Rhino.GetString ("break the symmetry with a bit of rnd", "yes", array("yes","no"))	
	Dim strBlnRelax : strBlnRelax = Rhino.GetString ("relax the crvs during attraction", "yes", array("yes","no"))
	Dim strCopies   : strCopies   = Rhino.GetString ("make copies of curves", "no", array("yes","no"))
	ReDim arrAllCrvPts(Ubound(arrCrvs))
	Dim adjScaleAtStart 
	If strBlnAdj = "yes" Then
		adjScaleAtStart = dblThres
	Else
		adjScaleAtStart = 1
	End If
	
	Dim intContinue : intContinue = 10
	Do
		Call Rhino.Print("computing " &#38; 100 - intContinue*10 &#38; "% done")
		Call Rhino.EnableRedraw(False)
		Dim arrNewCrvs : arrNewCrvs = arrcrvs
		Dim i
		For i=0 To Ubound(arrCrvs)
			Dim l
			For l=0 To Ubound(arrCrvs)
				arrAllCrvPts(l) = Rhino.CurvePoints(arrCrvs(l))
			Next
			Dim arrPtsOnICrv : arrPtsOnICrv = arrAllCrvPts(i)
			Dim j
			Dim intStart, intEnd
			If strBool = "yes" Then
				intStart = 0
				intEnd   = Ubound(arrPtsOnICrv)
			Else
				intStart = 1
				intEnd   = Ubound(arrPtsOnICrv)-1
			End If
			For j=intStart To intEnd
				Dim arrVector : arrVector = array(0,0,0)
				Dim count : count = 0
				Dim k
				For k=0 To Ubound(arrCrvs)
					Dim arrPtsOnKCrv : arrPtsOnKCrv = arrAllCrvPts(k)
					Dim e
					For e = 0 To Ubound(arrPtsOnKCrv)
						Dim dblDistance : dblDistance = Rhino.Distance(arrPtsOnICrv(j), arrPtsOnKCrv(e))
						If dblDistance &#60; dblThres Then
							Dim arrCurrentVec : arrCurrentVec = Rhino.VectorCreate(arrPtsOnKCrv(e),arrPtsOnICrv(j))
							arrVector = Rhino.VectorAdd(arrVector,arrCurrentVec)
							count = count + 1
						End If
					Next
				Next
				If Not count=0 Then
					arrVector = rhino.VectorDivide(arrVector,count)
					If strBoolrnd = "yes" Then
						arrVector = rhino.VectorScale(arrVector,dblStep*rnd*adjScaleAtStart)
					Else
						arrVector = rhino.VectorScale(arrVector,dblStep*adjScaleAtStart)
					End If
				End If
				arrPtsOnIcrv(j) = Rhino.VectorAdd(arrPtsOnIcrv(j), arrVector)
			Next
			arrnewCrvs(i) = Rhino.AddCurve(arrPtsOnICrv)
		Next
		If strCopies = "no" Then
			Call Rhino.DeleteObjects(arrCrvs)
		End If
		arrCrvs = arrnewCrvs
		If adjScaleAtStart&#62;1 Then
			adjScaleAtStart = adjScaleAtStart-10/dblThres
		End If
			
		For i=0 To Ubound(arrCrvs)
			arrCrvs(i) = RelaxCurve(arrCrvs(i), dblStep*2, strBool)
		Next
		Call Rhino.EnableRedraw(True)
		If intContinue &#60; 1 Then
			Dim strStop : strStop = Rhino.GetString ("enough", "no", array("yes","no"))
			If strStop = "yes" Then 
				Call Rhino.EnableRedraw(True)
				Exit Do
			Else
				intContinue = 10
			End If	
		End If
		intContinue = intContinue - 1
	Loop
End Sub

Function RelaxCurve(strCrv, howMuch, strBool)
	RelaxCurve = Null
	Dim arrPts    : arrPts    = Rhino.CurvePoints(strCrv)
	Dim arrNewPts : arrNewPts = arrPts
	Dim i
	Dim intStart, intEnd
	If strBool = "yes" Then
		intStart = 0
		intEnd   = Ubound(arrPts)
	Else
		intStart = 1
		intEnd   = Ubound(arrPts)-1
	End If
	For i=intStart To intEnd
		Dim arrVector0, arrVector1
		If Not i = 0 Then
			arrVector0 = Rhino.VectorCreate(arrPts(i-1),arrPts(i))
		Else
			arrVector0 = array(0,0,0)
		End If
		If Not i=Ubound(arrPts) Then
			arrVector1 = Rhino.VectorCreate(arrPts(i+1),arrPts(i))
		Else
			arrVector1 = array(0,0,0)
		End If
		Dim arrSumVec  : arrSumVec = Rhino.VectorAdd(arrVector0, arrVector1)
		arrSumVec = rhino.VectorScale(arrSumVec,howMuch)
		arrNewPts(i) = Rhino.PointAdd(arrPts(i), arrSumVec)
	Next
	Call Rhino.DeleteObject(strCrv)
	RelaxCurve = Rhino.AddCurve(arrNewPts)
End Function</description>
		
		<excerpt></excerpt>

		<!--<wfw:commentRss></wfw:commentRss>-->

		<media:thumbnail url="http://payload.cargocollective.com/1/0/9123/966684/prt_1297193836.jpg" />

	</item>
		
		
	<item>
		<title>Agents On Mesh</title>
				
		<link>http://code.algorithmicdesign.net/Agents-On-Mesh</link>

		<comments>http://code.algorithmicdesign.net/following/code.algorithmicdesign.net/Agents-On-Mesh</comments>

		<pubDate>Tue, 07 Feb 2012 13:34:53 +0000</pubDate>

		<dc:creator>algorithmic design</dc:creator>
		
		<category><![CDATA[python, rhinoscript]]></category>

		<guid isPermaLink="false">1033655</guid>

		<description>&#60;img src="http://payload.cargocollective.com/1/0/9123/1033655/addAgentOnMesh_Banner_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/1033655/addAgentOnMesh_Banner_o.jpg" data-mid="4965190"  border="0" align="left"/&#62;Agents On Mesh Deforming Vertices Towards Attractorsthe code in python:import rhinoscriptsyntax as rs
import random
"""
Script written by Ezio Blasetti
Script copyrighted by algorithmicdesign.net
Script version Sunday, June 25, 2011 5:11:59 PM
###########################################################################################
This is a simple mesh navigation example.
It takes as an input a single mesh, a few attractors as points or curves and
a collection of points for the selection of vertices-agents
"""

def MeshVtxAdjacentVtxs (strMesh, index, blnAbsolutConnections=False, blnCreate=False): 
    """---------------------------------------------------------------------------------------------------------------------------------------
    MeshVtxAdjacentVtxs
    finds the adjecent vertices on a mesh for a given index of a vertex.
    written by Ezio Blasetti. Last Revision 062411.
    
    Syntax
    MeshVtxAdjacentVtxs (strMesh, index, blnAbsolutConnections, blnCreate)
    
    Parameters
    strMesh                       Required. String.  The identifier of a mesh object.
    index                         Required. Integer. The index of a vertex object inside the array returned from rs.MeshVertices method.
                                                     Use rs.MeshVertexCount for the length of that array.
    blnAbsolutConnections         Optional. Boolean. If True only the end points of the adjacent edges will be returned.
                                                     Note, if false, all the vertices of the adjacent faces will be returned.
    blnCreate                     Optional. Boolean. Create the adjacent points. If false, points are not created.
    
    Returns
    Array                         If blnCreate is equal to True , an array containing 3D adjacent points if successful.
    Array                         If blnCreate is equal to False, an array containing the indexes of the adjacent vetrices if successful.
    None                          If not successful, or on error.
    
    
    Example
    import rhinoscriptsyntax as rs
    strObject        = rs.GetObject("Select the mesh", 32)
    intRndVtxIndex   = 0
    arr              = MeshVtxAdjacentVtxs (strObject, intRndVtxIndex, True, True)
    ---------------------------------------------------------------------------------------------------------------------------------------"""
    """custom function"""
    #-----------------------------------------------------------------------------------------------------------------------------------------
    def CullDuplicates(seq, idfun=None):  
        # order preserving 
        if idfun is None: 
            def idfun(x): return x 
        seen = {} 
        result = [] 
        for item in seq: 
            marker = idfun(item) 
            if marker in seen: continue 
            seen[marker] = 1 
            result.append(item) 
        return result
    #-----------------------------------------------------------------------------------------------------------------------------------------
    MeshVtxAdjacentVtxs = []
    if rs.IsMesh(strMesh)==False : 
        print "strMesh is not an mesh"
        return None
    if type(index)==type("string"):
        print "index is not an integer"
        return None
    if type(index)==type(0.1): index = int(index)

    arrVertices     = rs.MeshVertices    (strMesh)
    arrFaceVertices = rs.MeshFaceVertices(strMesh)

    intCount = 0
    arrAdjacentVtxs = []
    for arrFace in arrFaceVertices:
        blnIsAdjacent = False
        for arrVtxIndex in arrFace:
            if arrVtxIndex == index :
                blnIsAdjacent = True
        if blnIsAdjacent :
            if blnAbsolutConnections :
                if arrFace[2]==arrFace[3] :
                    for arrVtxIndex in arrFace :
                        if arrVtxIndex != index :
                            arrAdjacentVtxs.append( arrVtxIndex)
                else :
                    if index == arrFace[0] :
                        arrAdjacentVtxs.append( arrFace[3] )
                        arrAdjacentVtxs.append( arrFace[1] )
                    elif index == arrFace[1] :
                        arrAdjacentVtxs.append( arrFace[0] )
                        arrAdjacentVtxs.append( arrFace[2] )
                    elif index == arrFace[2] :
                        arrAdjacentVtxs.append( arrFace[1] )
                        arrAdjacentVtxs.append( arrFace[3] )
                    elif index == arrFace(3) :
                        arrAdjacentVtxs.append( arrFace[2] )
                        arrAdjacentVtxs.append( arrFace[0] )
            else :
                for arrVtxIndex in arrFace :
                    if arrVtxIndex != index :
                        arrAdjacentVtxs.append( arrVtxIndex )
    if type(arrAdjacentVtxs) != type([]) : return None
    arrOrderAdjacentVtxs = CullDuplicates(arrAdjacentVtxs)
    if blnCreate :
        arrStrPts = []
        for arrVtxIndex in arrOrderAdjacentVtxs:
            rs.AddPoint ( arrVertices[arrVtxIndex] )
            arrStrPts.append( arrVertices[arrVtxIndex] )
        return arrStrPts
    else :
        return arrOrderAdjacentVtxs

def RenderAgentsOnMesh(strMesh, arrIndexes):
	arrVertices     = rs.MeshVertices(strMesh)
	arrVertexColors = []
	for i in range(len(arrVertices)):
		arrVertexColors.append( [255,255,255] )
	for index in arrIndexes:
		arrVertexColors[index] = [0,0,0]
	rs.MeshVertexColors (strMesh , arrVertexColors)

def Main():
	#SETUP
	#-------------------------------------------------------------------------------------------------------
	#select the mesh to work on	////////////////////////////////////////////////////////////////////
	strMesh         = rs.GetObject ("select mesh to work on", 32)	
	# store the mesh face vertices - we'll need it later to rebuild the mesh
	arrFaceVertices = rs.MeshFaceVertices(strMesh)
	#select the attractors points		////////////////////////////////////////////////////////////////////
	attrs           = rs.GetObjects ("select the attractors for direction - either points or curves", 5)
	# here we need to translate the attractors (IDS of points and curves that the user gave us) to coordinates
	#--------------------------------------------------------------------------
	arrAttractors = []
	for attr in attrs:
		if rs.IsCurve(attr) :
			#if it is a curve - i need to find the closest point to the current agent
			#right now i'll set it up to array(0,0,0) and i'll replace those values in the do loop later
			arrAttractors.append([0,0,0])
		else : 
			arrAttractors.append( rs.PointCoordinates(attr)	)
	#select the agents			////////////////////////////////////////////////////////////////////
	arrStrPtAgents = rs.GetObjects ("select Agents to move on the mesh", 1)	
	dblStep        = rs.GetReal("please type the step size of the agents' deformation vactor",1)
	# here we need to translate the agents (points that the user gave us
	# to vertices on the mesh....
	#--------------------------------------------------------------------------
	# start a new array same size as the agents-points - call it agentsOnmesh
	agentsOnMesh = []		
	# get the mesh vertices
	arrVTXS         = rs.MeshVertices (strMesh)
	# loop throught the points-agents that the user gave us,
	for strPtAgent in arrStrPtAgents:
		arrPtAgent = rs.PointCoordinates(strPtAgent)
		# use point array closest point to determine which mesh vertex is closest to the current agent-point
		# store that index from pointarrayclosestpoint in the agentsOnMesh(i)		
		agentsOnMesh.append( rs.PointArrayClosestPoint(arrVTXS,arrPtAgent) )
		# end loop	
	#-------------------------------------------------------------------------------------------------------
	#RUN
	#-------------------------------------------------------------------------------------------------------	
	#loop for number of steps
	for e in range(100):
		# 	get the mesh vertices of the current mesh arrVTXS
		arrVTXS = rs.MeshVertices (strMesh)
		#	start a arrNEWVTXS and make it equal to arrVTXS (for now)
		arrNEWVTXS = arrVTXS[:]
		#	i loop through each index in agentsOnMesh
		i = 0
		for agentOnMesh in  agentsOnMesh:
			# MOVE THE MESH POINT --------------------------------------------------------------------------
			j = 0
			for attr in attrs :
				if rs.IsCurve(attr) :
					#here we find the closestpoint on the curve attractors from the current agent
					dblParam = rs.CurveClosestPoint(attr,arrVTXS[agentOnMesh])
					arrAttractors[j] = rs.EvaluateCurve(attr,dblParam)
					j += 1
			ClosestAttIndex = rs.PointArrayClosestPoint(arrAttractors,arrVTXS[agentOnMesh])
			# make a vector from arrVTXS(agentsOnMesh(i)) towards the closest attractor arrAttractors(ClosestAttIndex)
			arrVector = rs.VectorCreate(arrAttractors[ClosestAttIndex], arrVTXS[agentOnMesh])
			arrVector = rs.VectorUnitize(arrVector)
			arrVector = rs.VectorScale(arrVector, dblStep)
			# add the vector to the arrVTXS(agentsOnMesh(i)) and store it in arrNEWVTXS(agentsOnMesh(i))
			arrNEWVTXS[agentOnMesh] = rs.PointAdd(arrVTXS[agentOnMesh], arrVector)
			# MOVE THE AGENT      --------------------------------------------------------------------------
			# get the adjacent mesh vtx indexes from MeshVtxAdjacentVtxs
			arrNeighborIndexes = MeshVtxAdjacentVtxs (strMesh, agentOnMesh, False, False)
			# choose which vtx to "move" to, and store it in agentsOnMesh(i)
			rnd = random.random()
			agentsOnMesh[i] = arrNeighborIndexes[int((rnd)*(len(arrNeighborIndexes)-1))]
			i += 1
		#	add a new mesh in the document using arrNEWVTXS
		strNewMesh = rs.AddMesh(arrNEWVTXS,arrFaceVertices)
		RenderAgentsOnMesh(strNewMesh, agentsOnMesh)
		#	delete the old one 
		rs.DeleteObject(strMesh)
		#	replace the ID of old mesh with the NEW ID
		strMesh = strNewMesh

Main()the code in vbscript
Option Explicit
'Script written by Ezio Blasetti &#38; Wisarut Wattanachote
'Script version Sunday, February 06, 2011 12:00:32 PM
Call Main()
Sub Main()

	'SETUP
	'-------------------------------------------------------------------------------------------------------
	'select the mesh to work on	////////////////////////////////////////////////////////////////////
	Dim strMesh         : strMesh         = Rhino.GetObject ("select mesh to work on", 32)	
	' store the mesh face vertices - we'll need it later to rebuild the mesh
	Dim arrFaceVertices : arrFaceVertices = Rhino.MeshFaceVertices(strMesh)
	'select the attractors points		////////////////////////////////////////////////////////////////////
	Dim attrs           : attrs           = Rhino.GetObjects ("select the attractors for direction - either points or curves", 5)
	' here we need to translate the attractors (IDS of points and curves that the user gave us) to coordinates
	'--------------------------------------------------------------------------
	ReDim arrAttractors(Ubound(attrs))
	Dim i
	For i=0 To Ubound(attrs)
		If Rhino.IsCurve(attrs(i)) Then
			'if it is a curve - i need to find the closest point to the current agent
			'right now i'll set it up to array(0,0,0) and i'll replace those values in the do loop later
			arrAttractors(i) = array(0,0,0)
		Else
			arrAttractors(i) = Rhino.PointCoordinates(attrs(i))	
		End If
	Next
	'select the agents			////////////////////////////////////////////////////////////////////
	Dim arrStrPtAgents : arrStrPtAgents = Rhino.GetObjects ("select Agents to move on the mesh", 1)	
	Dim dblStep        : dblStep        = Rhino.GetReal("please type the step size of the agents' deformation vactor",1)
	' here we need to translate the agents (points that the user gave us
	' to vertices on the mesh....
	'--------------------------------------------------------------------------
	' start a new array same size as the agents-points - call it agentsOnmesh
	ReDim agentsOnMesh(Ubound(arrStrPtAgents))		
	' get the mesh vertices
	Dim arrVTXS : arrVTXS         = Rhino.MeshVertices (strMesh)
	' i loop throught the points-agents that the user gave us,
	For i=0 To Ubound(arrStrPtAgents)
		Dim arrPtAgent : arrPtAgent = Rhino.PointCoordinates(arrStrPtAgents(i))
		' use point array closest point to determine which mesh vertex is closest to the current agent-point
		' store that index from pointarrayclosestpoint in the agentsOnMesh(i)		
		agentsOnMesh(i)           = Rhino.PointArrayClosestPoint(arrVTXS,arrPtAgent)
		' end loop	
	Next
	'-------------------------------------------------------------------------------------------------------
	
	
	'RUN
	'-------------------------------------------------------------------------------------------------------	
	'do
	Do
		' 	get the mesh vertices of the current mesh arrVTXS
		arrVTXS = Rhino.MeshVertices (strMesh)
		'	start a arrNEWVTXS and make it equal to arrVTXS (for now)
		Dim arrNEWVTXS : arrNEWVTXS = arrVTXS
		'	i loop through each index in agentsOnMesh
		For i = 0 To Ubound(agentsOnMesh)
			' MOVE THE MESH POINT --------------------------------------------------------------------------
			Dim j
			For j=0 To Ubound(attrs)
				If Rhino.IsCurve(attrs(j)) Then
					'here we find the closestpoint on the curve attractors from the current agent
					Dim dblParam : dblParam = Rhino.CurveClosestPoint(attrs(j),arrVTXS(agentsOnMesh(i)))
					arrAttractors(j) = Rhino.EvaluateCurve(attrs(j),dblParam)
				End If
			Next
			Dim ClosestAttIndex : ClosestAttIndex = Rhino.PointArrayClosestPoint(arrAttractors,arrVTXS(agentsOnMesh(i)))
			' make a vector from arrVTXS(agentsOnMesh(i)) towards the closest attractor arrAttractors(ClosestAttIndex)
			Dim arrVector : arrVector = Rhino.VectorCreate(arrAttractors(ClosestAttIndex), arrVTXS(agentsOnMesh(i)))
			arrVector = Rhino.VectorUnitize(arrVector)
			arrVector = Rhino.VectorScale(arrVector, dblStep)
			' add the vector to the arrVTXS(agentsOnMesh(i)) and store it in arrNEWVTXS(agentsOnMesh(i))
			arrNEWVTXS(agentsOnMesh(i)) = Rhino.VectorAdd(arrNEWVTXS(agentsOnMesh(i)), arrVector)	
			' MOVE THE AGENT      --------------------------------------------------------------------------
			' get the adjacent mesh vtx indexes from MeshVtxAdjacentVtxs
			Dim arrNeighborIndexes : arrNeighborIndexes = MeshVtxAdjacentVtxs (strMesh, agentsOnMesh(i), False, False)
			' choose which vtx to "move" to, and store it in agentsOnMesh(i)
			agentsOnMesh(i) = arrNeighborIndexes(Int(rnd*Ubound(arrNeighborIndexes)+0.5))
			' end for loop
		Next
		'	add a new mesh in the document using arrNEWVTXS
		Dim strNewMesh : strNewMesh = Rhino.AddMesh(arrNEWVTXS,arrFaceVertices)
		Call RenderAgentsOnMesh(strNewMesh, agentsOnMesh)
		'	delete the old one 
		Call rhino.DeleteObject(strMesh)
		'	replace the ID of old mesh with the NEW ID
		strMesh = strNewMesh
	Loop
End Sub

Function MeshVtxAdjacentVtxs (strMesh, index, blnAbsolutConnections, blnCreate)
	' MeshVtxAdjacentVtxs
	' finds the adjecent vertices on a mesh for a given index of a vertex.
	' written by Ezio Blasetti. Last Revision 071607.
	'
	' Syntax
	' MeshVtxAdjacentVtxs (strMesh, index, blnAbsolutConnections, blnCreate)
	' 
	' Parameters
	' strMesh                       Required. String.  The identifier of a mesh object.
	' index                         Required. Integer. The index of a vertex object inside the array returned from Rhino.MeshVertices method.
	'                                                  Use Rhino.MeshVertexCount for the Ubound of that array.
	' blnAbsolutConnections         Required. Boolean. If True only the end points of the adjacent edges will be returned.
	'                                                  Note, if false, all the vertices of the adjacent faces will be returned.
	' blnCreate                     Required. Boolean. Create the adjacent points. If false, points are not created.
	'
	' Returns
	' Array                         If blnCreate is equal to True , an array containing 3D adjacent points if successful.
	' Array                         If blnCreate is equal to False, an array containing the indexes of the adjacent vetrices if successful.
	' Null                          If not successful, or on error.
	'
	' 
	' Example
	' dim strObject       : strObject        = Rhino.GetObject("Select the mesh", 32)
	' dim intRndVtxIndex  : intRndVtxIndex   = 0
	' dim arr             : arr              = MeshVtxAdjacentVtxs (strObject, intRndVtxIndex, VbTrue, VbTrue)
	'
	'
	MeshVtxAdjacentVtxs = Null
	If Not Rhino.IsMesh(strMesh) Then Exit Function
	If Not IsNumeric(index)      Then Exit Function
	index=Int(index)
	Dim arrVertices     : arrVertices     = Rhino.MeshVertices    (strMesh)
	Dim arrFaceVertices : arrFaceVertices = Rhino.MeshFaceVertices(strMesh)
	If Not IsArray(arrVertices)     Then Exit Function
	If Not IsArray(arrFaceVertices) Then Exit Function
	Dim intCount   : intCount = 0
	Dim arrVtxIndex, arrFace, blnIsAdjacent
	Dim arrAdjacentVtxs()
	For Each arrFace In arrFaceVertices
		blnIsAdjacent = VbFalse
		For Each arrVtxIndex In arrFace
			If arrVtxIndex = index Then
				blnIsAdjacent = VbTrue
			End If
		Next
		If blnIsAdjacent Then
			If blnAbsolutConnections Then
				If arrFace(2)=arrFace(3) Then
					For Each arrVtxIndex In arrFace
						If Not arrVtxIndex = index Then
							ReDim Preserve arrAdjacentVtxs(intCount)
							arrAdjacentVtxs(intCount) = arrVtxIndex
							intCount = intCount + 1
						End If
					Next
				Else
					If index = arrFace(0) Then
						ReDim Preserve arrAdjacentVtxs(intCount)
						arrAdjacentVtxs(intCount) = arrFace(3)
						intCount = intCount + 1
						ReDim Preserve arrAdjacentVtxs(intCount)
						arrAdjacentVtxs(intCount) = arrFace(1)
						intCount = intCount + 1
					ElseIf index = arrFace(1) Then
						ReDim Preserve arrAdjacentVtxs(intCount)
						arrAdjacentVtxs(intCount) = arrFace(0)
						intCount = intCount + 1
						ReDim Preserve arrAdjacentVtxs(intCount)
						arrAdjacentVtxs(intCount) = arrFace(2)
						intCount = intCount + 1
					ElseIf index = arrFace(2) Then
						ReDim Preserve arrAdjacentVtxs(intCount)
						arrAdjacentVtxs(intCount) = arrFace(1)
						intCount = intCount + 1
						ReDim Preserve arrAdjacentVtxs(intCount)
						arrAdjacentVtxs(intCount) = arrFace(3)
						intCount = intCount + 1
					ElseIf index = arrFace(3) Then
						ReDim Preserve arrAdjacentVtxs(intCount)
						arrAdjacentVtxs(intCount) = arrFace(2)
						intCount = intCount + 1
						ReDim Preserve arrAdjacentVtxs(intCount)
						arrAdjacentVtxs(intCount) = arrFace(0)
						intCount = intCount + 1
					End If
				End If
			Else
				For Each arrVtxIndex In arrFace
					If Not arrVtxIndex = index Then
						ReDim Preserve arrAdjacentVtxs(intCount)
						arrAdjacentVtxs(intCount) = arrVtxIndex
						intCount = intCount + 1
					End If
				Next
			End If
		End If
	Next
	If Not IsArray(arrAdjacentVtxs) Then Exit Function
	Dim arrOrderAdjacentVtxs : arrOrderAdjacentVtxs = Rhino.CullDuplicateNumbers (arrAdjacentVtxs)
	If Not blnCreate Then
		MeshVtxAdjacentVtxs = arrOrderAdjacentVtxs
		Exit Function
	Else
		Dim arrStrPts : arrStrPts = arrOrderAdjacentVtxs
		intCount = 0
		For Each arrVtxIndex In arrOrderAdjacentVtxs
			Call rhino.AddPoint ( arrVertices(arrVtxIndex) )
			arrStrPts(intCount) = arrVertices(arrVtxIndex)
			intCount = intCount + 1
		Next
		MeshVtxAdjacentVtxs = arrStrPts
	End If
End Function

Sub RenderAgentsOnMesh(strMesh, arrIndexes)
	Dim arrVertices     : arrVertices     = Rhino.MeshVertices(strMesh)
	ReDim arrVertexColors(Ubound(arrVertices))
	Dim i
	For i=0 To Ubound(arrVertexColors)
		arrVertexColors(i) = RGB(255,255,255)
	Next
	For i=0 To Ubound(arrIndexes)
		arrVertexColors(arrIndexes(i)) = RGB(0,0,0)
	Next
	Call Rhino.MeshVertexColors (strMesh , arrVertexColors)
End Sub</description>
		
		<excerpt></excerpt>

		<!--<wfw:commentRss></wfw:commentRss>-->

		<media:thumbnail url="http://payload.cargocollective.com/1/0/9123/1033655/prt_1297184799.jpg" />

	</item>
		
		
	<item>
		<title>Colors From Attractors</title>
				
		<link>http://code.algorithmicdesign.net/Colors-From-Attractors</link>

		<comments>http://code.algorithmicdesign.net/following/code.algorithmicdesign.net/Colors-From-Attractors</comments>

		<pubDate>Tue, 07 Feb 2012 13:34:47 +0000</pubDate>

		<dc:creator>algorithmic design</dc:creator>
		
		<category><![CDATA[rhinoscript]]></category>

		<guid isPermaLink="false">1035135</guid>

		<description>&#60;img src="http://payload.cargocollective.com/1/0/9123/1035135/addColors_banner_1000.jpg" width="1000" height="200" width_o="1000" height_o="200" src_o="http://payload.cargocollective.com/1/0/9123/1035135/addColors_banner_o.jpg" data-mid="4970860"  border="0" align="left"/&#62;Paint Objects Colors &#38; Material By Distance From R, G, B AttractorsOption Explicit
'Script written by Ezio Blasetti
'Script copyrighted by algorithmicdesign.net
'Script version Tuesday, February 08, 2011 4:29:33 PM
Call Main()
Sub Main()
	'ask the user to select the components (objects) to paint
	Dim arrObjects : arrObjects = Rhino.GetObjects("please select the objects to paint")
	'get all the point and curve OBJECTS from the layer "R","G","B" and store them in arrays
	Dim arrAttrR : arrAttrR = PointsAndCrvsFromLayer("R")
	Dim arrAttrG : arrAttrG = PointsAndCrvsFromLayer("G")
	Dim arrAttrB : arrAttrB = PointsAndCrvsFromLayer("B")
	Dim i
	If IsArray(arrAttrR) Then
		ReDim arrAttrRDists(Ubound(arrAttrR))
		For i=0 To Ubound(arrAttrR)
			arrAttrRDists(i) = GetMinAndMaxDistanceToAttrFromObjects(arrAttrR(i),arrObjects)
		Next
	End If
	If IsArray(arrAttrG) Then
		ReDim arrAttrGDists(Ubound(arrAttrG))
		For i=0 To Ubound(arrAttrG)
			arrAttrGDists(i) = GetMinAndMaxDistanceToAttrFromObjects(arrAttrG(i),arrObjects)
		Next
	End If
	If IsArray(arrAttrB) Then
		ReDim arrAttrBDists(Ubound(arrAttrB))
		For i=0 To Ubound(arrAttrB)
			arrAttrBDists(i) = GetMinAndMaxDistanceToAttrFromObjects(arrAttrB(i),arrObjects)
		Next
	End If
	'loop through your (objects)
	Dim k, dblDistance
	For i=0 To Ubound(arrObjects)
		Dim Rvalue : Rvalue = 0
		Dim Gvalue : Gvalue = 0
		Dim Bvalue : Bvalue = 0
		If IsArray(arrAttrR) Then
			Rvalue = Get0_255ValueFromDist2Attractors(arrAttrR, arrAttrRDists, arrObjects(i))
		End If
		If IsArray(arrAttrG) Then
			Gvalue = Get0_255ValueFromDist2Attractors(arrAttrG, arrAttrGDists, arrObjects(i))
		End If
		If IsArray(arrAttrB) Then
			Bvalue = Get0_255ValueFromDist2Attractors(arrAttrB, arrAttrBDists, arrObjects(i))
		End If
		Call Rhino.ObjectColor (arrObjects(i), RGB(Rvalue,Gvalue,Bvalue))
		Dim intIndex : intIndex = Rhino.AddMaterialToObject (arrObjects(i))
		Call Rhino.MaterialColor (intIndex , RGB(Rvalue,Gvalue,Bvalue))
	Next
End Sub

Function CenterOfBoundingBox(arrObjects)
	Dim arrBBox : arrBBox = Rhino.BoundingBox (arrObjects)
	Dim XofCenter : XofCenter = (arrBBox(0)(0) + arrBBox(1)(0))/2
	Dim YofCenter : YofCenter = (arrBBox(0)(1) + arrBBox(3)(1))/2
	Dim ZofCenter : ZofCenter = (arrBBox(0)(2) + arrBBox(4)(2))/2
	CenterOfBoundingBox = array( XofCenter, YofCenter, ZofCenter)
End Function

Function PointsAndCrvsFromLayer(strLayer)
	PointsAndCrvsFromLayer = Null
	Dim arrObjects : arrObjects = Rhino.ObjectsByLayer (strLayer)
	If IsArray(arrObjects) Then
		'define a new variable (array) dynamic with size -1
		ReDim arrReturn(-1)
		Dim i
		'loop through all the Ids of the objects
		For i=0 To Ubound(arrObjects)
			If Rhino.Ispoint(arrObjects(i)) Then
				ReDim Preserve arrReturn(Ubound(arrReturn)+1)
				arrReturn(Ubound(arrReturn)) = arrObjects(i)
			ElseIf Rhino.IsCurve(arrObjects(i)) Then
				ReDim Preserve arrReturn(Ubound(arrReturn)+1)
				arrReturn(Ubound(arrReturn)) = arrObjects(i)
			End If
			' end the loop
		Next
		PointsAndCrvsFromLayer = arrReturn
	End If
End Function

Function GetMinAndMaxDistanceToAttrFromObjects(strAttr,arrObjects)
	GetMinAndMaxDistanceToAttrFromObjects = Null
	'If Not Rhino.IsPoint(strAttr) Or Rhino.IsCurve(strAttr) Then Exit Function
	If Not IsArray(arrObjects) Then Exit Function
	
	Dim dblMinDistance : dblMinDistance = 5000000 
	Dim dblMaxDistance : dblMaxDistance = -1
	Dim i
	For i=0 To Ubound(arrObjects)
		Dim dblDistance 
		If Rhino.IsPoint(strAttr) Then
			dblDistance = Rhino.Distance(CenterOfBoundingBox(arrObjects(i)),Rhino.PointCoordinates(strAttr))
		Else
			Dim dblParam : dblParam = Rhino.CurveClosestPoint(strAttr, CenterOfBoundingBox(arrObjects(i)))
			dblDistance = Rhino.Distance(CenterOfBoundingBox(arrObjects(i)),Rhino.EvaluateCurve(strAttr,dblParam))
		End If
		
		If dblDistance &#60; dblMinDistance Then
			dblMinDistance = dblDistance
		End If
		If dblDistance &#62; dblMaxDistance Then
			dblMaxDistance = dblDistance
		End If
	Next
	GetMinAndMaxDistanceToAttrFromObjects = array(dblMinDistance,dblMaxDistance)
End Function

Function Get0_255ValueFromDist2Attractors(arrAttrs, arrMinMaxDist, strObject)
	Get0_255ValueFromDist2Attractors = Null
	Dim intReturn : intReturn = 0
	Dim arrCenter : arrCenter = CenterOfBoundingBox(strObject)
	Dim i
	For i=0 To Ubound(arrAttrs)
		Dim dblDistance 
		If Rhino.IsPoint(arrAttrs(i)) Then
			dblDistance = Rhino.Distance(arrCenter,Rhino.PointCoordinates(arrAttrs(i)))
		Else
			Dim dblParam : dblParam = Rhino.CurveClosestPoint(arrAttrs(i), arrCenter)
			dblDistance = Rhino.Distance(arrCenter,Rhino.EvaluateCurve(arrAttrs(i),dblParam))
		End If
		intReturn = intReturn + ((arrMinMaxDist(i)(1)-dblDistance)/(arrMinMaxDist(i)(1)-arrMinMaxDist(i)(0)))*255
	Next
	intReturn = intReturn/(Ubound(arrAttrs)+1)
	Get0_255ValueFromDist2Attractors = intReturn
End Function</description>
		
		<excerpt></excerpt>

		<!--<wfw:commentRss></wfw:commentRss>-->

		<media:thumbnail url="http://payload.cargocollective.com/1/0/9123/1035135/prt_1297206689.jpg" />

	</item>
		
	</channel>
</rss>
