Diffuse Curve
This is a RhinoScript that I wrote about a few months ago in: http://crtl-i.com/blog/2008/12/diffuse-noise/
It will take a curve and diffuse it into many curves according to a few parameters:
devRate: deviation rate
vecLenMax: maximum length of a particle
vecLenMin: minimum length of a particle
noParticle: number of total particles
If vecLenMax and vecLenMin are the same, all the particles will have the same length.
—
Option Explicit
Call Diffuse()
Sub Diffuse()
Dim devRate : devRate = 0.01
Dim vecLenMax : vecLenMax = 1
Dim vecLenMin : vecLenMin = 3
Dim noParticle : noParticle = 100
Dim aCrvs : aCrvs = Rhino.GetObjects(“Select Curves”, 4)
Dim i,n
Dim aPts()
Dim crvDom, crvParam, crvLen
Randomize
For i = 0 To UBound(aCrvs)
n = 0
Dim strCrv : strCrv = aCrvs(i)
crvDom = Rhino.CurveDomain(strCrv)
crvLen = Rhino.CurveLength(strCrv)
Rhino.EnableRedraw False
Do Until n = noParticle
crvParam = (RN(0.00, 1.00)) * (crvDom(1))
ReDim Preserve aPts(n)
aPts(n) = Rhino.EvaluateCurve(strCrv, crvParam)
Dim devPt : devPt = aPts(n)
Dim devX : devX = crvLen * devRate * RN(-1,1) + devPt(0)
Dim devY : devY = crvLen * devRate * RN(-1,1) + devPt(1)
Dim devZ : devZ = crvLen * devRate * RN(-1,1) + devPt(2)
Dim devPt2 : devPt2 = Array(devX, devY, devZ)
Dim rndPt : rndPt = Array(RN(-1,1), RN(-1,1), RN(-1,1))
Dim rndPt2 : rndPt2 = Rhino.PointAdd(devPt2, rndPt)
If n >= 1 Then
Dim vecDir : vecDir = Rhino.AddLine(devPt2, rndPt2)
Dim vecLen : vecLen = RN(vecLenMin, vecLenMax)
Dim Xform : Xform = Rhino.XformScale(devPt2, vecLen)
Rhino.TransformObject vecDir, Xform, True
End If
n = n + 1
Loop
Rhino.EnableRedraw True
Next
End Sub
Function RN (nMin, nMax)
RN = Null
Randomize
RN = (nMax – nMin) * Rnd + nMin
End Function