11.9 triangle and attractor Sukie & Shen

Option Explicit
‘Script written by <insert name>
‘Script copyrighted by <insert company name>
‘Script version 2009年11月6日 0:39:25

Call Main()
Sub Main()
Dim strn
strn = rhino.GetInteger(“curve dividing number”,30)
Dim ptn
ptn = rhino.getinteger(“give the dividing number of each circle”,4)
Dim noise
noise = rhino.getinteger(“give the z direction deviation for the points”,30)
Dim u
Dim arrcenline
arrcenline = rhino.GetObjects(“pick the curves to transform”, 4)
Dim arratt
arratt = rhino.getobjects(“get all the attractors”,1)
Dim y
For y = 0 To ubound(arratt)
arratt(y) = rhino.PointCoordinates(arratt(y))
Next

Dim l
Dim arrdvpts
Dim dvpts()
ReDim Preserve dvpts(ptn)
Dim degree
ReDim degree(ptn)
Dim closestpt
ReDim closestpt(ptn)
Dim vector
ReDim vector(ptn)
Dim data
Dim outpts
ReDim outpts(ptn)
Dim allcurves
Dim arrlayer
ReDim arrlayer(ubound(arrcenline))
Dim count1:count1 = 0
For u = 0 To ubound(arrcenline)
arrdvpts = rhino.DivideCurve(arrcenline(u),strn,True, True)
Dim count :count = 1
Dim k,arrcircles
ReDim arrcircles(ubound(arrdvpts))
Dim arrnum
ReDim arrnum(ubound(arrdvpts))
For k = 0 To ubound(arrdvpts)
count = count +0.2
Dim closestpt1,index
index = rhino.PointArrayClosestPoint(arratt,arrdvpts(k))
closestpt1 = arratt(index)
Dim distance
distance = rhino.distance (arrdvpts(k),closestpt1)
Dim strPoncurve: strPoncurve = rhino.CurveClosestPoint(arrcenline(u), arrdvpts(k))
Dim strframe: strframe = rhino.Curveperpframe(arrcenline(u), strPoncurve)
arrcircles(k) = rhino.addcircle(strframe,distance/15)               ‘(10*sin(count*rhino.Pi)  30*sin(count*rhino.Pi)+40+
Next
‘——————————————————————————-generate the points
Dim vecscale
vecscale = 3+3*rnd
For k = 0 To ubound(arrcircles)
data = rhino.CurveDomain(arrcircles(k))
arrnum(k) = array(outpts)
For l = 0 To ptn
If l = 0 Then
degree(l) = 0.5*rnd*(data(1)-data(0))/ptn
dvpts(l) = rhino.EvaluateCurve(arrcircles(k),degree(l))
outpts(l) = rhino.AddPoint(dvpts(l))
closestpt(l) = rhino.CurveClosestPoint(arrcenline(u), dvpts(l))
closestpt(l) = rhino.evaluatecurve(arrcenline(u),closestpt(l))
vector(l) = rhino.vectorcreate(dvpts(l),closestpt(l))
vector(l) = rhino.VectorScale(vector(l), (1.2+0.8*rnd))
outpts(l) = rhino.moveobject(outpts(l),vector(l))
outpts(l) = rhino.PointCoordinates(outpts(l))
arrnum(k)(0)(l) = array(outpts(l)(0) + rnd*randomWithinRange(-noise,noise),outpts(l)(1) + rnd*randomWithinRange(-noise,noise),outpts(l)(2) + rnd*randomWithinRange(-noise,noise))
End If
If l > 0 And l < ptn Then
degree(l) = (l-0.5+rnd)*(data(1)-data(0))/ptn
dvpts(l) = rhino.EvaluateCurve(arrcircles(k),degree(l))
outpts(l) = rhino.AddPoint(dvpts(l))
closestpt(l) = rhino.CurveClosestPoint(arrcenline(u), dvpts(l))
closestpt(l) = rhino.evaluatecurve(arrcenline(u),closestpt(l))
vector(l) = rhino.vectorcreate(dvpts(l),closestpt(l))
vector(l) = rhino.VectorScale(vector(l), (1.2+0.8*rnd))
outpts(l) = rhino.moveobject(outpts(l),vector(l))
outpts(l) = rhino.PointCoordinates(outpts(l))
arrnum(k)(0)(l) = array(outpts(l)(0) + rnd*randomWithinRange(-noise,noise),outpts(l)(1) + rnd*randomWithinRange(-noise,noise),outpts(l)(2) + rnd*randomWithinRange(-noise,noise))
End If
If l = ptn Then
degree(l) = (l-0.5+0.5*rnd)*(data(1)-data(0))/ptn
dvpts(l) = rhino.EvaluateCurve(arrcircles(k),degree(l))
outpts(l) = rhino.AddPoint(dvpts(l))
closestpt(l) = rhino.CurveClosestPoint(arrcenline(u), dvpts(l))
closestpt(l) = rhino.evaluatecurve(arrcenline(u),closestpt(l))
vector(l) = rhino.vectorcreate(dvpts(l),closestpt(l))
vector(l) = rhino.VectorScale(vector(l), (1.2+0.8*rnd))
outpts(l) = rhino.moveobject(outpts(l),vector(l))
outpts(l) = rhino.PointCoordinates(outpts(l))
arrnum(k)(0)(l) = array(outpts(l)(0) + rnd*randomWithinRange(-noise,noise),outpts(l)(1) + rnd*randomWithinRange(-noise,noise),outpts(l)(2) + rnd*randomWithinRange(-noise,noise))
End If
Next
Next
‘————————————————————————- generate the trianglate polyline based on the points above
Dim pline1,pline2,pline3,pline4
ReDim pline1(k*(l-1))
ReDim pline2(k*(l-1))
ReDim pline3(k)
ReDim pline4(k)
For k = 0 To ubound(arrnum)-1
For l = 0 To ptn-1
pline1(k*ptn+l) = rhino.AddPolyline(array(arrnum(k)(0)(l),arrnum(k+1)(0)(l),arrnum(k)(0)(l+1),arrnum(k)(0)(l)))
pline2(k*ptn+l) =  rhino.AddPolyline(array(arrnum(k)(0)(l+1),arrnum(k+1)(0)(l),arrnum(k+1)(0)(l+1),arrnum(k)(0)(l+1)))
Next
pline3(k)=  rhino.AddPolyline(array(arrnum(k)(0)(ptn),arrnum(k+1)(0)(ptn),arrnum(k)(0)(0),arrnum(k)(0)(ptn)))
pline4(k) =  rhino.AddPolyline(array(arrnum(k)(0)(0),arrnum(k+1)(0)(ptn),arrnum(k+1)(0)(0),arrnum(k)(0)(0)))
Next
Call rhino.AddLoftSrf(arrcircles)
Call rhino.DeleteObjects(arrcircles)
Dim deletepts
deletepts = rhino.ObjectsByType(1)
Call rhino.deleteobjects(deletepts)
allcurves = rhino.ObjectsByType(4)
rhino.Command “_group”

Next
End Sub
Function randomWithinRange(min, max)
Randomize
randomWithinRange = min + (max-min) * rnd()
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