11.9 grid curve script_Sukie & Shen

Option Explicit
‘Script written by <insert name>
‘Script copyrighted by <insert company name>
‘Script version 2009年10月15日 13:40:39

Call Main()
Sub Main()
Dim h
h = rhino.GetInteger(“give the height of robot”,500)
Dim minangle,maxangle

Dim gen1
gen1 = rhino.getinteger(“generation”,10)
Dim strn
strn = rhino.GetInteger(“curve dividing number”,30)
Dim ptn
ptn = rhino.getinteger(“give the dividing number of each circle”,6)
Dim noise
noise = rhino.getinteger(“give the z direction deviation for the points”,120)

‘———————————————– make the grid for the trees to grow
Dim m,p
Dim number,number1
number = rhino.getinteger(“give the number of x grid”,3)
number1= rhino.GetInteger(“give the number of y grid”,3)
Dim gridlength
gridlength = rhino.getinteger(“give the grid inteval”,1500)
Dim pt1,pt2
Dim robline
Dim stpt,edpt
Dim lenvec
Dim length
Dim rtvec
Dim ptarray
Dim i
Dim cenline
Dim l
Dim arrdvpts
Dim dvpts()
ReDim Preserve dvpts(ptn)
Dim degree
ReDim degree(ptn)
Dim closestpt
ReDim closestpt(ptn)
Dim vector
ReDim vector(ptn)
Dim data
Dim outpts
ReDim outpts(ptn)
Dim countgp
countgp = 0
For m = 0 To number
For p = 0 To number1
‘———————————————– get the properties of the robot line
pt1 = array(m*gridlength,p*gridlength,0)
pt2 = array(m*gridlength,p*gridlength,h)
robline = rhino.AddLine(pt1,pt2)
stpt = Rhino.CurveStartPoint(robline)
Call rhino.AddPoint(stpt)
edpt = rhino.CurveEndPoint(robline)
Call rhino.AddPoint(edpt)
lenvec = rhino.vectorcreate(edpt,stpt)
length = rhino.CurveLength(robline)
‘rtvec = Rhino.Curveframe(robline,rhino.CurveClosestPoint(robline,edpt))
rtvec = rhino.CurveNormal(robline)
If isnull (rtvec) Then Exit Sub
Dim gen
gen = gen1
Call rotatline(robline,rtvec,stpt,edpt,lenvec,gen)
‘——————————————————–select all the points and generate the central curve
ptarray = Rhino.ObjectsByType(1)
For i = 0 To ubound(ptarray)
ptarray(i) = rhino.pointcoordinates(ptarray(i))
Next
ptarray = Rhino.SortPointList(ptarray)

cenline = rhino.AddInterpCurve(ptarray)
Call rhino.LockObject(cenline)
Dim deletepts
deletepts = rhino.ObjectsByType(1)

Call rhino.deleteobjects(deletepts)

Next
Next
Dim deletecurs
deletecurs = rhino.ObjectsByType(4)

‘Call rhino.SelectObjects(deletecurs)
‘Call rhino.Command (“_delete”)
‘Call rhino.Command (“_unlock”)
End Sub
Function rotatline(robline,rtvec,stpt,edpt,lenvec,gen)

Dim line
line = rhino.CopyObject(robline,stpt,edpt)
line  = rhino.RotateObject(line,edpt,(-30+rnd*60),rtvec)
Dim endpt
endpt = rhino.CurveEndPoint(line)
Dim startpt
startpt = rhino.CurveStartPoint(line)

Dim endvec
endvec = rhino.CurveNormal(line)
Dim lvec
lvec = rhino.VectorCreate(endpt,startpt)
‘    ptarray(n) = startpt
‘    n = n+1
gen = gen -1
If gen = 0 Then Exit Function
Dim a
a = rnd*1
Dim line2
Dim spt
Dim ept
Dim lenvec2
Dim rtvec2
If a < 0.33 Then
line2 = rhino.RotateObject(line,startpt,120,lenvec)
spt = rhino.CurveStartPoint(line2)
ept = rhino.CurveEndPoint(line2)
lenvec2 = rhino.VectorCreate(ept,spt)
rtvec2 = rhino.CurveNormal(line2)
Call rhino.AddPoint(ept)
Call rotatline(line2,rtvec2,spt,ept,lenvec2,gen)
End If
If a > 0.33 And a < 0.66 Then
line2 = rhino.RotateObject(line,startpt,240,lenvec)
spt = rhino.CurveStartPoint(line2)
ept = rhino.CurveEndPoint(line2)
lenvec2 = rhino.VectorCreate(ept,spt)
rtvec2 = rhino.CurveNormal(line2)
Call rhino.AddPoint(ept)
Call rotatline(line2,rtvec2,spt,ept,lenvec2,gen)
End If
If a > 0.66 And a<1 Then
Call rhino.AddPoint(endpt)
Call rotatline(line,endvec,startpt,endpt,lvec,gen)
End If

End Function

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s