''-------------------------------------- '' Lindenmeyer-System Script '' by John Snavely ''-------------------------------------- '' *** requires the Dynamic Array class in the default Rhino library to be loaded first!! '' ''-------------------------------------- '' This is a hacked together Rhinoscript for generating L-Systems. Be careful with the recursions, '' can get out of hand pretty quickly. Sorry there's no comments! ''-------------------------------------- '' '' dim xrule : xrule = "-FYFX" dim yrule : yrule = "FXFY+" dim angle : angle = 0 dim angle2 : angle2 = 90 dim startstr : startstr = "FX" dim tempstr : tempstr = "" dim i dim length dim oldpt dim pi dim unit dim recursions : recursions =8 dim t1, t2, t3 ''dim splineRA Set splineRA = New DynamicArray ' Create an instance of DynamicArray oldpt = Array(0,0,0) unit = 1 pi=4*Atn(1) 'call Rhino.MessageBox(pi) while(recursions > 0) length = Len(startstr) for i = 0 to length char = Mid(startstr,1,1) if(Len(startstr)>0)then startstr = Right(startstr,(Len(startstr)-1)) 'call Rhino.MessageBox(startstr) Select Case char Case "F" tempstr = tempstr&"F" Case "+" tempstr = tempstr&"+" Case "-" tempstr = tempstr&"-" Case "*" tempstr = tempstr&"*" Case "%" tempstr = tempstr&"%" Case "Y" tempstr = tempstr&yrule Case "X" tempstr = tempstr&xrule End Select end if next 'call Rhino.MessageBox(tempstr) startstr = tempstr tempstr = "" recursions = recursions -1 wend 'call Rhino.MessageBox(startstr) ' now draw it while(Len(startstr)>0) length = Len(startstr) for i = 0 to length char = Mid(startstr,1,1) if(Len(startstr)>0)then startstr = Right(startstr,(Len(startstr)-1)) 'call Rhino.MessageBox(oldpt(0)&" , "& oldpt(1)& " , " &oldpt(2)) Select Case char Case "F" t1 = oldpt(0)+(unit*Cos((pi/180)*angle)*Sin((pi/180)*angle2)) t2 = oldpt(1)+(unit*Sin((pi/180)*angle)*Sin((pi/180)*angle2)) t3 = oldpt(2)+(unit*Cos((pi/180)*angle2)) gotopt = Array(t1,t2,t3) tempstr = tempstr & " F " 'gotopt = Array(oldpt(0)+(unit*Cos((pi/180)*angle)),oldpt(1)+(unit*Sin((pi/180)*angle)),0) ''Call Rhino.AddPoint(oldpt) 'Call Rhino.AddEdgeSrf(Array(oldpt,gotopt)) splineRA.Add(gotopt) oldpt = gotopt ''Case "+" angle = angle + 22 ''Case "-" angle = angle - 23 ''Case "*" angle2 = angle2 + 52 ''Case "%" angle2 = angle2 - 168 Case "+" angle = angle + 12 tempstr = tempstr & "+" Case "-" angle = angle - 33 tempstr = tempstr & "-" Case "*" angle2 = angle2 + 22 tempstr = tempstr & "*" Case "%" angle2 = angle2 - 248 tempstr = tempstr & "%" End Select end if next wend ''hack -- not sure why dynamic array isn't working redim spArray(splineRA.Count()-1) for i = 0 to splineRA.Count()-1 spArray(i) = splineRA.DataArray()(i) next ''call Rhino.AddInterpCurve(spArray) '' call Rhino.AddPolyLine(spArray) Rhino.AddPointCloud(spArray) 'call Rhino.MessageBox(startstr)