(n)certainties/LAB M4

USC / 2010-2011

(n)certainties/LAB M4 header image 3

Sugar & CC_Final Code

[Generate random curves on surface]

Option Explicit
‘Script written by <Suqi>

Call Main()
Sub Main()
Call rhino.EnableRedraw(True)
Dim idSrf : idSrf = Rhino.GetObject(“Pick surface to generate structure”, 8, True, True)
If IsNull(idSrf) Then Exit Sub

Dim layer1 : layer1 = Rhino.AddLayer (“line”,RGB(0, 0, 0))
Dim layer2 : layer2 = Rhino.AddLayer (“structure”,RGB(0, 255, 255))

Dim udiv, vdiv
udiv = 1
vdiv = 100

Dim radius : radius = 0.5

Dim uDomain : uDomain = Rhino.SurfaceDomain(idSrf, 0)
Dim vDomain : vDomain = Rhino.SurfaceDomain(idSrf, 1)

Dim ustep : ustep = (uDomain(1) – uDomain(0)) /udiv
Dim vstep : vstep = (vDomain(1) – vDomain(0)) /vdiv

Dim u, v
Dim k
Dim pta, ptb
Dim sec1, sec2
Dim plane1, plane2
Dim curve
For u = 0 To uDomain(1) Step ustep

k =U+CInt(80*(Rnd()-0.5))*Ustep
If k < 0 Then
k = CInt(2*Rnd())*Ustep
End If
If k > UDomain(1) Then
k = Udomain(1)- CInt(3*Rnd())*Ustep
End If

pta = array(u,Vdomain(1))
ptb = array(k,Vdomain(0))
curve = AddInterpCrvOnSrfUV(idSrf, array(pta,ptb))
”Call rhino.ObjectLayer(curve,Layer1)
” Call rectpipe(curve, idsrf, radius, layer2)

Next

For v = 0 To 13*vstep Step vstep

k =v+CInt(80*(Rnd()-0.5))*vstep
If k < 0 Then
k = CInt(6*Rnd())*vstep
End If

pta =array(uDomain(0),v)
ptb = array(udomain(1),k)
curve = AddInterpCrvOnSrfUV(idSrf, array(pta,ptb))
” Call rhino.ObjectLayer(curve,Layer1)
” Call rectpipe(curve, idsrf, radius, layer2)
Next

For v = 13*vstep To 25*vstep Step vstep

k =v+CInt(80*(Rnd()-0.5))*vstep

pta =array(uDomain(0),v)
ptb = array(udomain(1),k)
curve = AddInterpCrvOnSrfUV(idSrf, array(pta,ptb))
” Call rhino.ObjectLayer(curve,Layer1)
” Call rectpipe(curve, idsrf, radius, layer2)

k =v+CInt(80*(Rnd()-0.5))*0.5*vstep

pta =array(uDomain(1),v+0.5*vstep)
ptb = array(udomain(0),k)
curve = AddInterpCrvOnSrfUV(idSrf, array(pta,ptb))
” Call rhino.ObjectLayer(curve,Layer1)
Next

For v = 26*vstep To vDomain(1) Step vstep

k =v+CInt(80*(Rnd()-0.5))*vstep
If k > vDomain(1) Then
k = vdomain(1)- CInt(6*Rnd())*vstep
End If
pta =array(uDomain(0),v)
ptb = array(udomain(1),k)
curve = AddInterpCrvOnSrfUV(idSrf, array(pta,ptb))
” Call rhino.ObjectLayer(curve,Layer1)
” Call rectpipe(curve, idsrf, radius, layer2)

k =v+CInt(80*(Rnd()-0.5))*(vstep/3)
If k > vDomain(1) Then
k = vdomain(1)- CInt(6*Rnd())*(vstep/3)
End If
pta =array(uDomain(1),v+vstep/3)
ptb = array(udomain(0),k)
curve = AddInterpCrvOnSrfUV(idSrf, array(pta,ptb))
” Call rhino.ObjectLayer(curve,Layer1)

k =v+CInt(80*(Rnd()-0.5))*(2*vstep/3)
If k > vDomain(1) Then
k = vdomain(1)- CInt(6*Rnd())*(2*vstep/3)
End If
pta =array(uDomain(1),v+2*vstep/3)
ptb = array(udomain(0),k)
curve = AddInterpCrvOnSrfUV(idSrf, array(pta,ptb))
” Call rhino.ObjectLayer(curve,Layer1)

Next

‘ For u = 0 To uDomain(1) Step ustep

‘  Dim x, a
‘  a = Rnd()
‘  If a >= 0.5 Then
‘   x = udomain(0)
‘  Else
‘   x = udomain(1)

‘  End If

‘  k = (5+CInt(Rnd()*33))*vstep

‘  pta = array(u,Vdomain(0))
‘  ptb = array(x,k)
‘  curve = AddInterpCrvOnSrfUV(idSrf, array(pta,ptb))
‘  ” Call rhino.ObjectLayer(curve,Layer1)
‘  ” Call rectpipe(curve, idsrf, radius, layer2)
‘ Next

‘ For u = 0 To uDomain(1) Step ustep


‘  a = Rnd()
‘  If a >= 0.5 Then
‘   x = udomain(0)
‘  Else
‘   x = udomain(1)

‘  End If

‘  k = (5+CInt(Rnd()*33))*vstep

‘  pta = array(u,Vdomain(1))
‘  ptb = array(x,k)
‘  curve = AddInterpCrvOnSrfUV(idSrf, array(pta,ptb))
‘  ”  Call rhino.ObjectLayer(curve,Layer1)
‘ Next

End Sub

Function Between(ByVal A, ByVal B)
Between = Array((A(0)+B(0))/2, (A(1)+B(1))/2, (A(2)+B(2))/2)
End Function