computational craft

Cellular Automata

posterca

cellular automata [sel-yuh-ler aw-tom-uh-tuh]

definition by mathworld:

A cellular automaton is a collection of “colored” cells on a grid of specified shape that evolves through a number of discrete time steps according to a set of rules based on the states of neighboring cells. The rules are then applied iteratively for as many time steps as desired. von Neumann was one of the first people to consider such a model, and incorporated a cellular model into his “universal constructor.” Cellular automata were studied in the early 1950s as a possible model for biological systems (Wolfram 2002, p. 48). Comprehensive studies of cellular automata have been performed by S. Wolfram starting in the 1980s, and Wolfram’s fundamental research in the field culminated in the publication of his book A New Kind of Science (Wolfram 2002) in which Wolfram presents a gigantic collection of results concerning automata, among which are a number of groundbreaking new discoveries.

rule 30:

rule30
One of the elementary cellular automaton rules introduced by Stephen Wolfram in 1983 (Wolfram 1983, 2002). It specifies the next color in a cell, depending on its color and its immediate neighbors. Its rule outcomes are encoded in the binary representation . This rule is illustrated above together with the evolution of a single black cell it produces after 15 steps (Wolfram 2002, p. 55).

1-d CA in rhinoscript:

Option Explicit
'1 dimensional Cellular automata

Call Main()
Sub Main()
      'define the starting condition
     Dim strGen
      strGen = "0,1,0,0,1,0,0,1,0,1,1,0,1,1,1,1,0,0,1,0,0,0,0,0,0,1,1,1,0,0,1,1,0,1,1,0,1,1,1,1,0,1,1,0,1,1,1,0,0,1,1,0,1,1,1,1,0,0,0,0,1,1,0,1,0,0,0,0,1,0,1,0"
      Dim intHowMany : intHowMany = Rhino.GetInteger ("how many generations should I plot?", 20)
      Dim j
      For j=0 To intHowMany

          dim arrTokens : arrTokens = rhino.strtok(strGen, ",")
          Dim i
          For i=0 To Ubound(arrTokens)
              Dim strCurrentChar : strCurrentChar = arrTokens(i)
              Dim arrPoint       : arrPoint       = array(i,j,0)
              'Dim strTextDotID   : strTextDotID   = Rhino.AddTextDot (strCurrentChar, arrPoint)
             Dim strObjectID    : strObjectID    = Rhino.AddSrfPt (array(array((i-.5),(j-.5),0),array((i-.5),(j+.5),0),array((i+.5),(j+.5),0),array((i+.5),(j-.5),0)))          
              if strCurrentChar=0 Then
                 'Call Rhino.ObjectColor ( strTextDotID, RGB(250,250,250) )
                Call Rhino.ObjectColor ( strObjectID,  RGB(250,250,250) )
              Else
                 'Call Rhino.ObjectColor ( strTextDotID, RGB(0,0,0) )
                Call Rhino.ObjectColor ( strObjectID,  RGB(0,0,0) )
              End if
           Next
           strGen = NextGeneration(strGen)
      Next

End Sub



Function NextGeneration (strGen)
     'define 3 variables for each character and define a new string for next generation
    Dim strCharacter, strLeftCharacter, strRightCharacter, strNextGen, arrTokens


     strNextGen = ""
     'tokenize the strGen
    arrTokens = rhino.strtok(strGen, ",")
     Dim i
     For i=0 To Ubound(arrTokens)
         strCharacter      = arrTokens(i)
         
         If i=0 Then
             strLeftCharacter  = arrTokens(Ubound(arrTokens))
         Else
             strLeftCharacter  = arrTokens(i-1)
         End If

         If i=Ubound(arrTokens) Then
             strRightCharacter  = arrTokens(0)
         Else
             strRightCharacter  = arrTokens(i+1)
         End If

         'loop through each of the arrTokens
        'go through the wolfram rules
        'if rule applies change the character
        if strLeftCharacter = 1 AND strCharacter = 1 AND strRightCharacter = 1  Then
               strNextGen = strNextGen & ",0"
         End If

         if strLeftCharacter = 1 AND strCharacter = 1 AND strRightCharacter = 0  Then
               strNextGen = strNextGen & ",0"
         End If

         if strLeftCharacter = 1 AND strCharacter = 0 AND strRightCharacter = 1  Then
               strNextGen = strNextGen & ",0"
         End If
         
         if strLeftCharacter = 1 AND strCharacter = 0 AND strRightCharacter = 0  Then
               strNextGen = strNextGen & ",1"
         End If
         
         if strLeftCharacter = 0 AND strCharacter = 1 AND strRightCharacter = 1  Then
               strNextGen = strNextGen & ",1"
         End If
         
         if strLeftCharacter = 0 AND strCharacter = 1 AND strRightCharacter = 0  Then
               strNextGen = strNextGen & ",1"
         End If
         
         if strLeftCharacter = 0 AND strCharacter = 0 AND strRightCharacter = 1  Then
               strNextGen = strNextGen & ",1"
         End If
         
         if strLeftCharacter = 0 AND strCharacter = 0 AND strRightCharacter = 0  Then
               strNextGen = strNextGen & ",0"
         End If

     
     Next

     'return the new created sting
    NextGeneration = strNextGen
End Function

7stateca