Hi, Starshyne Emir. Its been a while. Nicely Done!
I do not have the Matrix1 Utilities installed on my system. So, I had to make some modifications to your source to get it working. DBPro complained about the color parameter of the Box function. Removed the color parameter and started getting window not responding errors. I would assume IanM's Box function uses the same DirectX method as the native DBPro Box function, as it is the most optimized method, I'm aware of. If that's the case, locking the pixel buffer is not required and the app may crash on some systems. Well, guess what! LOL.
Then, I just went crazy. I structured your source to read a little nicer. I know, I'm anal. I removed some unnecessary code and reduced the array by utilizing index zero. Also, added my missing Wrap function. Lastly, I replace the Box function with Paste Image and wow, what a increase in your drawing routine.
Sorry, I don't know much about the cellular automaton stuff. Let us know how the fire spread algorithm is going. It sounds very useful.
`defines ruleset in the format b$/l$ where b$ is when the cell can be born and l$ is when the cell survives
b$ = "23"
l$ = "3"
`size of the grid and number of generations to create
w = 63
h = 47
g = 999
` Initialize
randomize timer()
box 0, 0, 10, 10
get image 1, 0, 0, 10, 10
`main loop
do
cls
`prepare grid
dim grid(g, w, h)
`set up some random points in generation 1
for x = 0 to w
for y = 0 to h
if rnd(1) then grid(0, x, y) = 1
next
next
`calculate the further generations
for gen = 0 to g-1
for x = 0 to w
for y = 0 to h
`check the neighborhood
n = 0
for nx = Wrap(x-1, 0, w) to Wrap(x+1 , 0, w)
for ny = Wrap(y-1, 0, h) to Wrap(y+1, 0, h)
if not (x = nx and y = ny)
if grid(gen, nx, ny) then inc n
endif
next
next
`parse the rulesets and check if it applies
v = 0
if grid(gen, x, y)
if b$
for r = 1 to len(b$)
c = val(mid$(b$, r))
if c = n then v = 1
next
endif
else
if l$
for r = 1 to len(l$)
c = val(mid$(l$, r))
if c = n then v = 1
next
endif
endif
grid(gen+1, x, y) = v
next
next
next
`draws result on screen in an infinite loop
gen = 0
repeat
cls
for x = 0 to w
for y = 0 to h
if grid(gen, x, y) then paste image 1, x*10, y*10
next
next
gen = Wrap(gen+1, 1, g)
until spacekey()
cls
undim grid()
loop
end
function Wrap(CurVal as integer, MinVal as integer, MaxVal as integer)
local Result as integer
local Range as integer
Range = MaxVal-MinVal+1
if CurVal<MinVal
inc CurVal, Range*((MinVal-CurVal)/Range+1)
endif
Result = MinVal+(CurVal-MinVal) mod Range
endfunction Result