(n)certainties

GSAPP- Fall 2010

(n)certainties header image 3

Code Endless Bio-Anarchia

AggregationScriptNoDuplicatesVoidAttractors


Option Explicit
'Script written by Maysam Ghaffari and Ezio Blasetti

'
'0 : 2,-1, 0 3,-1, 0 3, 0, 0
'1 : 0,-3, 0 0,-2, 0 -1,-2, 0
'2 :-2,-1, 0 -3,-1, 0 -3,-2, 0
'3 :-2, 3, 0 -1, 3, 0 -1, 4, 0
'4 : 2, 3, 0 1, 3, 0 1, 2, 0
'5 : 2,-1, 2 1,-1, 2 1,-2, 2
'6 :-2,-1, 2 -1,-1, 2 -1, 0, 2
'7 : 0, 1, 2 0, 2, 2 -1, 2, 2
'8 : 2,-1,-2 1,-1,-2 1,-2,-2
'9 :-2,-1,-2 -1,-1,-2 -1, 0,-2
'10: 0, 1,-2 0, 2,-2 -1, 2,-2

Call Main()
Sub Main()

Dim strCrv : strCrv = Rhino.GetObject("select the starting polyline",4)
Dim gen : gen = Rhino.GetInteger("how many generations", 5)
Dim arrStrAttractors4Voids : arrStrAttractors4Voids = Rhino.GetObjects("Select the attractors for the voids",1)
Dim arrStrAttractors4Rand : arrStrAttractors4Rand = Rhino.GetObjects("Select the attractors for the randomness",1)

Dim i
ReDim arrAttractors4VoidsXYZ(Ubound(arrStrAttractors4Voids))
For i=0 To Ubound(arrStrAttractors4Voids)
arrAttractors4VoidsXYZ(i) = Rhino.PointCoordinates(arrStrAttractors4Voids(i))
Next

ReDim arrAttractors4RandXYZ(Ubound(arrStrAttractors4Rand))
For i=0 To Ubound(arrStrAttractors4Rand)
arrAttractors4RandXYZ(i) = Rhino.PointCoordinates(arrStrAttractors4Rand(i))
Next

Call aggregateHendecahedrons(strCrv, gen, arrAttractors4VoidsXYZ, arrAttractors4RandXYZ)

End Sub

Function aggregateHendecahedrons(strCrv, gen, arrAttractors4VoidsXYZ, arrAttractors4RandXYZ)

If gen > 0 Then

Dim arrDiegos : arrDiegos = Rhino.ObjectsByName("Diego")

Dim strNewCrv0, strNewCrv1

Dim arrPoints(10)

arrpoints( 0) = array(array( 2,-1, 0),array( 3,-1, 0),array( 3, 0, 0))
arrpoints( 1) = array(array( 0,-3, 0),array( 0,-2, 0),array(-1,-2, 0))
arrpoints( 2) = array(array(-2,-1, 0),array(-3,-1, 0),array(-3,-2, 0))
arrpoints( 3) = array(array(-2, 3, 0),array(-1, 3, 0),array(-1, 4, 0))
arrpoints( 4) = array(array( 2, 3, 0),array( 1, 3, 0),array( 1, 2, 0))

arrpoints( 5) = array(array( 2,-1,-2),array( 1,-1,-2),array( 1,-2,-2))
arrpoints( 6) = array(array(-2,-1,-2),array(-1,-1,-2),array(-1, 0,-2))
arrpoints( 7) = array(array( 0, 1,-2),array( 0, 2,-2),array(-1, 2,-2))

arrpoints( 8) = array(array( 2,-1, 2),array( 1,-1, 2),array( 1,-2, 2))
arrpoints( 9) = array(array(-2,-1, 2),array(-1,-1, 2),array(-1, 0, 2))
arrpoints(10) = array(array( 0, 1, 2),array( 0, 2, 2),array(-1, 2, 2))

Dim index0, index1, arrReference, arrTarget
arrReference = array(array(0,1,0),array(0,0,0),array(1,0,0))
arrTarget = Rhino.CurvePoints(strCrv)

