Initial Script

initial state

Script: initial state

Option Explicit
‘Script written by Adolfo Nadal, Ignacio Senra, Sergio Gomez
‘Script copyrighted by <insert company name>
‘Script version viernes, 07 de noviembre de 2008 11:26:37

Call Main()
Sub Main()
Dim i, j,k,l, strPt(),strtmpPt(),arrPt()
Dim Light, strLights, arrLights()
strLights = Rhino.GetObjects(“Lights”,1)
Dim thresholdDist
Dim testDist
Dim scalefactor

‘PROCESS INPUT POINTS SUCH AS LIGHT SOURCES
If IsNull (strLights) Then
Rhino.Print “light sources were required… creating n random sources”
Dim n : n = CInt(Ceil(arbitraryValue(1,4)))
Dim x,y,z
ReDim strLights(n-1)
ReDim arrLights(n-1)
For l = 0 To n-1
x = arbitraryValue(0,20)
y = arbitraryValue(0,13)
z = arbitraryValue(0,-2)
strLights(l)= Rhino.AddPoint(array(0.1*x,0.1*y,0.1*z))
arrLights(l)= array(0.1*x,0.1*y,0.1*z)
Next
Else
For k=0 To Ubound(strLights)
ReDim Preserve arrLights(k)
arrLights(k) = Rhino.PointCoordinates(strLights(k))
Next
End If

‘CREATE LAYERS
AddLayers
Rhino.ObjectLayer strLights,”Lights”
Rhino.EnableRedraw False

‘CREATE POINT GRID FOR CIRCLES
Rhino.CurrentLayer(“Points”)
Dim arrPlane, arrCircles(),arrtmpCircles(), arrCloseLight,dblLength
For i= 0 To 20
thresholdDist = 10
For j = 0 To 13
ReDim Preserve arrtmpPt(j)
arrtmpPt(j) = array(0.1*i,0.1*j,0)
For Each Light In arrLights
testDist = Rhino.Distance (arrtmpPt(j), Light)
If testDist < thresholdDist Then
thresholdDist = testDist
arrCloseLight = Light
End If
‘IF THE SCALE FACTOR IS LOCATED HERE, A MORE UNIFORM PATTERN OCCURS
‘scalefactor = (1/(100*(dblLength)))
Next
dblLength = Rhino.Distance(arrCloseLight,arrtmpPt(j))
‘IF THE SCALE FACTOR HAPPENS TO BE CALCULATED HERE, MORE GRADUAL RESULTS WILL HAPEN
scalefactor = 2*(1/(100*(dblLength)))
If dblLength = thresholdDist Then
Rhino.Print “they are the same” & i & ” ” & j & ” ”
End If
If dblLength = testDist Then
Rhino.Print “they are the same…2…” & i & ” ” & j & ” ”
End If
arrPlane = Rhino.PlaneFromFrame(arrtmpPt(j),array(0.1*i+1,0.1*j,0),array(0.1*i,0.1*j+1,0))
ReDim Preserve arrtmpCircles(j) : arrtmpCircles(j)=Rhino.AddCircle(arrPlane,scalefactor)
Next
ReDim Preserve arrPt(i)
arrPt(i) = arrtmpPt
‘ReDim Preserve strPt(i)
‘strPt(i) = Rhino.AddPoints(arrPt(i))
ReDim Preserve arrCircles(i)
arrCircles(i) = arrtmpCircles
Next

‘WE NEED TO CONVERT THE NESTED ARRAY arrCircles INTO A 1-DIMENSIONAL ARRAY
Dim counter, p, m, arrCirclesIntersection()
counter = 0
For p = 0 To Ubound(arrCircles)
For m = 0 To Ubound(arrCircles(l))
ReDim Preserve arrCirclesIntersection(counter)
arrCirclesIntersection(counter) = arrCircles(p)(m)
counter = counter +1
Next
Next

‘NOW WE CAN PASS THE DATA TO THE FUNCTION
MultipleDifferences arrCirclesIntersection

‘FINALIZE SCRIPT AND WRAP-UP
Rhino.CurrentLayer(“Script”)
Rhino.Print “Done”
Rhino.EnableRedraw True

End Sub

Function arbitraryValue(min, max)
Randomize
arbitraryValue = Int((max – min + 1) * Rnd + min)
End Function

Function AddLayers
If Not IsLayer(“Script”) Then
Rhino.AddLayer “Script”,RGB(0, 0, 0),True,False
End If

If Not IsLayer(“Lights”) Then
Rhino.AddLayer “Lights”,RGB(128, 0, 128),True,False,”Script”
Rhino.LayerLinetype “Polylines”, “Continuous”
End If

If Not IsLayer(“Points”) Then
Rhino.AddLayer “Points”,RGB(0, 0, 0),True,False,”Script”
Rhino.LayerLinetype “Polylines”, “Continuous”
End If
End Function

Function MultipleDifferences(strCrvs)

Rhino.Print “calculating intersection for ” & CStr(Ubound(strCrvs)^2) & ” curves. Please wait…”
Dim strCrv1, strCrv2, strCrvresult
Dim i, j
For i=0 To Ubound(strCrvs)
strCrv1=strCrvs(i)
For j=0 To Ubound(strCrvs)
strCrv2=strCrvs(j)
strCrvresult = Rhino.CurveBooleanDifference (strCrv1,strCrv2)
If Not IsNull(strCrvresult) Then
strCrv1 = strCrvresult(0)
‘ERASE ALL INBETWEEN STEPS IN THE CALCULATION OF SUCCESIVE DIFFERENCES
If j < Ubound(strCrvs) And i <> Ubound(strCrvs) Then
Rhino.HideObjects strCrvresult
Else
‘FOR THE LAST CURVE IT WORKS DIFFERENTLY
If i=Ubound(strCrvs) Then
If j<Ubound(strCrvs)-1 Then
Rhino.HideObjects strCrvresult
End If
End If
End If
End If
If j Mod 50 = 0 And i Mod 40= 0 And i>0 Then
Rhino.Print (i/Ubound(strCrvs)) & “% completed”
End If
Next
Rhino.EnableRedraw True
Rhino.EnableRedraw False
Next
Rhino.Print “completed”
Rhino.DeleteObjects strCrvs

End Function

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s