I'm not 100% sure this is working correctly but it was a good first try.
-- conway's game of life -- by ian seyler maxinit=1400 cls() for t=1,maxinit do x=rnd(127) y=rnd(127) pset(x,y,15) end while(1) do for y=0,127 do for x=0,127 do neigh=0 for tx=-1,1 do for ty=-1,1 do if(pget(x+tx,y+ty)==15) then neigh+=1 end end end if(pget(x,y)==15) then neigh-=1 if(neigh<2 or neigh>3) then pset(x,y,0) end elseif(pget(x,y)==0) then if(neigh==3) then pset(x,y,15) end end end end end |



Nice! It isn't 100% accurate since you're reading & writing to the same buffer as you loop through the pixels. This means that the update to one row affects the next one down.
To fix this you would need to buffer that row, or write to a separate buffer. I wonder if you could use the sprite memory for this?
Thanks for sharing your code :)



Ah, that makes sense. Ideally I would like to read the pixels from the screen and write new pixels to the back buffer. Then I could just call flip() and run through the screen pixels again.
How does the back buffer work? Should we be able to use it?



Well, what you could do is write all your cells to a table, then each time the table is finished, you iterate through the table and draw the cells.
But that would make the program quite a bit larger.
[Please log in to post a comment]