Imagin a family of worms sorted on a path. Every worm move randomly from previous one. This worm recive a vote based on approach to the target specified.
Coding this script I follow a very simple rule: worms that gain better vote may proliferate replacing themselves in next generations.
Every generation manifest mutation like in Darwin's theory of evolution, and environment rules define if this mutations are good or not for species.
Like human body and ant colony, later generations reduce scattering for a more accurate configuration. Studying countless generations, the family should reach the target specified.
Specifying different rules for worms should be possible to study emergent systems whose behavior is not predictable from the study of individual elements, like organic complexity L-systems.
Option Explicit
' Script written by Alessandro Zomparelli
' alessandro.zomparelli@gmail.com
' http://alessandrozompa.altervista.org/
' Script version venerdì 30 ottobre 2009 16.59.03
Call Main()
Sub Main()
Dim strTarget, arrFamily, arrTarget, n
n=Rhino.GetInteger("set number elements",20,2,100)
ReDim arrFamily(n), arrTarget(2)
arrFamily(0)=Rhino.GetObject("pick starting point")
'check for starting point
If Rhino.IsPoint(arrFamily(0))=False Then
Exit Sub
End If
strTarget=Rhino.GetObject("pick target point")
'check for target point
If Rhino.IsPoint(strTarget)=False Then
Exit Sub
End If
arrTarget=Rhino.PointCoordinates(strTarget)
Dim dblDist
dblDist=Rhino.Distance(Rhino.PointCoordinates(arrFamily(0)),arrTarget)
'defining number of generations and amount of mutation between following generations
Dim dblGen, dblMut
dblGen=Rhino.GetInteger("set number of generations",100,2,1000)
dblMut=Rhino.GetReal("set mutation value",2,0.01,100)
'defining an array to collect data about different family
Dim arrData
ReDim arrData(n)
'defining a value for better step-element of different family
Dim dblVote
'defining counters, array for data recording and an array for scattering direction
Dim i, j, arrVect, arrVect0, arrRec
ReDim arrVect(2), arrVect0(2), arrRec(1)
'defining random data for first generation
For j=1 To n
arrVect=array(rnd-rnd,rnd-rnd,rnd-rnd)
dblVote=0
arrData(j)=array(dblVote,arrVect)
Next
Dim strLine
'starting evolution system
For i=0 To dblGen-1
Call Rhino.EnableRedraw(False)
'starting family growning
For j=1 To n
arrRec=arrData(j)
arrVect0=arrRec(1)
arrVect=array(arrVect0(0)+dblMut*(dblGen-i)/dblGen*(rnd-rnd),arrVect0(1)+dblMut*(dblGen-i)/dblGen*(rnd-rnd),arrVect0(2)+dblMut*(dblGen-i)/dblGen*(rnd-rnd))
arrVect0=Rhino.VectorUnitize(arrVect)
arrVect=Rhino.VectorScale(arrVect0,dblDist/n)
'generation of new element of the family
arrFamily(j)=Rhino.CopyObject(arrFamily(j-1),arrVect)
strLine=Rhino.AddLine(Rhino.PointCoordinates(arrFamily(j-1)),Rhino.PointCoordinates(arrFamily(j)))
Call Rhino.ObjectColor(strLine, RGB(255-255/dblGen*i,0,255/dblGen*i))
If Rhino.Distance(Rhino.PointCoordinates(arrFamily(j)),arrTarget)
arrData(j)=array(dblVote,arrVect)
End If
End If
Next
For j=1 To n
Call Rhino.DeleteObject(arrFamily(j))
Next
Call Rhino.EnableRedraw(True)
Next
End Sub