I would welcome any suggestions to improve my coding.
Code: Select all
'a cellular automaton (from Scientific American 1998)
' create rectangle on screen of pixels with random colors
' from 1 to numberOfColors using "pset"
'to run it;
' repeat same operation many times as follows
' each iteration goes across all pixels, using a nested for/next loop
'this is the predator
'the predator looks at all 8 surrounding pixels, which are prey,
'and gets pixel color of the prey using "point"
'the prey pixel color will change to the predator color number if
'1. the predator color number is bigger than the prey color number by one
'2. the predator is 1 and the prey is the max number ie numberOfColors
'it is a "circle"
'it starts with random colors then deleops lines etc
'need to run hundreds, thousands of iterations
screen 13
screenres 1200, 600',12
dim shared as integer maxX, maxY, predX, predY,preyX, preyY, n,preyN,predN,iters,ppDiff,anyInt, numberOfColors
dim shared as integer oneMinusNumberOfColors
declare sub LoadScreen
declare sub LoadVariables
declare sub DoOneIter
'run it
LoadVariables
LoadScreen
'iters = iterations
for iters = 1 to 50000
locate 1,110
print iters
DoOneIter
next
'after all the iters, inform user it has finished running
locate 200,0: print "done"
sleep
sub DoOneIter
for predX = 1 to maxX
for predY = 1 to maxY 'go through all pixels
predN= point (predX,predY) 'get predator color number predN
for preyX = predX - 1 to predX + 1
for preyY = predY- 1 to predY+1
preyN = point(preyX,preyY)'use point to get prey color number preyN
ppDiff= predN-preyN ' difference between predator and prey color number
select case ppDiff
case 1,oneMinusNumberOfColors'oneMinusNumberOfColors to make it that number one "eats" the biggest number
pset (preyX,preyY),predN
end select
select case inkey$
case "q"' stop it
end
case "s"
sleep' temporary stop to look at it
end select
'if inkey$= "q"then
'end
'end if
next
next
next
next
end sub
sub LoadVariables
randomize 77796 '46159
maxX= 500' sixe of box of pixels used
maxY =400
numberOfColors = 12
oneMinusNumberOfColors = 1- numberOfColors' done here for speed
end sub
sub LoadScreen'put random color pixels on screen
for preyX = 1 to maxX
for preyY = 1 to maxY
n = 1+(int (numberOfColors * rnd))
'print n
pset (preyX,preyY),n
next
next
end sub
'
sleep
' Explicit end of program
End