SG&RM_particles_random_range_color

Option Explicit
‘Script written by <reihaneh_sara>
‘Script copyrighted by <insert company name>
‘Script version Friday, 4 December 2009 11:19:47

Call Main()
Sub Main()

Dim aCrvs
Dim i,j, k
Dim aps, ap, pt, lColor,Colpt
Dim range, rangeLocal, nSeeds, n
Dim l,p
‘Dim component : component = rhino.GetObjects (“sel Component”)
‘Dim compentCntr : compentCntr = rhino.GetPointCoordinates (“sel Comp Cntr”)
Dim vect,angle,strobj
Dim scale
Dim strpts()
Dim count : count = 0
Dim p1,p2, p3, m, Pspread

aCrvs =  rhino.getobjects(“pick path”, 4)

nSeeds = 100
PSpread = 5
‘n = 25

Call rhino.EnableRedraw(False)
For i =0 To UBound(aCrvs)
range=30
aps =DivideCurve(aCrvs(i),nSeeds)
For j = 0 To Ubound(aps)

ReDim Preserve strPts(20)
For k = 0 To 20
‘For k = 0 To int(n-(Ubound(aps)/n*j))
‘rangeLocal = range/Ubound(aps)*j

” SET RANGE BY HALF CRVS
If j < Ubound(aps)/2 Then
rangeLocal = range/(Ubound(aps)/2)*j
Else
rangeLocal = range – (range/(Ubound(aps)/2)*j/2)
End If
” PT COORD
ap = array(aps(j)(0)+ random(-rangeLocal,rangeLocal),_
aps(j)(1)+random(-rangeLocal,rangeLocal),_
aps(j)(2)+random(-rangeLocal,rangeLocal))

” DRAW
‘ReDim Preserve strPts(count)
‘strpts(k) = rhino.addpoint(ap)
‘pt = rhino.addpoint(ap)

” draw particul
For m = 0 To 4
p1 = array(ap(0)+random(-PSpread,PSpread),_
ap(1)+random(-PSpread,PSpread),_
ap(2)+random(-PSpread,PSpread))
p2 = array(ap(0)+random(-PSpread,PSpread),_
ap(1)+random(-PSpread,PSpread),_
ap(2)+random(-PSpread,PSpread))
p3 = array(ap(0)+random(-PSpread,PSpread),_
ap(1)+random(-PSpread,PSpread),_
ap(2)+random(-PSpread,PSpread))
Call rhino.AddCurve(array(ap,p1,p2, p3))
Next

” COLOR
If j < Ubound(aps)/2 Then
lColor = rgb(255/(Ubound(aps)/2)*j,191/(Ubound(aps)/2)*j,0)
Else
lColor = rgb(255-(255/(Ubound(aps)/2)*j/2),191-(191/(Ubound(aps)/2)*j/2),0)
End If
‘Call rhino.ObjectColor(strpts, lColor)
‘count = count+1
Next

Next
Next

‘    For p=0 To ubound (strpts)
‘        For l=0 To ubound (component)
‘            angle = random (0,360)
‘            vect = array (random(-10,10),random(-10,10),random(-10,10))
‘            scale = random (0.5,1)

‘            pt = rhino.PointCoordinates (strpts(p))
‘            strobj = rhino.CopyObject (component(l),compentCntr(0),pt)
‘            rhino.RotateObject strobj,pt,angle,vect, False
‘            rhino.ScaleObject strobj,pt,array(scale,scale,scale)
‘            ‘Call rhino.ObjectColor(strobj, Colpt)

‘        Next
‘    Next

Call rhino.EnableRedraw(True)
‘Call Rhino.DeleteObjects (strPts)

End Sub

Function random(min,max)
random=Rnd*(max-min)+min
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