(n)certainties

GSAPP- Fall 2010

(n)certainties header image 3

Code Asphyxia

addForest


Option Explicit
'Script written by Massimiliano Orzi, Pablo Ros and Ezio Blasetti

Call Main()
Sub Main()

' user input

Dim intHowManyTrees : intHowManyTrees = Rhino.GetInteger("how many trees is a forest",20,1,50)
Dim intHowManyGenerations : intHowManyGenerations = Rhino.GetInteger("how many generations is a tree?",6,1,10)
Dim dblForestLength : dblForestLength = Rhino.GetReal("was is the desired length of your forest",50)
Dim dblForestWidth : dblForestWidth = Rhino.GetReal("was is the desired width of your forest",50)
Dim dblInitLength : dblInitLength = Rhino.GetReal("was is the desired length of the first main Branch?",10)
Dim ang : ang = Rhino.GetReal("angle of rotation", 30, 1, 180)
Dim scale : scale = Rhino.GetReal("scale of branch", 0.9)
'loop for number of generations i
'ReDim arrgenerations (Ubound (intHowManyGenerations))
Dim layer_0 : layer_0 = Rhino.AddLayer("0")
Dim i
For i=0 To intHowManyTrees
Dim arrSeed : arrSeed = Array(Rnd*dblForestLength, Rnd*dblForestWidth,0)
Dim strLine : strLine = Rhino.AddLine(Array (arrSeed(0), arrSeed (1), arrSeed (2)+Rnd*3), Array(arrSeed(0), arrSeed(1),arrSeed(2)+Rnd*dblInitLength+3))

Call Rhino.ObjectLayer (strLine, "0" )
Call Rhino.ObjectName (strLine, i)
Next
Dim j,vec
ReDim arrbranch (intHowManyGenerations)
For i=1 To intHowManyGenerations
'select the elements
arrbranch (i) = Rhino.ObjectsByLayer (i-1)
Dim strBranch
For j=0 To Ubound(arrBranch(i))
strBranch = arrBranch(i)(j)
Dim strParentName : strParentName = Rhino.ObjectName(strBranch)
' get start and end points
Dim arrStartPt : arrStartPt = Rhino.CurveStartPoint(strBranch)
Dim arrEndPt : arrEndPt = Rhino.CurveEndPoint(strBranch)

' get a vector between start and end
vec = Rhino.VectorCreate(arrEndPt, arrStartPt) ''''' vec(x,y,z)

' scale vector
vec = Rhino.VectorScale(vec, scale)

' rotate vectors
Dim arrPlane : arrPlane = Rhino.CurvePerpFrame (strBranch, Rhino.CurveDomain(strBranch)(1))

Dim arrRotAxis
Dim layer
layer = Rhino.AddLayer ( i )

arrRotAxis = arrPlane(Int(Rnd*3))
Dim vec1 : vec1 = Rhino.VectorRotate(vec, ang, arrRotAxis)
' add the vector to the end point
Dim newEndPt : newEndPt = Rhino.VectorAdd(arrEndPt, vec1)

Dim line1: line1 = Rhino.AddLine(arrEndPt, newEndPt)
Call Rhino.ObjectLayer (line1, i)
Call Rhino.ObjectName(line1, strParentName)

If rnd<0.8 Then arrRotAxis = arrPlane(Int(Rnd*3)) Dim vec2 : vec2 = Rhino.VectorRotate(vec, -ang, arrRotAxis) Dim newEndPt2 : newEndPt2 = Rhino.VectorAdd(arrEndPt, vec2) Dim line2: line2 = Rhino.AddLine(arrEndPt, newEndPt2) Call Rhino.ObjectLayer (line2, i) Call Rhino.ObjectName(line2, strParentName) End If If rnd<0.2 Then arrRotAxis = arrPlane(Int(Rnd*3)) Dim vec3 : vec3 = Rhino.VectorRotate(vec, ang*(rnd-0.5)*2, arrRotAxis) Dim newEndPt3 : newEndPt3 = Rhino.VectorAdd(arrEndPt, vec3) Dim line3: line3 = Rhino.AddLine(arrEndPt, newEndPt3) Call Rhino.ObjectLayer (line3, i) Call Rhino.ObjectName(line3, strParentName) End If Next Next End Sub

addCrvsFromTurtleLsystem


Option Explicit
'Script written by Massimiliano Orzi, Pablo Ros and Ezio Blasetti

Call Main()
Sub Main()

Dim arrLines : arrLines = Rhino.GetObjects("",4)
Dim strLine, i : i = 0
Dim arrNames : arrNames = arrLines
For Each strLine In arrLines
arrNames(i) = CInt(Rhino.ObjectLayer(strLine))
i = i+1
Next

Call rhino.EnableRedraw(False)
Dim arrSort : arrSort = Rhino.SortNumbers (arrNames)

Dim arrLeafs : arrLeafs = Rhino.ObjectsByLayer(arrSort(Ubound(arrSort)))
Dim arrPaths : arrPaths = arrLeafs
Dim strLeaf
For Each strLeaf In arrLeafs
ReDim arrPts(0)
arrPts(0) = Rhino.CurveEndPoint(strLeaf)
Dim strLeafName : strLeafName = Rhino.ObjectLayer(strLeaf)
Dim j : j = CInt(strLeafName)
Dim strCurrentBranch : strCurrentBranch = strLeaf
Dim arrParLeafs, strParent
Do
If j > 0 Then
arrParLeafs = Rhino.ObjectsByLayer(CStr(j-1))
For i = 0 To Ubound(arrParLeafs)
If Rhino.PointCompare (Rhino.CurveStartPoint(strCurrentBranch),Rhino.CurveEndPoint(arrParLeafs(i))) Then
strParent = arrParLeafs(i)
Exit For
End If
Next
ReDim Preserve arrPts(Ubound(arrPts)+1)
arrPts(Ubound(arrPts)) = Rhino.CurveEndPoint(strParent)
strCurrentBranch = strParent
j = j - 1
ElseIf j = 0 Then
arrParLeafs = Rhino.ObjectsByName(0)
For i = 0 To Ubound(arrParLeafs)
If Rhino.PointCompare (Rhino.CurveStartPoint(strCurrentBranch),Rhino.CurveEndPoint(arrParLeafs(i))) Then
strParent = arrParLeafs(i)
Exit For
End If
Next
ReDim Preserve arrPts(Ubound(arrPts)+1)
arrPts(Ubound(arrPts)) = Rhino.CurveStartPoint(strParent)
strCurrentBranch = strParent
j = -1
Else
Exit Do
End If
Loop

Call Rhino.AddCurve(arrPts)

Next
rhino.EnableRedraw(True)

End Sub

strangler

click on the image for the strangler processing code by Miranda Romer Luna