NO&BR_infect path from path_with gradient

Option Explicit
‘Script written by <insert name>
‘Script copyrighted by <insert company name>
‘Script version Monday, 09 November 2009 18:58:49

Call Main()
Sub Main()

 Dim i,j, k
 Dim acs, apts
 Dim aPlan, dRad, dRadMax, dRadDefault
 Dim sCrv, aparam
 Dim aPt, aPtOnCrv
 Dim dTreshold, dD
 Dim RedIDs
 Dim Allpts
 Dim dThresh
 Dim iterations
 Dim sp, sC, sFib
 Dim nFibers, aptsCircle
 
 ‘Allpts = rhino.GetObjects (“sel pts”,1)
 acs = rhino.GetObjects(“pick crvs”, 4)
 If isnull(acs) Then Exit Sub
 
 sCrv = rhino.GetObject(“pick path”, 4)
 If isnull(sCrv) Then Exit Sub
 
 dTreshold = 3
 dRadMax = .25
 dRadDefault = 0.03
 nFibers = 15
 
 Call Rhino.EnableRedraw(False)
 ” ———————————————————–
 ” divide crvs
 For i=0 To ubound (aCs)
  ‘apts = Rhino.CurveMidPoint(acs(i))
  ‘apts = rhino.DivideCurveLength(acs(i), 0.25)
  apts = rhino.DivideCurve(acs(i), 2)
  
  ‘To use midpt, firt divide crv by distance – but not array
  ‘apts = Rhino.CurveMidPoint(acs(i))
  
  
  ReDim aptsCircle(UBound(apts))
  For j = 0 To UBound(apts)
   
   ” PT
   ‘sp = rhino.addPoint(apts(j))
   
   ”PATH
   aParam = rhino.CurveClosestPoint(sCrv, aPts(j))
   aPtOnCrv = rhino.EvaluateCurve(sCrv,aParam)
   dD = rhino.Distance(aPts(j),aPtOnCrv)
   
   ” RAD
   If dD < dTreshold Then
    dRad = dRadmax – (dRadMax * dD/dTreshold) + dRadDefault
   Else
    dRad = dRadDefault
   End If
   
   ” CIRCLE
   ‘aPlan = Rhino.MovePlane(Rhino.WorldXYPlane(),apts(j))
   aPlan = rhino.PlaneFromNormal(apts(j), rhino.CurveTangent(aCs(i),rhino.CurveClosestPoint(aCs(i), aPts(j))))
   sC = Rhino.AddCircle (aPlan,dRad)
   
   ‘   ” COLOR
   ‘   If dD < dTreshold Then
   ‘    ‘Call rhino.ObjectColor(sP, rgb(255-(200*dD/dTreshold),0,0))
   ‘    Call rhino.ObjectColor(sC, rgb(255-(200*dD/dTreshold),0,0))
   ‘   Else
   ‘    Call rhino.ObjectColor(sC, vbBlue)
   ‘   End If
   
   
   
   ” div circle
   aptsCircle(j) = rhino.DivideCurve(sC, nFibers)
   
   Call rhino.DeleteObject(sC)
   
  Next
  
  ReDim aPCrv(UBound(apts))
  For j = 0 To nFibers-1
   For k = 0 To UBound(apts)
    ‘aPCrv(k) = aptsCircle(k)(j)
    aPCrv(k) = aptsCircle(k)((nFibers-1)*rnd)
   Next
   ‘sFib = rhino.addInterpCurve(aPCrv)
   sFib = rhino.addCurve(aPCrv)
   Call rhino.ObjectColor(sFib, vbgreen)
  Next
  ‘  
 Next

 Call Rhino.EnableRedraw(True)
 
End Sub

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