View of Rule 30 Re: Auto Cellular automaton

"valery_vi" <[email protected]>
Newsgroups gmane.comp.windows.autoit.user
Message-ID <[email protected]>
New Photos of it (Auto Cellular automaton - Rule 30) was added into 
Photos/Views of this group, too.

Enjoy,
Valery

--- In [email protected], "valery_vi" <shehrer1@...> wrote:
>
> Hi,
> 
> As soon as AutoIt can draw fractals, I've written other example 
> ACA.au3:
> 
> ; ACA, © Valery Ivanov, 20 June, 2007
> ;  ACA is Auto Cellular automaton example
> ; About CA see here:
> ; http://en.wikipedia.org/wiki/Cellular_automata
> #include <GUIConstants.au3>
> Global $hDC, $GDI, $hWnd
> 
> 
> ; Default Rule 30
> ;  Rule 30 cellular automaton
> Global $RuleNum = 30
> Global $CA_Rule[8] = [0,0,0,1,1,1,1,0]
> ; Rule 30 cellular automaton
> ; You can set Rule 110
> ; $RuleNum = 110
> Set_CA_Rule($RuleNum)
> 
> $hWnd = GUICreate("Auto Cellular automaton - © Valery Ivanov, 20 
> June, 2007", 400, 200)
> GUISetState(@SW_SHOW)
> 
> $GDI = DllOpen("gdi32.dll")
> $hDC = DllCall ("user32.dll", "int", "GetDC", "hwnd", $hWnd)
> $hDC = $hDC[0]
> 
> $String = GetFirstLine(400)
> $s = StringSplit($String,'')
> $i = 0
> for $i = 1 To 200
>  for $j = 1 To $s[0]
>   if $s[$j] = '1' Then 
>    PutPoint($hDC,$j,$i,0xAA0000)
>   else
>    PutPoint($hDC,$j,$i,0xFFFFFF)
>   endif
>  next
>  $String = GetNextLine($String)
>  $s = StringSplit($String,'')
> Next
> 
> ; Loop until user exits
> do
> until GUIGetMsg() = $GUI_EVENT_CLOSE
> 
> ;===============
> func PutPoint($hDC, $x, $y, $color)
>  DllCall ($GDI, "long", "SetPixel", "long", $hDC, "long", 
$x, "long", 
> $y, "long", $color)
> endfunc
> 
> ;===============
> ;set Rule 
> ; There are 256 rules [0 - 255]
> ; The known CA rule are 30 and 110!
> func Set_CA_Rule($RuleNum)
>  for $i = 1 to 8
>   $CA_Rule[8-$i] = 0
>   if mod($RuleNum,2) then $CA_Rule[8-$i] = 1
>   $RuleNum = BitShift($RuleNum,1)
>  next  
> endfunc
> 
> ;===============
> ;view Rule 
> func View_CA_Rule()
>  $l = ''
>  for $i = 0 to 7
>   $l &= $CA_Rule[$i]
>   if $i <> 7 then $l &= ', '
>  next
>  Msgbox(0,'',$l)
> endfunc
> 
> ;===============
> ;view CA
> func View_CA()
>  $s = GetFirstLine(20)
>  $l = $s
>  for $i = 0 to 3
>   $s = GetNextLine($s)
>   $l &= @CrLf & $s
>  next
>  Msgbox(0,'',$l)
> endfunc
> 
> ;===============
> ;get first CA line
> func GetFirstLine($Dim)
> local $String = ''
> for $i = 1 to  $Dim
>  if $i = $Dim/2 then 
>   $String &= '1'
>  else
>   $String &= '0'
>  endif
> next
> return $String
> endfunc
> 
> ;===============
> ;get next CA line
> func GetNextLine($String)
> local $S, $N, $l, $c, $r
>  $S = StringSplit($String,'')
>  $String = ''
>  $N = $S[0]
>  for $i = 1 to $N
>   $l = $S[$N]
>   if $i <> 1 then $l = $S[$i-1]
>   $c = $S[$i]
>   $r = $S[1]
>   if $i <> $n then $r = $S[$i+1]
>   $String &= $CA_Rule[7-($r+2*$c+4*$l)]
>  next
>  return $String
> endfunc
> 
> This script shows how to draw the simplest nontrivial CA. 
> Current code build Rule 30 but you can update it to draw any Rule 
> examples with help of special variable $RuleNum and calling of 
> function Set_CA_Rule($RuleNum). 
> for example
> 
>   $RuleNum = 110
>   Set_CA_Rule($RuleNum)
> 
> BTW About CA read the following:
> 
> http://en.wikipedia.org/wiki/Cellular_automata
> 
> Enjoy,
> Valery
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.