Preview "Automaton"

Post Reply
Henko
Posts: 814
Joined: Tue Apr 09, 2013 12:23 pm
My devices: iPhone,iPad
Windows
Location: Groningen, Netherlands
Flag: Netherlands

Preview "Automaton"

Post by Henko »

'  "Automaton"
'  The "automaton" is a very simple digital machine, 
'  extensively described in the  december 1986 edition of the Byte 
'  magazine. It consists of a one-dimensional array of elements
'  that can each have 1 out of 4 statusses.
'  By assigning a color to each of the statusses, the array can
'  be put on the screen as a multicolored line.
'  For the next step, the status of each element is recalculated
'  as the sum of his former status and those of its neighbours (points).
'  This sum can be anything between 0 and 9. that sum is reduced
'  to a value between 0 and 3 by a "rule". an example of such rule:
'       sum:   0  1  2  3  4  5  6  7  8  9
'       rule:  0  2  3  0  1  1  0  2  2  1
'  the new line is drawn, and the proces is repeated a number
'  of times to produce a pattern.
'  Dependent on the starting values of the points and the rule
'  that is applied, interesting patterns may emerge.
'  In general, all patterns converge to a stable pattern,
'  some quickly, others only after a considerable number of steps.
'
'  This preview program does nothing more than generating a series
'  of such patterns, just for viewing.
'  The next version will have some tools to play with rules.
'  Each pattern takes about 5 seconds to display.
'
dim p1(202),p2(202),r(10)
randomize
graphics
graphics clear .8,.8,.8
loop1:
for i=0 to 9 !  r(i)=rnd(4) ! next i
for i=1 to 200 ! p1(i)=rnd(4) ! next i
graphics lock
y=80 ! disp(p1,y)
for k=1 to 100
  for i=1 to 200
    p2(i)=p1(i-1)+p1(i)+p1(i+1) ! p2(i)=r(p2(i))
    next i
  y=y+3 ! disp(p2,y)
  for i=1 to 200
    p1(i)=p2(i-1)+p2(i)+p2(i+1) ! p1(i)=r(p1(i))
    next i
  y=y+3 ! disp(p1,y)
  next k
graphics unlock
goto loop1
end

def disp(p(),y)
xp=80
for i=1 to 200
  x=p(i)
  if x=0 then
    fill color 0,0,0
    else 
    if x=1 then 
      fill color 1,0,0
      else
      if x=2 then
        fill color 0,1,0
        else 
        fill color 0,0,1
        end if
      end if
    end if
  xp=xp+3
  fill rect xp,y to xp+3,y+3
  next i
end def

Post Reply