<?xml version="1.0" encoding="UTF-8"?>
<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:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>supermanoeuvre</title>
	<atom:link href="http://www.supermanoeuvre.com/blog/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.supermanoeuvre.com/blog</link>
	<description>resource blog</description>
	<lastBuildDate>Wed, 01 Sep 2010 21:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Living Morphologies &#8211; Housing Precedent Lists</title>
		<link>http://www.supermanoeuvre.com/blog/?p=958</link>
		<comments>http://www.supermanoeuvre.com/blog/?p=958#comments</comments>
		<pubDate>Wed, 01 Sep 2010 11:01:53 +0000</pubDate>
		<dc:creator>iainmaxwell</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.supermanoeuvre.com/blog/?p=958</guid>
		<description><![CDATA[
Habitat ‘67 (1967), Moshe Safdie, Montreal, Canada
Mountain Dwellings (2008), Bjarke Ingels Group, Ørestad
Mirador Housing (2005), MVRDV, Madrid, Spain
Gifu Kitagata Housing (2000), SANAA, Gifu, Japan
Eda Apartments (2002), SANAA, Kanagawa, Japan.
Unité d’Habitation (1952), Le Corbusier, Marseille, France
Walden 7 (1974), Ricardo Bofil, Barcelona, Spain
Kanchanjunga Apts (1983), Charles Correa, Mumbai, India
Maharashtra Housing (1999), Charles Correa,Maharashtra, India
Indian Institute of Management [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/04/livingMorphologies.jpg" alt="livingMorphologies" title="livingMorphologies" width="600" height="234" class="alignleft size-full wp-image-872" /></p>
<p><strong>Habitat ‘67</strong> (1967), Moshe Safdie, Montreal, Canada<br />
<strong>Mountain Dwellings (2008)</strong>, Bjarke Ingels Group, Ørestad<br />
<strong>Mirador Housing (2005)</strong>, MVRDV, Madrid, Spain<br />
<strong>Gifu Kitagata Housing (2000)</strong>, SANAA, Gifu, Japan<br />
<strong>Eda Apartments (2002)</strong>, SANAA, Kanagawa, Japan.<br />
<strong>Unité d’Habitation (1952)</strong>, Le Corbusier, Marseille, France<br />
<strong>Walden 7 (1974)</strong>, Ricardo Bofil, Barcelona, Spain<br />
<strong>Kanchanjunga Apts (1983)</strong>, Charles Correa, Mumbai, India<br />
<strong>Maharashtra Housing (1999)</strong>, Charles Correa,Maharashtra, India<br />
<strong>Indian Institute of Management (1962)</strong>, Louis I. Kahn, Ahmedhabad, India<br />
<strong>MIT Simmons Hall (2004)</strong>, Steven Holl, Boston, USA<br />
<strong>Fukuoka Housing (1991)</strong>, Steven Holl, Fukuoka, Japan<br />
<strong>Barcom Avenue Housing (2004)</strong>, Engelen Moore, Darlinghurst, Sydney<br />
<strong>Rue des Suisses (2000)</strong>, Herzog &#038; de Meuron, Paris, France<br />
<strong>Ivry Sur Seine (1980)</strong>, Jean Renaudie, Paris, France<br />
<strong>Trellick Tower (1972)</strong>, Erno Goldfinger, London, U.K.<br />
<strong>Baumhaus in Helmond (1984)</strong>, Piet Blom, Rotterdam, The Netherlands.<br />
<strong>Nexus World Housing (1991)</strong>, OMA, Fukuoka, Japan.<br />
<strong>Carabanchel Apartments (2007)</strong>, Dosmasuno Arquitectos, Madrid, Spain.<br />
<strong>Carabanchel Apartments (2007)</strong>, Foreign Office Architects (FOA), Madrid, Spain.</p>
<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/04/sanaa.jpg" alt="sanaa" title="sanaa" width="600" height="238" class="alignleft size-full wp-image-871" /></p>
]]></content:encoded>
			<wfw:commentRss>http://www.supermanoeuvre.com/blog/?feed=rss2&amp;p=958</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Geometric Transformations</title>
		<link>http://www.supermanoeuvre.com/blog/?p=940</link>
		<comments>http://www.supermanoeuvre.com/blog/?p=940#comments</comments>
		<pubDate>Tue, 31 Aug 2010 10:47:32 +0000</pubDate>
		<dc:creator>iainmaxwell</dc:creator>
				<category><![CDATA[RhinoScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.supermanoeuvre.com/blog/?p=940</guid>
		<description><![CDATA[
 Using Orient 3D 

&#160;
Option Explicit
'Script written by maxi
' do this to a welded mesh box

Call Main()
Sub Main()
&#160;
	'------------------------------------------------------------------
	'USER INPUTS
	Dim strStartObj : strStartObj =  rhino.getObject(&#34;gimme BOX&#34;, 32)
	If isNull(strStartObj) Then Exit Sub
&#160;
	'------------------------------------------------------------------
	'SCRIPT	
	' get the vertices of the welded mesh object
	Dim arrVertices : arrVertices = Rhino.MeshVertices (strStartObj) 
&#160;
	' apply a orient3D and copy!
	Dim arrPlaneStart   : [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/crystalTransform.jpg" alt="crystalTransform" title="crystalTransform" width="600" height="404" class="alignleft size-full wp-image-944" /></p>
<p><strong> Using Orient 3D </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #008000;">'Script written by maxi
</span><span style="color: #008000;">' do this to a welded mesh box
</span>
<span style="color: #000080;">Call</span> Main()
<span style="color: #000080;">Sub</span> Main()
&nbsp;
	<span style="color: #008000;">'------------------------------------------------------------------
</span>	<span style="color: #008000;">'USER INPUTS
</span>	<span style="color: #000080;">Dim</span> strStartObj : strStartObj =  rhino.getObject(&quot;gimme BOX&quot;, 32)
	<span style="color: #000080;">If</span> isNull(strStartObj) <span style="color: #000080;">Then</span> <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
&nbsp;
	<span style="color: #008000;">'------------------------------------------------------------------
</span>	<span style="color: #008000;">'SCRIPT	
</span>	<span style="color: #008000;">' get the vertices of the welded mesh object
</span>	<span style="color: #000080;">Dim</span> arrVertices : arrVertices = Rhino.MeshVertices (strStartObj) 
&nbsp;
	<span style="color: #008000;">' apply a orient3D and copy!
</span>	<span style="color: #000080;">Dim</span> arrPlaneStart   : arrPlaneStart   = Array( arrVertices(0), arrVertices(2) )
	<span style="color: #000080;">Dim</span> arrPlaneTargets : arrPlaneTargets = Array( Array(arrVertices(3), arrVertices(7)),  Array(arrVertices(2), arrVertices(5)) )	
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i =0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrPlaneTargets)
		<span style="color: #000080;">Call</span> rhino.OrientObject(strStartObj, arrPlaneStart, arrPlaneTargets(i), 1+2)
	<span style="color: #000080;">Next</span>	
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/attDistortion.jpg" alt="attDistortion" title="attDistortion" width="600" height="345" class="alignleft size-full wp-image-954" /></p>
<p><strong>Attractor Based Transformations</strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #008000;">'Script written by maxi@supermanoeuvre.com
</span>
<span style="color: #000080;">Call</span> Main()
&nbsp;
<span style="color: #000080;">Sub</span> Main()
&nbsp;
	<span style="color: #008000;">'----------------------------------------------------------
</span>	<span style="color: #008000;">' USER INPUTS
</span>	<span style="color: #000080;">Dim</span> strMesh : strMesh = rhino.getObject(&quot;gimme MESH&quot;, 32)
	<span style="color: #000080;">If</span> isNull(strMesh) <span style="color: #000080;">Then</span> <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
&nbsp;
	<span style="color: #000080;">Dim</span> strAtts : strAtts = rhino.getObjects(&quot;gimme attractor POINT objects&quot;, 1)
	<span style="color: #000080;">If</span> isNull(strAtts) <span style="color: #000080;">Then</span> <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
&nbsp;
	<span style="color: #000080;">Dim</span> dblAttractionScale : dblAttractionScale = 50.0
&nbsp;
	<span style="color: #008000;">'----------------------------------------------------------
</span>	<span style="color: #008000;">' SCRIPT PROPER
</span>	
	<span style="color: #000080;">Dim</span> arrMeshVerts : arrMeshVerts = rhino.MeshVertices(strMesh)
	<span style="color: #000080;">Dim</span> arrMeshFaces : arrMeshFaces = Rhino.MeshFaceVertices(strMesh)
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">Dim</span> arrPtClosestAtt, arrVecBetween, dblLen
	<span style="color: #000080;">Dim</span> arrVecNorm, arrVecScaled, arrPtNew
	<span style="color: #000080;">Dim</span> arrNewMeshVerts()
&nbsp;
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrMeshVerts)
		<span style="color: #008000;">' find the closest attractor
</span>		arrPtClosestAtt = getClosestAttractorLocation(arrMeshVerts(i), strAtts)
		<span style="color: #008000;">' make a vector between current location and attractor
</span>		arrVecBetween   = rhino.VectorSubtract(arrPtClosestAtt, arrMeshVerts(i))		
		<span style="color: #008000;">' Do some scaling based on distance, etc....
</span>		dblLen          = rhino.vectorLength(arrVecBetween)
		arrVecNorm      = Rhino.VectorUnitize(arrVecBetween)
		arrVecScaled    = rhino.VectorScale( arrVecNorm, (1/dblLen) * dblAttractionScale )
		<span style="color: #008000;">' move back relatice to starting position
</span>		arrPtNew        = rhino.pointAdd(arrVecScaled, arrMeshVerts(i))
		<span style="color: #000080;">ReDim</span> <span style="color: #000080;">Preserve</span> arrNewMeshVerts(i)
		arrNewMeshVerts(i) = arrPtNew
	<span style="color: #000080;">Next</span>
&nbsp;
	<span style="color: #000080;">Call</span> rhino.AddMesh(arrNewMeshVerts, arrMeshFaces)
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #000080;">Function</span> getClosestAttractorLocation(TESTPT, STRATTS)
&nbsp;
	getClosestAttractorLocation = Null
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">Dim</span> arrPtTest, distClosest, arrPtClosest, distBetween
&nbsp;
	distClosest = 99999999
&nbsp;
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(STRATTS)
		arrPtTest   = rhino.PointCoordinates(STRATTS(i))
		distBetween = rhino.Distance(arrPtTest, TESTPT)
		<span style="color: #000080;">If</span> distBetween &lt; distClosest <span style="color: #000080;">Then</span>
			distClosest  = distBetween
			arrPtClosest = arrPtTest
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	<span style="color: #000080;">Next</span>
&nbsp;
	getClosestAttractorLocation = arrPtClosest
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/axisTransformations2.jpg" alt="axisTransformations" title="axisTransformations" width="600" height="350" class="alignleft size-full wp-image-952" /></p>
<p><strong>Transformation Axis </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Call</span> Main()
&nbsp;
<span style="color: #000080;">Sub</span> Main()
&nbsp;
	<span style="color: #008000;">'---------------------------------------------------------------------
</span>	<span style="color: #008000;">' USER INPUTS
</span>	<span style="color: #000080;">Dim</span> strObj : strObj = rhino.getObject(&quot;gimme POLYSURFACE primitive&quot;, 4+8+16)
	<span style="color: #000080;">If</span> isNull(strObj) <span style="color: #000080;">Then</span> <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
&nbsp;
	<span style="color: #000080;">Dim</span> strAxisCrv : strAxisCrv = rhino.GetObject(&quot;gimme axis CURVE&quot;, 4)
	<span style="color: #000080;">If</span> isNull(strAxisCrv) <span style="color: #000080;">Then</span> <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
&nbsp;
	<span style="color: #000080;">Dim</span> numGens : numGens = 6 
&nbsp;
	<span style="color: #008000;">'---------------------------------------------------------------------
</span>	<span style="color: #008000;">' SCRIPT BODY
</span>	
	<span style="color: #008000;">'------------------- DEFINE THE ROTATION AXIS
</span>	<span style="color: #000080;">Dim</span> arrAxis01Start : arrAxis01Start = rhino.CurveStartPoint(strAxisCrv)
	<span style="color: #000080;">Dim</span> arrAxis01End   : arrAxis01End   = rhino.CurveEndPoint(strAxisCrv)
&nbsp;
	<span style="color: #008000;">'------------------- DEFINE THE ROTATION PARAMETER
</span>	<span style="color: #000080;">Dim</span> arrAxis01      : arrAxis01   = rhino.VectorSubtract(arrAxis01End, arrAxis01Start)
	<span style="color: #000080;">Dim</span> dblRotParam    : dblRotParam = 360/numGens
&nbsp;
	<span style="color: #008000;">'------------------- PERFORM THE ROTATIONS
</span>	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 1 <span style="color: #000080;">To</span> numGens
		<span style="color: #000080;">Call</span> rhino.RotateObject(strObj, arrAxis01Start, i*dblRotParam, arrAxis01, <span style="color: #000080;">True</span>)
	<span style="color: #000080;">Next</span>	
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.supermanoeuvre.com/blog/?feed=rss2&amp;p=940</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quickstart Introduction to Rhinoscript</title>
		<link>http://www.supermanoeuvre.com/blog/?p=918</link>
		<comments>http://www.supermanoeuvre.com/blog/?p=918#comments</comments>
		<pubDate>Tue, 31 Aug 2010 10:19:16 +0000</pubDate>
		<dc:creator>iainmaxwell</dc:creator>
				<category><![CDATA[RhinoScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.supermanoeuvre.com/blog/?p=918</guid>
		<description><![CDATA[
EXERCISE 01: Variables &#038; Data Types 

&#160;
Option Explicit
&#160;
Call Main()
&#160;
Sub Main()
&#160;
	' DATA TYPES AND VARIABLES
	
	' INTEGER -- whole numbers!
	Dim intNumber    : intNumebr    = 100
	Dim intNegNumber : intNegNumebr = -154
&#160;
	' DOUBLE or FLOAT or REAL -- precision
	Dim dblValue    : dblValue    = 5.0234
	Dim dblNegValue : dblNegValue [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2009/04/rhinotutes.jpg" alt="rhinotutes" title="rhinotutes" width="600" height="154" class="alignleft size-full wp-image-19" /></p>
<p><strong>EXERCISE 01: Variables &#038; Data Types </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Call</span> Main()
&nbsp;
<span style="color: #000080;">Sub</span> Main()
&nbsp;
	<span style="color: #008000;">' DATA TYPES AND VARIABLES
</span>	
	<span style="color: #008000;">' INTEGER -- whole numbers!
</span>	<span style="color: #000080;">Dim</span> intNumber    : intNumebr    = 100
	<span style="color: #000080;">Dim</span> intNegNumber : intNegNumebr = -154
&nbsp;
	<span style="color: #008000;">' DOUBLE or FLOAT or REAL -- precision
</span>	<span style="color: #000080;">Dim</span> dblValue    : dblValue    = 5.0234
	<span style="color: #000080;">Dim</span> dblNegValue : dblNegValue = -1753.0234
&nbsp;
	<span style="color: #008000;">' STRING -- no mathematical function can be performed on a string!
</span>	<span style="color: #000080;">Dim</span> strName1 : strName1 = &quot;MAX&quot;
	<span style="color: #000080;">Dim</span> strName2 : strName2 = &quot;max2x0011xx$%0011&quot;
&nbsp;
	<span style="color: #008000;">' BOOLEAN - TRUE or FALSE
</span>	<span style="color: #000080;">Dim</span> blnAnswer : blnAnswer = <span style="color: #000080;">True</span>
	<span style="color: #000080;">Dim</span> blnAnswer : blnAnswer = <span style="color: #000080;">False</span>	
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p><strong>EXERCISE 02: Custom Functions </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Call</span> Main()
&nbsp;
<span style="color: #000080;">Sub</span> Main()
&nbsp;
	<span style="color: #008000;">' SOME RHINO FUNCTIONS 
</span>	<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">print</span>(&quot;hello world&quot;)                          <span style="color: #008000;">' simple print statement 
</span>	<span style="color: #000080;">Call</span> rhino.AddSphere( Array(0,0,0), 10 )                 <span style="color: #008000;">' a sphere 
</span>	<span style="color: #000080;">Call</span> rhino.addPoint( Array(rnd*100,rnd*100, rnd*100) )   <span style="color: #008000;">' a point randomly in space
</span>		
	<span style="color: #008000;">' SOME RHINO FUNCTIONS USED TO ASSIGN A VARIABLE
</span>	<span style="color: #000080;">Dim</span> strMyShape	
	strMyShape = rhino.AddSphere( Array(25,25,0), 25 )
&nbsp;
	<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">print</span>(&quot;The rhino <span style="color: #000080;">object</span> identifier of strMyShape <span style="color: #000080;">is</span> &quot; + strMyShape)	
&nbsp;
	<span style="color: #008000;">' OUR FIRST CUSTOM FUNCTION
</span>	<span style="color: #000080;">Dim</span> intMyAge    : intMyAge    = 34
	<span style="color: #000080;">Dim</span> dblMyHeight : dblMyHeight = 1.85
	<span style="color: #000080;">Dim</span> dblResult   : dblResult   = customTransformation(intMyAge, dblMyHeight)
	<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">print</span>( &quot;The result of my age multiplied by my height <span style="color: #000080;">is</span> &quot; + <span style="color: #000080;">CStr</span>(dblResult) )
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
&nbsp;
<span style="color: #000080;">Function</span> customCalculator(VAL00, VAL01)
&nbsp;
	customCalculator = Null
&nbsp;
	<span style="color: #000080;">Dim</span> answer
&nbsp;
	answer = VAL00 + VAL01
&nbsp;
	customCalculator = answer
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
&nbsp;
<span style="color: #000080;">Function</span> customTransformation(VAL00, VAL01)
&nbsp;
	customTransformation = Null
&nbsp;
	<span style="color: #000080;">Dim</span> answer
&nbsp;
	answer = 1 / Sqr(VAL00 + VAL01)
&nbsp;
	customTransformation = answer
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

<p><strong>EXERCISE 03: Iteration </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Call</span> Main()
&nbsp;
<span style="color: #000080;">Sub</span> Main()
&nbsp;
	<span style="color: #008000;">' A simple loop
</span>	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> 10
		<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">print</span>(&quot;number &quot; &amp; i &amp; &quot; says hello!&quot;)
	<span style="color: #000080;">Next</span>
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/movingDot.jpg" alt="movingDot" title="movingDot" width="600" height="300" class="alignleft size-full wp-image-928" /></p>
<p><strong>EXERCISE 04: Basic Geometry &#8212; Iterative object copying </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Call</span> Main()
<span style="color: #000080;">Sub</span> Main()	
&nbsp;
	<span style="color: #008000;">'-----------------------------------------------------------
</span>	<span style="color: #008000;">' USER INPUT	
</span>	
	<span style="color: #008000;">' WHAT TO COPY?
</span>	<span style="color: #000080;">Dim</span> strBox : strBox = rhino.getObject(&quot;gimme BOX dude&quot;, 16) 
	<span style="color: #000080;">If</span> isNull(strBox) <span style="color: #000080;">Then</span> <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
&nbsp;
	<span style="color: #008000;">' HOW MANY TO MAKE?
</span>	<span style="color: #000080;">Dim</span> numBoxes : numBoxes = 10
&nbsp;
	<span style="color: #008000;">' HOW FAR TO MOVE?
</span>	<span style="color: #000080;">Dim</span> dblTransation : dblTransation = 10
&nbsp;
	<span style="color: #008000;">'-----------------------------------------------------------
</span>	<span style="color: #008000;">' SCRIPT ROUTINE
</span>	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> numBoxes
		<span style="color: #000080;">Call</span> rhino.copyObject( strBox, Array(0,0,0), Array(0,0,i*dblTransation) )
	<span style="color: #000080;">Next</span>
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/rotation.jpg" alt="rotation" title="rotation" width="600" height="300" class="alignleft size-full wp-image-927" /></p>
<p><strong>EXERCISE 05: Basic Geometry &#8212; Iterative Geometric Transformations </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Call</span> Main()
&nbsp;
<span style="color: #000080;">Sub</span> Main()	
&nbsp;
	<span style="color: #008000;">'-----------------------------------------------------------
</span>	<span style="color: #008000;">' USER INPUT	
</span>	
	<span style="color: #008000;">' WHAT TO COPY?
</span>	<span style="color: #000080;">Dim</span> strBox : strBox = rhino.getObject(&quot;gimme BOX dude&quot;, 16) 
	<span style="color: #000080;">If</span> isNull(strBox) <span style="color: #000080;">Then</span> <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
&nbsp;
	<span style="color: #008000;">' HOW MANY TO MAKE?
</span>	<span style="color: #000080;">Dim</span> numBoxes : numBoxes = 10
&nbsp;
	<span style="color: #008000;">' HOW FAR TO MOVE?
</span>	<span style="color: #000080;">Dim</span> dblTransation : dblTransation = 10
&nbsp;
	<span style="color: #008000;">' HOW MUCH TO ROTATE NEW BOX BY?
</span>	<span style="color: #000080;">Dim</span> dblRotVal : dblRotVal = 5
&nbsp;
&nbsp;
	<span style="color: #008000;">'-----------------------------------------------------------
</span>	<span style="color: #008000;">' SCRIPT ROUTINE
</span>	<span style="color: #000080;">Call</span> rhino.enableRedraw(<span style="color: #000080;">False</span>)
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">Dim</span> strNewBox
&nbsp;
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> numBoxes
		strNewBox = rhino.copyObject( strBox, Array(0,0,0), Array(0,0,i*dblTransation) )
		<span style="color: #000080;">Call</span> rhino.RotateObject( strNewBox, Array(0,0,0), i*dblRotVal )
	<span style="color: #000080;">Next</span>
&nbsp;
	<span style="color: #000080;">Call</span> rhino.enableRedraw(<span style="color: #000080;">True</span>)
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p><strong>EXERCISE 06: Arrays (Part 01 &#8212; Static Array lists) </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Call</span> Main()
&nbsp;
<span style="color: #000080;">Sub</span> Main()
&nbsp;
	<span style="color: #000080;">Dim</span> arrShoppingList : arrShoppingList = Array(&quot;Milk&quot;, &quot;Eggs&quot;, &quot;Bread&quot;, &quot;Chocolate&quot;, &quot;Ham&quot;)
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrShoppingList)
		<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">Print</span>( &quot;Item number &quot; &amp; i &amp; &quot; <span style="color: #000080;">is</span> &quot; &amp; arrShoppingList(i) )
	<span style="color: #000080;">Next</span>
&nbsp;
	<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">Print</span>( &quot;result <span style="color: #000080;">is</span> &quot; &amp; getItem(arrShoppingList, 3) )
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
&nbsp;
<span style="color: #000080;">Function</span> getItem(<span style="color: #000080;">ByVal</span> LIST, <span style="color: #000080;">ByVal</span> INDEX)
&nbsp;
	getItem = null
&nbsp;
	<span style="color: #000080;">Dim</span> result : result = LIST(INDEX)
&nbsp;
	getItem = result
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

<p><strong>EXERCISE 07: Arrays (Part 02 &#8212; Two-Dimensional Arrays) </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
&nbsp;
<span style="color: #000080;">Call</span> Main()
&nbsp;
<span style="color: #000080;">Sub</span> Main()
&nbsp;
	<span style="color: #008000;">' AN ARRAY OF STRINGS
</span>	<span style="color: #000080;">Dim</span> arrGroceryList  : arrGroceryList  = Array(&quot;Milk&quot;, &quot;Eggs&quot;, &quot;Bread&quot;, &quot;Chocolate&quot;, &quot;Ham&quot;)
&nbsp;
	<span style="color: #008000;">' ANOTHER ARRAY OF STRINGS
</span>	<span style="color: #000080;">Dim</span> arrWishList     : arrWishList     = Array(&quot;Car&quot;, &quot;Boat&quot;, &quot;Aeroplane&quot;, &quot;Jacket&quot;, &quot;Holiday&quot;)
&nbsp;
	<span style="color: #008000;">' A TW-DIMENSIONAL ARRAY OF STRINGS
</span>	<span style="color: #000080;">Dim</span> arrCombinedList : arrCombinedList = Array(arrGroceryList, arrWishList)
&nbsp;
&nbsp;
	<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">Print</span>( &quot;grocery list result <span style="color: #000080;">is</span> &quot; &amp; arrGroceryList(3) )
&nbsp;
	<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">Print</span>( &quot;wish list result <span style="color: #000080;">is</span> &quot; &amp; arrWishList(0) )
&nbsp;
	<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">Print</span>( &quot;two-dimensional array result <span style="color: #000080;">is</span> &quot; &amp; arrCombinedList(0)(3) )	
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span></pre></div></div>

<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/closestPt.jpg" alt="closestPt" title="closestPt" width="600" height="550" class="alignleft size-full wp-image-924" /></p>
<p><strong>EXERCISE 08: Arrays (Part 03A &#8212; Dynamic Arrays and Iteration) </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #008000;">'Script written by maxisupermanoeuvre.com
</span>
<span style="color: #000080;">Call</span> Main()
<span style="color: #000080;">Sub</span> Main()
&nbsp;
	<span style="color: #008000;">' LOOP TO BUILD SOME NEW OBJECTS
</span>	<span style="color: #000080;">Dim</span> i, arrStrObjs()
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> 99
		<span style="color: #000080;">ReDim</span> <span style="color: #000080;">Preserve</span> arrStrObjs(i)
		arrStrObjs(i) = rhino.addPoint( Array(rnd*100,rnd*100,rnd*100) )
	<span style="color: #000080;">Next</span>
&nbsp;
	<span style="color: #008000;">' LOOP TO GET CLOSEST POINT &amp;&amp; MAKE A LINE
</span>	<span style="color: #000080;">Dim</span> arrPtCoord, arrPtOther
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrStrObjs)
		arrPtCoord = rhino.PointCoordinates(arrStrObjs(i))
		arrPtOther = getClosestPoint(arrPtCoord, arrStrObjs)
		<span style="color: #000080;">Call</span> rhino.addLine( arrPtCoord, arrPtOther )
	<span style="color: #000080;">Next</span>
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #000080;">Function</span> getClosestPoint(TESTPT, PTS)
&nbsp;
	getClosestPoint = Null
&nbsp;
	<span style="color: #000080;">Dim</span> arrPtClosest
	<span style="color: #000080;">Dim</span> d2,distClosest
	<span style="color: #000080;">Dim</span> arrPtCoord
&nbsp;
	distClosest = 99999999
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(PTS)
		arrPtCoord = rhino.PointCoordinates(PTS(i))
		d2 = rhino.Distance(TESTPT, arrPtCoord)
		<span style="color: #000080;">If</span> (d2 &gt; 0) <span style="color: #000080;">And</span> (d2 &lt; distClosest) <span style="color: #000080;">Then</span>
			distClosest  = d2
			arrPtClosest = arrPtCoord
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	<span style="color: #000080;">Next</span>
&nbsp;
	getClosestPoint = arrPtClosest
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/threshTest.jpg" alt="threshTest" title="threshTest" width="600" height="460" class="alignleft size-full wp-image-925" /></p>
<p><strong>EXERCISE 09: Arrays (Part 03B &#8212; Dynamic Arrays and Iteration) </strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #008000;">'Script written by maxi@supermanoeuvre.com
</span>
<span style="color: #000080;">Call</span> Main()
<span style="color: #000080;">Sub</span> Main()
&nbsp;
	<span style="color: #008000;">' LOOP TO BUILD SOME NEW OBJECTS
</span>	<span style="color: #000080;">Dim</span> i, arrStrObjs()
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> 99
		<span style="color: #000080;">ReDim</span> <span style="color: #000080;">Preserve</span> arrStrObjs(i)
		arrStrObjs(i) = rhino.addPoint( Array(rnd*100,rnd*100,rnd*100) )
	<span style="color: #000080;">Next</span>
&nbsp;
	<span style="color: #008000;">' LOOP TO GET CLOSEST POINT &amp;&amp; MAKE A LINE
</span>	<span style="color: #000080;">Dim</span> j,k
	<span style="color: #000080;">Dim</span> arrPt, arrPtOthers
	<span style="color: #000080;">For</span> j = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrStrObjs)
		arrPt       = rhino.PointCoordinates(arrStrObjs(j))
		arrPtOthers = getAllPointsInRange(arrPt, arrStrObjs, 35.0)
		<span style="color: #000080;">For</span> k = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrPtOthers)
			<span style="color: #000080;">Call</span> rhino.addLine( arrPtOthers(k), arrPt )
		<span style="color: #000080;">Next</span>
	<span style="color: #000080;">Next</span>
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #000080;">Function</span> getAllPointsInRange(TESTPT, PTS, RANGE)
&nbsp;
	getAllPointsInRange = Null
&nbsp;
	<span style="color: #000080;">ReDim</span> arrPtsList(-1)
	<span style="color: #000080;">Dim</span> successCounter, arrPtCoord, d2
&nbsp;
	successCounter = 0
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(PTS)
		arrPtCoord = rhino.PointCoordinates(PTS(i))
		d2 = rhino.Distance(TESTPT, arrPtCoord)
		<span style="color: #000080;">If</span> (d2 &gt; 0) <span style="color: #000080;">And</span> (d2 &lt; RANGE) <span style="color: #000080;">Then</span>
			<span style="color: #000080;">ReDim</span> <span style="color: #000080;">Preserve</span> arrPtsList(successCounter)
			arrPtsList(successCounter) = arrPtCoord
			successCounter = successCounter + 1
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
	<span style="color: #000080;">Next</span>
&nbsp;
	getAllPointsInRange = arrPtsList
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.supermanoeuvre.com/blog/?feed=rss2&amp;p=918</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Computing Growth and Aggregation &#8212; Lindenmayer Sytems (LSystems)</title>
		<link>http://www.supermanoeuvre.com/blog/?p=910</link>
		<comments>http://www.supermanoeuvre.com/blog/?p=910#comments</comments>
		<pubDate>Tue, 31 Aug 2010 09:52:11 +0000</pubDate>
		<dc:creator>iainmaxwell</dc:creator>
				<category><![CDATA[RhinoScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.supermanoeuvre.com/blog/?p=910</guid>
		<description><![CDATA[
Growth and Aggregation via Lindenmayer Rule-based System
STEP 01: String Substitution
A simple string substitution system. We will hard-code the substitution rules, and draw simple rhino text dots at the locations of the new aggregated cells.

&#160;
Option Explicit
'Script written by maxisupermanoeuvre.com

Call LSystemAggregation()
&#160;
Sub LSystemAggregation()
&#160;
	' USER INOUTS
	Dim numGenerations : numGenerations = rhino.getInteger(&#34;How many GENERATIONS to run?&#34;, 5)
	Dim strInput   [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/lsys.jpg" alt="lsys" title="lsys" width="600" height="299" class="alignleft size-full wp-image-913" /><br />
<strong>Growth and Aggregation via Lindenmayer Rule-based System</strong></p>
<p><strong>STEP 01: String Substitution</strong><br />
A simple string substitution system. We will hard-code the substitution rules, and draw simple <em>rhino text dots</em> at the locations of the new aggregated cells.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #008000;">'Script written by maxisupermanoeuvre.com
</span>
<span style="color: #000080;">Call</span> LSystemAggregation()
&nbsp;
<span style="color: #000080;">Sub</span> LSystemAggregation()
&nbsp;
	<span style="color: #008000;">' USER INOUTS
</span>	<span style="color: #000080;">Dim</span> numGenerations : numGenerations = rhino.getInteger(&quot;How many GENERATIONS <span style="color: #000080;">to</span> run?&quot;, 5)
	<span style="color: #000080;">Dim</span> strInput       : strInput       = rhino.GetString(&quot;gimme starting <span style="color: #000080;">STRING</span> input&quot;, &quot;A&quot;)
	<span style="color: #000080;">Dim</span> dblOffset      : dblOffset      = 5
&nbsp;
	<span style="color: #000080;">Call</span> computeLSystem(strInput, numGenerations, dblOffset)
&nbsp;
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #008000;">'-----------------------------------------------CUSTOM RECURSIVE FUNCTION
</span><span style="color: #000080;">Function</span> computeLSystem(STRINPUT, GENERATIONS, DISTANCE)
&nbsp;
	computeLSystem = Null
&nbsp;
	<span style="color: #000080;">Dim</span> strStartDot : strStartDot = rhino.addTextDot( STRINPUT, Array(0,0,0) )
	<span style="color: #000080;">Dim</span> arrDots
&nbsp;
	<span style="color: #008000;">' loop for given number of generations
</span>	<span style="color: #000080;">Dim</span> i		
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> GENERATIONS-1
&nbsp;
		<span style="color: #008000;">' each time through create an array list to store all the new dots 
</span>		<span style="color: #000080;">If</span> i= 0 <span style="color: #000080;">Then</span>
&nbsp;
			<span style="color: #000080;">ReDim</span> arrNewDots(0)
			arrDots = strStartDot		
			arrNewDots(0) = strStartDot		
&nbsp;
		<span style="color: #000080;">Else</span>	
&nbsp;
			arrDots = arrNewDots
			<span style="color: #000080;">ReDim</span> arrNewDots(-1)		
&nbsp;
			<span style="color: #008000;">' loop through characters and apply LSYSTEM rule-set
</span>			<span style="color: #000080;">Dim</span> j
			<span style="color: #000080;">Dim</span> strLabel, strNewLabel
			<span style="color: #000080;">Dim</span> arrPtCurrent, arrPtNext
&nbsp;
			<span style="color: #000080;">For</span> j = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrDots)			
&nbsp;
				<span style="color: #008000;">' get current dot label
</span>				strLabel    = rhino.TextDotText(arrDots(j))
				<span style="color: #008000;">' get current dot location
</span>				arrPtCurrent = rhino.TextDotPoint(arrDots(j))
				<span style="color: #008000;">' substitute using rule set
</span>				strNewLabel = applyStringSubstitution(strLabel)
&nbsp;
				<span style="color: #008000;">' exapnd the array of new dots
</span>				<span style="color: #000080;">ReDim</span> <span style="color: #000080;">Preserve</span> arrNewDots(j)
&nbsp;
				<span style="color: #008000;">' make the new dot by type
</span>				<span style="color: #000080;">If</span> strNewLabel=&quot;A&quot; <span style="color: #000080;">Then</span>	
					arrPtNext     = Array(arrPtCurrent(0) + DISTANCE, arrPtCurrent(1), arrPtCurrent(2) ) <span style="color: #008000;">' RIGHT
</span>					arrNewDots(j) = rhino.addTextDot( strNewLabel, arrPtNext )
					<span style="color: #000080;">Call</span> rhino.addline(arrPtCurrent, arrPtNext)
				<span style="color: #000080;">ElseIf</span> strNewLabel=&quot;B&quot; <span style="color: #000080;">Then</span>
					arrPtNext     = Array(arrPtCurrent(0), arrPtCurrent(1) + DISTANCE, arrPtCurrent(2) ) <span style="color: #008000;">' UP
</span>					arrNewDots(j) = rhino.addTextDot( strNewLabel, arrPtNext )
					<span style="color: #000080;">Call</span> rhino.addline(arrPtCurrent, arrPtNext)
				<span style="color: #000080;">ElseIf</span> strNewLabel=&quot;C&quot; <span style="color: #000080;">Then</span>
					arrPtNext     = Array(arrPtCurrent(0) - DISTANCE, arrPtCurrent(1), arrPtCurrent(2) ) <span style="color: #008000;">' LEFT
</span>					arrNewDots(j) = rhino.addTextDot( strNewLabel, arrPtNext )
					<span style="color: #000080;">Call</span> rhino.addline(arrPtCurrent, arrPtNext)
				<span style="color: #000080;">ElseIf</span> strNewLabel=&quot;D&quot; <span style="color: #000080;">Then</span>
					arrPtNext     = Array(arrPtCurrent(0), arrPtCurrent(1) - DISTANCE, arrPtCurrent(2) ) <span style="color: #008000;">' DOWN
</span>					arrNewDots(j) = rhino.addTextDot( strNewLabel, arrPtNext )
					<span style="color: #000080;">Call</span> rhino.addline(arrPtCurrent, arrPtNext)
				<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
			<span style="color: #000080;">Next</span>
&nbsp;
&nbsp;
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span> <span style="color: #008000;">' end generation if i &gt; 0
</span>		
&nbsp;
	<span style="color: #000080;">Next</span>
&nbsp;
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #008000;">'-----------------------------------------------CUSTOM FUNCTION -- STRING SUBSTITUTION
</span><span style="color: #000080;">Function</span> applyStringSubstitution(STRINPUT)
&nbsp;
	applyStringSubstitution = Null
&nbsp;
	<span style="color: #000080;">Dim</span> strNextGen : strNextGen = &quot;&quot;
&nbsp;
	<span style="color: #000080;">Dim</span> arrCharToks : arrCharToks = rhino.strtok(STRINPUT, &quot;,&quot;)
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrCharToks)
&nbsp;
		<span style="color: #008000;">'---- CASE A
</span>		<span style="color: #000080;">If</span> arrCharToks(i) = &quot;A&quot; <span style="color: #000080;">Then</span>
			strNextGen = strNextGen + &quot;B&quot;
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CASE B
</span>		<span style="color: #000080;">If</span> arrCharToks(i) = &quot;B&quot; <span style="color: #000080;">Then</span>
			strNextGen = strNextGen + &quot;A&quot;
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CASE C
</span>		<span style="color: #000080;">If</span> arrCharToks(i) = &quot;C&quot; <span style="color: #000080;">Then</span>
			strNextGen = strNextGen + &quot;A&quot;
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CASE D
</span>		<span style="color: #000080;">If</span> arrCharToks(i) = &quot;D&quot; <span style="color: #000080;">Then</span>
			strNextGen = strNextGen + &quot;B&quot;
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
&nbsp;
	<span style="color: #000080;">Next</span>
&nbsp;
	applyStringSubstitution = strNextGen
&nbsp;
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

<p><strong>STEP 02: Multiple String Substitutions (Bifurcation) </strong><br />
Similar to the previous exercise except that we allow each cell to grow multiple children.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #008000;">'Script written by maxisupermanoeuvre.com
</span>
<span style="color: #000080;">Call</span> LSystemAggregation()
&nbsp;
<span style="color: #000080;">Sub</span> LSystemAggregation()
&nbsp;
	<span style="color: #008000;">' USER INOUTS
</span>	<span style="color: #000080;">Dim</span> numGenerations : numGenerations = rhino.getInteger(&quot;How many GENERATIONS <span style="color: #000080;">to</span> run?&quot;, 5)
	<span style="color: #000080;">Dim</span> strInput       : strInput       = rhino.GetString(&quot;gimme starting <span style="color: #000080;">STRING</span> input&quot;, &quot;A&quot;)
	<span style="color: #000080;">Dim</span> dblOffset      : dblOffset      = 5
&nbsp;
	<span style="color: #000080;">Call</span> computeLSystem(strInput, numGenerations, dblOffset)
&nbsp;
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #008000;">'-----------------------------------------------CUSTOM RECURSIVE FUNCTION 
</span><span style="color: #000080;">Function</span> computeLSystem(STRINPUT, GENERATIONS, DISTANCE)
&nbsp;
	computeLSystem = Null
&nbsp;
	<span style="color: #000080;">Dim</span> strStartDot : strStartDot = rhino.addTextDot( STRINPUT, Array(0,0,0) )
	<span style="color: #000080;">Dim</span> arrDots
&nbsp;
	<span style="color: #008000;">' loop for given number of generations
</span>	<span style="color: #000080;">Dim</span> i		
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> GENERATIONS
&nbsp;
		<span style="color: #008000;">' each time through create an array list to store all the new dots 
</span>		<span style="color: #000080;">If</span> i= 0 <span style="color: #000080;">Then</span>
			<span style="color: #000080;">ReDim</span> arrNewDots(0)
			arrDots = strStartDot		
			arrNewDots(0) = strStartDot
		<span style="color: #000080;">Else</span>				
			arrDots = arrNewDots
			<span style="color: #000080;">ReDim</span> arrNewDots(-1)	
&nbsp;
			<span style="color: #008000;">' loop through characters and apply LSYSTEM rule-set
</span>			<span style="color: #000080;">Dim</span> j
			<span style="color: #000080;">Dim</span> strLabel, strNewLabel
			<span style="color: #000080;">Dim</span> arrPtCurrent, arrPtNext
			<span style="color: #000080;">Dim</span> dotCounter, strToks
&nbsp;
			dotCounter = 0
&nbsp;
			<span style="color: #000080;">For</span> j = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrDots)			
&nbsp;
				<span style="color: #008000;">' get current dot label
</span>				strLabel    = rhino.TextDotText(arrDots(j))
				<span style="color: #008000;">' get current dot location
</span>				arrPtCurrent = rhino.TextDotPoint(arrDots(j))
				<span style="color: #008000;">' get all the characters to make
</span>				strToks     = rhino.Strtok(strLabel, &quot;,&quot;)
&nbsp;
				<span style="color: #008000;">' create multiple dots
</span>				<span style="color: #000080;">Dim</span> k
				<span style="color: #000080;">For</span> k = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(strToks)				
&nbsp;
					<span style="color: #008000;">' exapnd the array of new dots
</span>					<span style="color: #000080;">ReDim</span> <span style="color: #000080;">Preserve</span> arrNewDots(dotCounter)
&nbsp;
					<span style="color: #008000;">' substitute using rule set
</span>					strNewLabel = applyStringSubstitution(strToks(k))
					<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">Print</span>(&quot;strNewLabel &quot; &amp; strNewLabel)
&nbsp;
					<span style="color: #008000;">' make the new dot by type
</span>					<span style="color: #000080;">If</span> strToks(k)=&quot;A&quot; <span style="color: #000080;">Then</span>	
						arrPtNext              = Array(arrPtCurrent(0) + DISTANCE, arrPtCurrent(1), arrPtCurrent(2) ) <span style="color: #008000;">' RIGHT
</span>						arrNewDots(dotCounter) = rhino.addTextDot( strNewLabel, arrPtNext )
						<span style="color: #000080;">Call</span> rhino.addline(arrPtCurrent, arrPtNext)
					<span style="color: #000080;">ElseIf</span> strToks(k)=&quot;B&quot; <span style="color: #000080;">Then</span>
						arrPtNext              = Array(arrPtCurrent(0), arrPtCurrent(1) + DISTANCE, arrPtCurrent(2) ) <span style="color: #008000;">' UP
</span>						arrNewDots(dotCounter) = rhino.addTextDot( strNewLabel, arrPtNext )
						<span style="color: #000080;">Call</span> rhino.addline(arrPtCurrent, arrPtNext)
					<span style="color: #000080;">ElseIf</span> strToks(k)=&quot;C&quot; <span style="color: #000080;">Then</span>
						arrPtNext              = Array(arrPtCurrent(0) - DISTANCE, arrPtCurrent(1), arrPtCurrent(2) ) <span style="color: #008000;">' LEFT
</span>						arrNewDots(dotCounter) = rhino.addTextDot( strNewLabel, arrPtNext )
						<span style="color: #000080;">Call</span> rhino.addline(arrPtCurrent, arrPtNext)
					<span style="color: #000080;">ElseIf</span> strToks(k)=&quot;D&quot; <span style="color: #000080;">Then</span>
						arrPtNext              = Array(arrPtCurrent(0), arrPtCurrent(1) - DISTANCE, arrPtCurrent(2) ) <span style="color: #008000;">' DOWN
</span>						arrNewDots(dotCounter) = rhino.addTextDot( strNewLabel, arrPtNext )
						<span style="color: #000080;">Call</span> rhino.addline(arrPtCurrent, arrPtNext)
					<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
					<span style="color: #008000;">' add to counter
</span>					dotCounter = dotCounter + 1
&nbsp;
				<span style="color: #000080;">Next</span> <span style="color: #008000;">' end k loop
</span>			
			<span style="color: #000080;">Next</span> <span style="color: #008000;">' end j loop
</span>			
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span> <span style="color: #008000;">' end generation if i &gt; 0
</span>				
	<span style="color: #000080;">Next</span> <span style="color: #008000;">' end i loop
</span>
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #008000;">'-----------------------------------------------CUSTOM FUNCTION -- STRING SUBSTITUTION
</span><span style="color: #000080;">Function</span> applyStringSubstitution(STRINPUT)
&nbsp;
	applyStringSubstitution = Null
&nbsp;
	<span style="color: #000080;">Dim</span> strNextGen : strNextGen = &quot;&quot;	
&nbsp;
	<span style="color: #008000;">'---- CASE A
</span>	<span style="color: #000080;">If</span> STRINPUT = &quot;A&quot; <span style="color: #000080;">Then</span>
		strNextGen = strNextGen + &quot;B,D&quot;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #008000;">'---- CASE B
</span>	<span style="color: #000080;">If</span> STRINPUT = &quot;B&quot; <span style="color: #000080;">Then</span>
		strNextGen = strNextGen + &quot;A&quot;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #008000;">'---- CASE C
</span>	<span style="color: #000080;">If</span> STRINPUT = &quot;C&quot; <span style="color: #000080;">Then</span>
		strNextGen = strNextGen + &quot;A&quot;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #008000;">'---- CASE D
</span>	<span style="color: #000080;">If</span> STRINPUT = &quot;D&quot; <span style="color: #000080;">Then</span>
		strNextGen = strNextGen + &quot;A&quot;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
&nbsp;
	applyStringSubstitution = strNextGen
&nbsp;
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

<p><strong>EXAMPLE 01: Cell Aggregation &#038;&#038; Growth </strong><br />
Here we introduce a custom function that draws a <em>rhino poly surface cube</em> at the location of the newly created cell.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #008000;">'Script written by maxisupermanoeuvre.com
</span>
<span style="color: #000080;">Call</span> LSystemAggregation()
&nbsp;
<span style="color: #000080;">Sub</span> LSystemAggregation()
&nbsp;
	<span style="color: #008000;">' USER INOUTS
</span>	<span style="color: #000080;">Dim</span> numGenerations : numGenerations = rhino.getInteger(&quot;How many GENERATIONS <span style="color: #000080;">to</span> run?&quot;, 5)
	<span style="color: #000080;">Dim</span> strInput       : strInput       = rhino.GetString(&quot;gimme starting <span style="color: #000080;">STRING</span> input&quot;, &quot;A&quot;)
&nbsp;
	<span style="color: #000080;">Dim</span> boxSizeX : boxSizeX = 5
	<span style="color: #000080;">Dim</span> boxSizeY : boxSizeY = 5
	<span style="color: #000080;">Dim</span> boxSizeZ : boxSizeZ = 5
&nbsp;
	<span style="color: #000080;">Call</span> computeLSystem(strInput, numGenerations, boxSizeX, boxSizeY, boxSizeZ)
&nbsp;
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #008000;">'-----------------------------------------------CUSTOM RECURSIVE FUNCTION
</span><span style="color: #000080;">Function</span> computeLSystem(STRINPUT, GENERATIONS, SX, SY, SZ)
&nbsp;
	computeLSystem = Null
&nbsp;
	<span style="color: #000080;">Dim</span> strStartBox : strStartBox = makeCustomBox( STRINPUT, Array(0,0,0), SX, SY, SZ )
&nbsp;
	<span style="color: #000080;">Dim</span> arrBoxes
&nbsp;
	<span style="color: #008000;">' loop for given number of generations
</span>	<span style="color: #000080;">Dim</span> i		
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> GENERATIONS
&nbsp;
		<span style="color: #008000;">' each time through create an array list to store all the new dots 
</span>		<span style="color: #000080;">If</span> i= 0 <span style="color: #000080;">Then</span>
			<span style="color: #000080;">ReDim</span> arrNewBoxes(0)
			arrBoxes       = strStartBox		
			arrNewBoxes(0) = strStartBox
		<span style="color: #000080;">Else</span>				
			arrBoxes = arrNewBoxes
			<span style="color: #000080;">ReDim</span> arrNewBoxes(-1)	
&nbsp;
			<span style="color: #008000;">' loop through characters and apply LSYSTEM rule-set
</span>			<span style="color: #000080;">Dim</span> j
			<span style="color: #000080;">Dim</span> strInfo, strInfoToks, strLabel, strNewLabel
			<span style="color: #000080;">Dim</span> arrPtCurrent, arrPtNext
			<span style="color: #000080;">Dim</span> boxCounter, strToks
&nbsp;
			boxCounter = 0
&nbsp;
			<span style="color: #000080;">For</span> j = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrBoxes)			
&nbsp;
				<span style="color: #008000;">' get current box label
</span>				strInfo      = rhino.objectName(arrBoxes(j))
				<span style="color: #008000;">' split using &quot;_&quot; to get type_arrPointCoordinate
</span>				strInfoToks  = rhino.Strtok(strInfo, &quot;_&quot;)
				<span style="color: #008000;">' get type to make
</span>				strLabel = strInfoToks(0)
				<span style="color: #008000;">' get current dot location
</span>				arrPtCurrent = rhino.Str2Pt( strInfoToks(1) )
				<span style="color: #008000;">' get all the characters to make
</span>				strToks      = rhino.Strtok(strLabel, &quot;,&quot;)
&nbsp;
				<span style="color: #008000;">' create multiple dots
</span>				<span style="color: #000080;">Dim</span> k
				<span style="color: #000080;">For</span> k = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(strToks)				
&nbsp;
					<span style="color: #008000;">' exapnd the array of new dots
</span>					<span style="color: #000080;">ReDim</span> <span style="color: #000080;">Preserve</span> arrNewBoxes(boxCounter)
&nbsp;
					<span style="color: #008000;">' substitute using rule set
</span>					strNewLabel = applyStringSubstitution(strToks(k))
					<span style="color: #008000;">'Call rhino.Print(&quot;strNewLabel &quot; &amp; strNewLabel)
</span>					
					<span style="color: #008000;">' make the new dot by type
</span>					<span style="color: #000080;">If</span> strToks(k)=&quot;A&quot; <span style="color: #000080;">Then</span>	
						arrPtNext               = Array(arrPtCurrent(0) + SX, arrPtCurrent(1), arrPtCurrent(2) ) <span style="color: #008000;">' RIGHT
</span>						arrNewBoxes(boxCounter)  = makeCustomBox( strNewLabel, arrPtNext, SX, SY, SZ )
					<span style="color: #000080;">ElseIf</span> strToks(k)=&quot;B&quot; <span style="color: #000080;">Then</span>
						arrPtNext               = Array(arrPtCurrent(0), arrPtCurrent(1) + SY, arrPtCurrent(2) ) <span style="color: #008000;">' UP
</span>						arrNewBoxes(boxCounter) = makeCustomBox( strNewLabel, arrPtNext, SX, SY, SZ )
					<span style="color: #000080;">ElseIf</span> strToks(k)=&quot;C&quot; <span style="color: #000080;">Then</span>
						arrPtNext               = Array(arrPtCurrent(0) - SX, arrPtCurrent(1), arrPtCurrent(2) ) <span style="color: #008000;">' LEFT
</span>						arrNewBoxes(boxCounter) = makeCustomBox( strNewLabel, arrPtNext, SX, SY, SZ )
					<span style="color: #000080;">ElseIf</span> strToks(k)=&quot;D&quot; <span style="color: #000080;">Then</span>
						arrPtNext               = Array(arrPtCurrent(0), arrPtCurrent(1) - SY, arrPtCurrent(2) + SZ) <span style="color: #008000;">' DOWN
</span>						arrNewBoxes(boxCounter) = makeCustomBox( strNewLabel, arrPtNext, SX, SY, SZ )
					<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
					<span style="color: #008000;">' add to counter
</span>					boxCounter = boxCounter + 1
&nbsp;
				<span style="color: #000080;">Next</span> <span style="color: #008000;">' end k loop
</span>			
			<span style="color: #000080;">Next</span> <span style="color: #008000;">' end j loop
</span>			
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span> <span style="color: #008000;">' end generation if i &gt; 0
</span>				
	<span style="color: #000080;">Next</span> <span style="color: #008000;">' end i loop
</span>
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #008000;">'-----------------------------------------------CUSTOM FUNCTION -- STRING SUBSTITUTION
</span><span style="color: #000080;">Function</span> applyStringSubstitution(STRINPUT)
&nbsp;
	applyStringSubstitution = Null
&nbsp;
	<span style="color: #000080;">Dim</span> strNextGen : strNextGen = &quot;&quot;	
&nbsp;
	<span style="color: #008000;">'---- CASE A
</span>	<span style="color: #000080;">If</span> STRINPUT = &quot;A&quot; <span style="color: #000080;">Then</span>
		strNextGen = strNextGen + &quot;B,D&quot;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #008000;">'---- CASE B
</span>	<span style="color: #000080;">If</span> STRINPUT = &quot;B&quot; <span style="color: #000080;">Then</span>
		strNextGen = strNextGen + &quot;A&quot;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #008000;">'---- CASE C
</span>	<span style="color: #000080;">If</span> STRINPUT = &quot;C&quot; <span style="color: #000080;">Then</span>
		strNextGen = strNextGen + &quot;C,B&quot;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #008000;">'---- CASE D
</span>	<span style="color: #000080;">If</span> STRINPUT = &quot;D&quot; <span style="color: #000080;">Then</span>
		strNextGen = strNextGen + &quot;A,B,C&quot;
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
&nbsp;
	applyStringSubstitution = strNextGen
&nbsp;
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span> 
&nbsp;
&nbsp;
<span style="color: #000080;">Function</span> makeCustomBox(STRINGTYPE, ARRCNTR, X, Y, Z)
&nbsp;
	makeCustomBox = Null
&nbsp;
	<span style="color: #000080;">Dim</span> arrVertices(7)
	<span style="color: #008000;">' BOTTOM VERTICES
</span>	arrVertices(0) = Array( ARRCNTR(0)-X/2, ARRCNTR(1)+Y/2, ARRCNTR(2)-Z/2 )
	arrVertices(1) = Array( ARRCNTR(0)+X/2, ARRCNTR(1)+Y/2, ARRCNTR(2)-Z/2 )
	arrVertices(2) = Array( ARRCNTR(0)+X/2, ARRCNTR(1)-Y/2, ARRCNTR(2)-Z/2 )
	arrVertices(3) = Array( ARRCNTR(0)-X/2, ARRCNTR(1)-Y/2, ARRCNTR(2)-Z/2 )
	<span style="color: #008000;">' TOP VERTICES
</span>	arrVertices(4) = Array( ARRCNTR(0)-X/2, ARRCNTR(1)+Y/2, ARRCNTR(2)+Z/2 )
	arrVertices(5) = Array( ARRCNTR(0)+X/2, ARRCNTR(1)+Y/2, ARRCNTR(2)+Z/2 )
	arrVertices(6) = Array( ARRCNTR(0)+X/2, ARRCNTR(1)-Y/2, ARRCNTR(2)+Z/2 )
	arrVertices(7) = Array( ARRCNTR(0)-X/2, ARRCNTR(1)-Y/2, ARRCNTR(2)+Z/2 )
&nbsp;
	<span style="color: #000080;">Dim</span> strBox : strBox = rhino.addBox(arrVertices)
	<span style="color: #000080;">Call</span> rhino.ObjectName(strBox, STRINGTYPE &amp; &quot;_&quot; &amp; rhino.Pt2Str(ARRCNTR) )
&nbsp;
	makeCustomBox = strBox	
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.supermanoeuvre.com/blog/?feed=rss2&amp;p=910</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Computing Neighbourhoods &#8212; Cellular Automata</title>
		<link>http://www.supermanoeuvre.com/blog/?p=901</link>
		<comments>http://www.supermanoeuvre.com/blog/?p=901#comments</comments>
		<pubDate>Tue, 31 Aug 2010 09:27:45 +0000</pubDate>
		<dc:creator>iainmaxwell</dc:creator>
				<category><![CDATA[RhinoScript]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.supermanoeuvre.com/blog/?p=901</guid>
		<description><![CDATA[
CELLULAR AUTOMATA
A cellular automaton (pl. cellular automata, abbrev. CA) is a discrete model studied in computability theory, mathematics, physics, complexity science, theoretical biology and microstructure modeling. It consists of a regular grid of cells, each in one of a finite number of states, such as &#8220;On&#8221; and &#8220;Off&#8221; (in contrast to a coupled map lattice). [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/CA_grab.jpg" alt="CA_grab" title="CA_grab" width="600" height="216" class="alignleft size-full wp-image-907" /></p>
<p><strong>CELLULAR AUTOMATA</strong><br />
A cellular automaton (pl. cellular automata, abbrev. CA) is a discrete model studied in computability theory, mathematics, physics, complexity science, theoretical biology and microstructure modeling. It consists of a regular grid of cells, each in one of a finite number of states, such as &#8220;On&#8221; and &#8220;Off&#8221; (in contrast to a coupled map lattice). The grid can be in any finite number of dimensions. For each cell, a set of cells called its neighborhood  (usually including the cell itself) is defined relative to the specified cell. For example, the neighborhood of a cell might be defined as the set of cells a distance of 2 or less from the cell. An initial state (time t=0) is selected by assigning a state for each cell. A new generation is created (advancing t  by 1), according to some fixed rule (generally, a mathematical function) that determines the new state of each cell in terms of the current state of the cell and the states of the cells in its neighborhood. For example, the rule might be that the cell is &#8220;On&#8221; in the next generation if exactly two of the cells in the neighborhood are &#8220;On&#8221; in the current generation, otherwise the cell is &#8220;Off&#8221; in the next generation. Typically, the rule for updating the state of cells is the same for each cell and does not change over time, and is applied to the whole grid simultaneously, though exceptions are known.</p>
<p>Further reading:<br />
<a href="http://www.wolframscience.com/nksonline/section-2.1"> How Simple Programs Behave &#8211; Stephen Wolfram</a><br />
<a href="http://en.wikipedia.org/wiki/Cellular_automaton"> WIKI</a></p>
<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/caRulesMatrix.jpg" alt="caRulesMatrix" title="caRulesMatrix" width="600" height="428" class="alignleft size-full wp-image-902" /></p>
<p><strong>STEP 01: Applying the rules</strong></p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #008000;">'Script written by maxi@supermanoeuvre.com
</span>
<span style="color: #000080;">Call</span> BerlinCA()
&nbsp;
<span style="color: #000080;">Sub</span> BerlinCA()
&nbsp;
	<span style="color: #000080;">Dim</span> strInput : strInput = rhino.GetString(&quot;gimme <span style="color: #000080;">input</span> STRING&quot;, &quot;0,0,0,1,0,0,1,1,0,1,1,1,1,1&quot; )	
&nbsp;
	<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">print</span>(&quot;the <span style="color: #000080;">input</span> <span style="color: #000080;">string</span> <span style="color: #000080;">to</span> test: &quot; &amp; strInput)
	<span style="color: #000080;">Call</span> rhino.<span style="color: #000080;">print</span>(&quot;the result of rule 30 <span style="color: #000080;">is</span>: &quot; &amp; applyRule30(strInput) )
&nbsp;
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #008000;">'--------------------------------------------------------- CUSTOM FUNCTION -- THE RULE SET 30
</span><span style="color: #000080;">Function</span> applyRule30(STRINPUT)
&nbsp;
	applyRule30 = Null
&nbsp;
	<span style="color: #000080;">Dim</span> arrTokens, strCharCurrent, strCharLeft, strCharRight, strNextGen
&nbsp;
	strNextGen = &quot;&quot;
	arrTokens = Rhino.Strtok (STRINPUT, &quot;,&quot;)
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrTokens)
&nbsp;
		<span style="color: #008000;">'------------------------GET LEFT SIDE (PREVIOUS COUNTER STEP)
</span>		<span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> i = 0 <span style="color: #000080;">Then</span>
			strCharLeft = arrTokens(i-1)
		<span style="color: #000080;">Else</span>
			strCharLeft = arrTokens(<span style="color: #000080;">ubound</span>(arrTokens))
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'------------------------GET CURRENT
</span>		strCharCurrent = arrTokens(i)
&nbsp;
		<span style="color: #008000;">'------------------------GET RIGHT (NEXT COUNTER STEP)		
</span>		<span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> i = <span style="color: #000080;">ubound</span>(arrTokens) <span style="color: #000080;">Then</span>
			strCharRight = arrTokens(i+1)
		<span style="color: #000080;">Else</span>
			strCharRight = arrTokens(0)
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>	
&nbsp;
&nbsp;
		<span style="color: #008000;">'------------------------THE CA RULE 30		
</span>		<span style="color: #008000;">'---- CONDITION #01
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #02
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #03
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #04
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #05
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #06
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #07
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #08
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				<span style="color: #008000;">' Starting value
</span>				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				<span style="color: #008000;">' separate with a comma
</span>				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #000080;">Next</span>
&nbsp;
	applyRule30 = strNextGen
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/caTextDots-300x117.jpg" alt="caTextDots" title="caTextDots" width="600" height="234" class="alignleft size-medium wp-image-904" /></p>
<p><strong>EXAMPLE 01: State-based Text Dots </strong><br />
In this example we visualize the CA states by placing a <em>rhino text dot</em> indicating the location, and whether the cell is active or not.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #008000;">'Script written by maxi@supermanoeuvre.com
</span>
<span style="color: #000080;">Call</span> BerlinCA()
&nbsp;
<span style="color: #000080;">Sub</span> BerlinCA()
&nbsp;
	<span style="color: #008000;">' USER INOUTS
</span>	<span style="color: #000080;">Dim</span> numGenerations : numGenerations = rhino.getInteger(&quot;How many GENERATIONS <span style="color: #000080;">to</span> run?&quot;, 50)
	<span style="color: #000080;">Dim</span> strInput       : strInput       = rhino.GetString(&quot;gimme <span style="color: #000080;">input</span> <span style="color: #000080;">string</span> ---separated by comma---&quot;, &quot;0,0,0,1,0,0,1,1,0,1,1,1,1,1&quot;)
&nbsp;
	<span style="color: #000080;">Call</span> computeCA(strInput, numGenerations)
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #008000;">'--------------------------------------------------------- CUSTOM FUNCTION -- COMPUTE THE CA
</span><span style="color: #000080;">Function</span> computeCA(STRINPUT, GENERATIONS)
&nbsp;
	computeCA = Null
&nbsp;
	<span style="color: #008000;">' string of characters
</span>	<span style="color: #000080;">Dim</span> strGen : strGen = STRINPUT
&nbsp;
&nbsp;
	<span style="color: #000080;">Dim</span> i
&nbsp;
	<span style="color: #008000;">' loop for given number of generations
</span>	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> GENERATIONS
&nbsp;
		<span style="color: #000080;">Dim</span> arrChars : arrChars = Rhino.Strtok (strGen, &quot;,&quot;)
&nbsp;
		<span style="color: #008000;">' loop through characters and apply CA rule-set
</span>		<span style="color: #000080;">Dim</span> j
		<span style="color: #000080;">For</span> j = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrChars)
&nbsp;
			<span style="color: #000080;">Dim</span> strDot : strDot = rhino.addTextDot(arrChars(j), Array(j,i,0) )
&nbsp;
			<span style="color: #000080;">If</span> arrChars(j)=&quot;0&quot; <span style="color: #000080;">Then</span>
				<span style="color: #008000;">' OFF is white
</span>				<span style="color: #000080;">Call</span> Rhino.ObjectColor (strDot , RGB(255,255,255))
			<span style="color: #000080;">Else</span>
				<span style="color: #008000;">' ON is black
</span>				<span style="color: #000080;">Call</span> Rhino.ObjectColor (strDot , RGB(0,0,0))
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #000080;">Next</span>
&nbsp;
		strGen = applyRule30(strGen)
&nbsp;
	<span style="color: #000080;">Next</span>
&nbsp;
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #008000;">'--------------------------------------------------------- CUSTOM FUNCTION -- THE RULE SET 30
</span><span style="color: #000080;">Function</span> applyRule30(STRINPUT)
&nbsp;
	applyRule30 = Null
&nbsp;
	<span style="color: #000080;">Dim</span> arrTokens, strCharCurrent, strCharLeft, strCharRight, strNextGen
&nbsp;
	strNextGen = &quot;&quot;
	arrTokens = Rhino.Strtok (STRINPUT, &quot;,&quot;)
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrTokens)
&nbsp;
		<span style="color: #008000;">'------------------------GET LEFT SIDE (PREVIOUS COUNTER STEP)
</span>		<span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> i = 0 <span style="color: #000080;">Then</span>
			strCharLeft = arrTokens(i-1)
		<span style="color: #000080;">Else</span>
			strCharLeft = arrTokens(<span style="color: #000080;">ubound</span>(arrTokens))
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'------------------------GET CURRENT
</span>		strCharCurrent = arrTokens(i)
&nbsp;
		<span style="color: #008000;">'------------------------GET RIGHT (NEXT COUNTER STEP)		
</span>		<span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> i = <span style="color: #000080;">ubound</span>(arrTokens) <span style="color: #000080;">Then</span>
			strCharRight = arrTokens(i+1)
		<span style="color: #000080;">Else</span>
			strCharRight = arrTokens(0)
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>	
&nbsp;
&nbsp;
		<span style="color: #008000;">'------------------------THE CA RULE 30		
</span>		<span style="color: #008000;">'---- CONDITION #01
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #02
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #03
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #04
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #05
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #06
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #07
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #08
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				<span style="color: #008000;">' Starting value
</span>				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				<span style="color: #008000;">' separate with a comma
</span>				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #000080;">Next</span>
&nbsp;
	applyRule30 = strNextGen
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

<p><img src="http://www.supermanoeuvre.com/blog/wp-content/uploads/2010/08/CA_grab.jpg" alt="CA_grab" title="CA_grab" width="600" height="216" class="alignleft size-full wp-image-907" /></p>
<p><strong>EXAMPLE 02: State-based Cube Distribution </strong><br />
In this example we add another custom function which creates a <em>poly surface box</em> indicating the location, and whether the cell is active or not.<br />
We also introduce rule set 110.</p>

<div class="wp_syntax"><div class="code"><pre class="vb" style="font-family:monospace;">&nbsp;
<span style="color: #000080;">Option</span> <span style="color: #000080;">Explicit</span>
<span style="color: #008000;">'Script written by maxi@supermanoeuvre.com
</span>
<span style="color: #000080;">Call</span> BerlinCA()
&nbsp;
<span style="color: #000080;">Sub</span> BerlinCA()
&nbsp;
&nbsp;
	<span style="color: #000080;">Dim</span> numGenerations : numGenerations = rhino.getInteger(&quot;How many GENERATIONS <span style="color: #000080;">to</span> run?&quot;, 35)
	<span style="color: #000080;">If</span> isNull(numGenerations) <span style="color: #000080;">Then</span> <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
&nbsp;
	<span style="color: #000080;">Dim</span> strInput       : strInput       = rhino.GetString(&quot;gimme <span style="color: #000080;">input</span> <span style="color: #000080;">string</span> ---separated by comma---&quot;, &quot;0,0,0,1,0,0,1,0,0,1,0,1,0,1&quot;)
	<span style="color: #000080;">If</span> isNull(strInput) <span style="color: #000080;">Then</span> <span style="color: #000080;">Exit</span> <span style="color: #000080;">Sub</span>
&nbsp;
	<span style="color: #000080;">Dim</span> boxSizeX : boxSizeX = 5
	<span style="color: #000080;">Dim</span> boxSizeY : boxSizeY = 5
	<span style="color: #000080;">Dim</span> boxSizeZ : boxSizeZ = 5
&nbsp;
	<span style="color: #000080;">Call</span> rhino.addLayer( &quot;VOID&quot;, RGB(255,255,255) )
	<span style="color: #000080;">Call</span> rhino.addLayer( &quot;SOLID&quot;, RGB(145,0,245) )
&nbsp;
	<span style="color: #000080;">Call</span> rhino.EnableRedraw(<span style="color: #000080;">False</span>)
	<span style="color: #000080;">Call</span> computeCA(strInput, numGenerations, boxSizeX, boxSizeY, boxSizeZ )
	<span style="color: #000080;">Call</span> rhino.EnableRedraw(<span style="color: #000080;">True</span>)
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Sub</span>
&nbsp;
<span style="color: #008000;">'--------------------------------------------------------- CUSTOM FUNCTION -- COMPUTE THE CA
</span><span style="color: #000080;">Function</span> computeCA(STRINPUT, GENERATIONS, SX, SY, SZ)
&nbsp;
	computeCA = Null
&nbsp;
	<span style="color: #008000;">' string of characters
</span>	<span style="color: #000080;">Dim</span> strGen : strGen = STRINPUT
&nbsp;
&nbsp;
	<span style="color: #000080;">Dim</span> i
&nbsp;
	<span style="color: #008000;">' loop for given number of generations
</span>	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> GENERATIONS
&nbsp;
		<span style="color: #000080;">Dim</span> arrChars : arrChars = Rhino.Strtok (strGen, &quot;,&quot;)
&nbsp;
		<span style="color: #008000;">' loop through characters and apply CA rule-set
</span>		<span style="color: #000080;">Dim</span> j
		<span style="color: #000080;">For</span> j = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrChars)
&nbsp;
			<span style="color: #000080;">Dim</span> strBox : strBox = makeBox(arrChars(j), Array(j*SX,i*SY,0), SX, SY, SZ )		
&nbsp;
		<span style="color: #000080;">Next</span>
&nbsp;
		<span style="color: #008000;">'strGen = applyRule30(strGen)
</span>		strGen = applyRule110(strGen)
&nbsp;
	<span style="color: #000080;">Next</span>
&nbsp;
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #008000;">'--------------------------------------------------------- CUSTOM FUNCTION -- THE RULE SET 30
</span><span style="color: #000080;">Function</span> applyRule30(STRINPUT)
&nbsp;
	applyRule30 = Null
&nbsp;
	<span style="color: #000080;">Dim</span> arrTokens, strCharCurrent, strCharLeft, strCharRight, strNextGen
&nbsp;
	strNextGen = &quot;&quot;
	arrTokens = Rhino.Strtok (STRINPUT, &quot;,&quot;)
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrTokens)
&nbsp;
		<span style="color: #008000;">'------------------------GET LEFT SIDE (PREVIOUS COUNTER STEP)
</span>		<span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> i = 0 <span style="color: #000080;">Then</span>
			strCharLeft = arrTokens(i-1)
		<span style="color: #000080;">Else</span>
			strCharLeft = arrTokens(<span style="color: #000080;">ubound</span>(arrTokens))
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'------------------------GET CURRENT
</span>		strCharCurrent = arrTokens(i)
&nbsp;
		<span style="color: #008000;">'------------------------GET RIGHT (NEXT COUNTER STEP)		
</span>		<span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> i = <span style="color: #000080;">ubound</span>(arrTokens) <span style="color: #000080;">Then</span>
			strCharRight = arrTokens(i+1)
		<span style="color: #000080;">Else</span>
			strCharRight = arrTokens(0)
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>	
&nbsp;
&nbsp;
		<span style="color: #008000;">'------------------------THE CA RULE 30		
</span>		<span style="color: #008000;">'---- CONDITION #01
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #02
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #03
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #04
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #05
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #06
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #07
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #08
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				<span style="color: #008000;">' Starting value
</span>				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				<span style="color: #008000;">' separate with a comma
</span>				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #000080;">Next</span>
&nbsp;
	applyRule30 = strNextGen
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
<span style="color: #008000;">'--------------------------------------------------------- CUSTOM FUNCTION -- THE RULE SET 30
</span><span style="color: #000080;">Function</span> applyRule110(STRINPUT)
&nbsp;
	applyRule110 = Null
&nbsp;
	<span style="color: #000080;">Dim</span> arrTokens, strCharCurrent, strCharLeft, strCharRight, strNextGen
&nbsp;
	strNextGen = &quot;&quot;
	arrTokens = Rhino.Strtok (STRINPUT, &quot;,&quot;)
&nbsp;
	<span style="color: #000080;">Dim</span> i
	<span style="color: #000080;">For</span> i = 0 <span style="color: #000080;">To</span> <span style="color: #000080;">ubound</span>(arrTokens)
&nbsp;
		<span style="color: #008000;">'------------------------GET LEFT SIDE (PREVIOUS COUNTER STEP)
</span>		<span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> i = 0 <span style="color: #000080;">Then</span>
			strCharLeft = arrTokens(i-1)
		<span style="color: #000080;">Else</span>
			strCharLeft = arrTokens(<span style="color: #000080;">ubound</span>(arrTokens))
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'------------------------GET CURRENT
</span>		strCharCurrent = arrTokens(i)
&nbsp;
		<span style="color: #008000;">'------------------------GET RIGHT (NEXT COUNTER STEP)		
</span>		<span style="color: #000080;">If</span> <span style="color: #000080;">Not</span> i = <span style="color: #000080;">ubound</span>(arrTokens) <span style="color: #000080;">Then</span>
			strCharRight = arrTokens(i+1)
		<span style="color: #000080;">Else</span>
			strCharRight = arrTokens(0)
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>	
&nbsp;
&nbsp;
		<span style="color: #008000;">'------------------------THE CA RULE 110		
</span>		<span style="color: #008000;">'---- CONDITION #01
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #02
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #03
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #04
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;1&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #05
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #06
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;1&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #07
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;1&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				strNextGen = strNextGen &amp; &quot;1&quot;
			<span style="color: #000080;">Else</span>
				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;1&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
		<span style="color: #008000;">'---- CONDITION #08
</span>		<span style="color: #000080;">If</span> strCharLeft=&quot;0&quot; <span style="color: #000080;">And</span> strCharCurrent=&quot;0&quot; <span style="color: #000080;">And</span> strCharRight=&quot;0&quot; <span style="color: #000080;">Then</span>
			<span style="color: #000080;">If</span> i = 0 <span style="color: #000080;">Then</span>
				<span style="color: #008000;">' Starting value
</span>				strNextGen = strNextGen &amp; &quot;0&quot;
			<span style="color: #000080;">Else</span>
				<span style="color: #008000;">' separate with a comma
</span>				strNextGen = strNextGen &amp; &quot;,&quot; &amp; &quot;0&quot;
			<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
		<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	<span style="color: #000080;">Next</span>
&nbsp;
	applyRule110 = strNextGen	
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span>
&nbsp;
&nbsp;
<span style="color: #000080;">Function</span> makeBox(ID, ARRCNTR, X, Y, Z)
&nbsp;
	makeBox = Null
&nbsp;
	<span style="color: #000080;">Dim</span> arrVertices(7)
	<span style="color: #008000;">' BOTTOM VERTICES
</span>	arrVertices(0) = Array( ARRCNTR(0)-X/2, ARRCNTR(1)+Y/2, ARRCNTR(2)-Z/2 )
	arrVertices(1) = Array( ARRCNTR(0)+X/2, ARRCNTR(1)+Y/2, ARRCNTR(2)-Z/2 )
	arrVertices(2) = Array( ARRCNTR(0)+X/2, ARRCNTR(1)-Y/2, ARRCNTR(2)-Z/2 )
	arrVertices(3) = Array( ARRCNTR(0)-X/2, ARRCNTR(1)-Y/2, ARRCNTR(2)-Z/2 )
	<span style="color: #008000;">' TOP VERTICES
</span>	arrVertices(4) = Array( ARRCNTR(0)-X/2, ARRCNTR(1)+Y/2, ARRCNTR(2)+Z/2 )
	arrVertices(5) = Array( ARRCNTR(0)+X/2, ARRCNTR(1)+Y/2, ARRCNTR(2)+Z/2 )
	arrVertices(6) = Array( ARRCNTR(0)+X/2, ARRCNTR(1)-Y/2, ARRCNTR(2)+Z/2 )
	arrVertices(7) = Array( ARRCNTR(0)-X/2, ARRCNTR(1)-Y/2, ARRCNTR(2)+Z/2 )
&nbsp;
	<span style="color: #000080;">Dim</span> strBox
	strBox = rhino.addBox(arrVertices)
&nbsp;
	<span style="color: #000080;">If</span> ID=&quot;0&quot; <span style="color: #000080;">Then</span>
		<span style="color: #008000;">' OFF is white
</span>		<span style="color: #000080;">Call</span> Rhino.ObjectLayer (strBox , &quot;VOID&quot;)
	<span style="color: #000080;">Else</span>
		<span style="color: #008000;">' ON is black
</span>		<span style="color: #000080;">Call</span> Rhino.ObjectLayer (strBox , &quot;SOLID&quot;)
	<span style="color: #000080;">End</span> <span style="color: #000080;">If</span>
&nbsp;
	makeBox = strBox	
&nbsp;
<span style="color: #000080;">End</span> <span style="color: #000080;">Function</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.supermanoeuvre.com/blog/?feed=rss2&amp;p=901</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