index0 = Int(Rnd*8)
strNewCrv0 = Rhino.AddPolyline(arrPoints(index0))
Call Rhino.ObjectName(strNewCrv0, "Diego")
Call Rhino.OrientObject (strNewCrv0, arrReference, arrTarget)

Dim arrPointOnNewPolyline0 : arrPointOnNewPolyline0 = Rhino.CurveMidPoint(strNewCrv0)

Dim i, dblDistance, indexClosestAttractor4Rand

indexClosestAttractor4Rand = Rhino.PointArrayClosestPoint(arrAttractors4RandXYZ, arrPointOnNewPolyline0)
dblDistance = Rhino.Distance(arrPointOnNewPolyline0, arrAttractors4RandXYZ(indexClosestAttractor4Rand))

If rnd>0.9Then
Call Rhino.OrientObject (strNewCrv0, Rhino.CurvePoints(strCrv), Randomize3Points(Rhino.CurvePoints(strCrv), dblDistance))
End If

index1 = Int(Rnd*8)
If index1 = index0 Then index1 = index1 + 1
If index1>Ubound(arrPoints) Then index1 = 0
strNewCrv1 = Rhino.AddPolyline(arrPoints(index1))
Call Rhino.ObjectName(strNewCrv1, "Diego")
Call Rhino.OrientObject (strNewCrv1, arrReference, arrTarget)

Dim arrPointOnNewPolyline1 : arrPointOnNewPolyline1 = Rhino.CurveMidPoint(strNewCrv1)
indexClosestAttractor4Rand = Rhino.PointArrayClosestPoint(arrAttractors4RandXYZ, arrPointOnNewPolyline1)
dblDistance = Rhino.Distance(arrPointOnNewPolyline1, arrAttractors4RandXYZ(indexClosestAttractor4Rand))
If rnd>0.9Then
Call Rhino.OrientObject (strNewCrv1, Rhino.CurvePoints(strCrv), Randomize3Points(Rhino.CurvePoints(strCrv), dblDistance))
End If

Dim blnKeepOrDelete0 : blnKeepOrDelete0 = True
Dim blnKeepOrDelete1 : blnKeepOrDelete1 = True
For i=0 To Ubound(arrDiegos)
Dim arrPointOnDiego : arrPointOnDiego = Rhino.CurveMidPoint(arrDiegos(i))
Dim dblDistance0 : dblDistance0 = Rhino.Distance(arrPointOnNewPolyline0, arrPointOnDiego)
Dim dblDistance1 : dblDistance1 = Rhino.Distance(arrPointOnNewPolyline1, arrPointOnDiego)
If dblDistance0<1 Then blnKeepOrDelete0 = False End If If dblDistance1<1 Then blnKeepOrDelete1 = False End If Next For i=0 To Ubound(arrAttractors4VoidsXYZ) dblDistance0 = Rhino.Distance(arrPointOnNewPolyline0, arrAttractors4VoidsXYZ(i)) dblDistance1 = Rhino.Distance(arrPointOnNewPolyline1, arrAttractors4VoidsXYZ(i)) If dblDistance0<5 Then blnKeepOrDelete0 = False End If If dblDistance1<5 Then blnKeepOrDelete1 = False End If Next If blnKeepOrDelete0 Then Call aggregateHendecahedrons(strNewCrv0, gen-1, arrAttractors4VoidsXYZ, arrAttractors4RandXYZ) Else Call Rhino.DeleteObject(strNewCrv0) End If If blnKeepOrDelete1 Then Call aggregateHendecahedrons(strNewCrv1, gen-1, arrAttractors4VoidsXYZ, arrAttractors4RandXYZ) Else Call Rhino.DeleteObject(strNewCrv1) End If End If End Function Function Randomize3Points(arr3Pts, dblDistance) Randomize3Points = Null Dim arrRandomizedPts(2) Dim i For i = 0 To Ubound(arr3Pts) Dim arrPoint : arrPoint = arr3Pts(i) arrPoint(0) = arrPoint(0) + rnd*.5/(dblDistance) arrPoint(1) = arrPoint(1) + rnd*.5/(dblDistance) arrPoint(2) = arrPoint(2) + rnd*.5/(dblDistance) arrRandomizedPts(i) = arrPoint Next Randomize3Points = arrRandomizedPts End Function

Line Attractors


Option Explicit
'Script written by Maysam Ghaffari, Diego Morell Perea and Ezio Blasetti

Call Main()
Sub Main()

Dim arrStrAttractors : arrStrAttractors = Rhino.GetObjects("select the attractors for the voids", 5)
Dim arrlines : arrlines = Rhino.GetObjects("select the lines", 4)
Dim dblThres : dblThres = Rhino.GetReal("type the threshold", 5)
ReDim arrLines2Delete(-1)

Dim strLine
For Each strLine In arrLines

Dim arrMidPt : arrMidPt = Rhino.CurveMidPoint(strLine)
Dim strAttractor, dblDistance, arrPt

For Each strAttractor In arrStrAttractors
Dim dblThreshold
Dim strName : strName = Rhino.ObjectName(strAttractor)
If IsNull(strName) Then
dblThreshold = dblThres
Else
dblThreshold = CDbl(strName)
End If
If rhino.Ispoint(strAttractor) Then
arrPt = Rhino.PointCoordinates(strAttractor)

dblDistance = rhino.distance(arrMidPt, arrPt)

If dblDistance < dblThreshold Then ReDim Preserve arrLines2Delete(Ubound(arrLines2Delete)+1) arrLines2Delete(Ubound(arrLines2Delete)) = strLine Exit For End If Else Dim dblParam : dblParam = Rhino.CurveClosestPoint(strAttractor, arrMidPt) arrPt = Rhino.EvaluateCurve(strAttractor,dblParam) dblDistance = rhino.distance(arrMidPt, arrPt) If dblDistance < dblThreshold Then ReDim Preserve arrLines2Delete(Ubound(arrLines2Delete)+1) arrLines2Delete(Ubound(arrLines2Delete)) = strLine Exit For End If End If Next Next Call Rhino.DeleteObjects(arrLines2Delete) End Sub

Emitter


Option Explicit
'Script written by Maysam Ghaffari, Diego Morell Perea and Ezio Blasetti

Call Main()
Sub Main()

Dim strEmitter : strEmitter = Rhino.GetObject("select the line - emmitter", 4)
Dim intHowMany : intHowMany = Rhino.GetInteger("type how many particles", 20)
Dim intSteps : intSteps = Rhino.GetInteger("type how many steps", 200)

Dim arrVector : arrVector = Rhino.VectorCreate(array(0,0,0), array((rnd-.5)*6,(rnd-.5)*6,(rnd-.5)*6))

Dim arrParticlePos : arrParticlePos = Rhino.CurveEndPoint(strEmitter)
Dim dblParameter : dblParameter = Rhino.CurveClosestPoint(strEmitter, arrParticlePos)
Dim arrParticleVec : arrParticleVec = Rhino.CurveTangent(strEmitter, dblParameter)

Dim i,j
ReDim arrParticles(intHowMany)
ReDim arrVelocities(intHowMany)
For i=0 To intSteps

For j = 0 To intHowMany

If i=0 Then
arrParticles(j) = arrParticlePos
arrVelocities(j) = arrParticleVec
End If

Dim oldPoint : oldPoint = arrParticles(j)

arrParticles(j) = Rhino.PointAdd(arrParticles(j), arrVelocities(j))

Call rhino.addLine(oldPoint, arrParticles(j))

arrVelocities(j) = Rhino.PointAdd(arrVelocities(j),array((rnd-.5)*10,(rnd-.5)*10,rnd*10))

arrVelocities(j) = Rhino.PointAdd(arrVelocities(j),arrVector)
arrVelocities(j) = Rhino.VectorUnitize(arrVelocities(j))

Next

arrVector = Rhino.VectorRotate(arrVector,rnd, array(0,0,1))
arrVector = Rhino.VectorScale(arrVector,(rnd+.5))
Next
End Sub

grasshopper