This is my first program using Codea. After I finished it and registered on the forums (just now), I noticed another member already submitted Game of Life a month ago. Yet I want to submit this anyway as I coded this independent of the former submission and would like feedback on my code.

```
-- Conway's Game of Life
-- Coded on iPad with Codea
-- Author, Stephen Monroe
function setup()
parameter("pause", 0, 1)
parameter("delay", 0, 10)
gridX = 24
gridY = 24
tick = 0
count = 0
cell = {}
for i = 0, gridX + 1 do
cell[i] = {}
for j = 0, gridY + 1 do
cell[i][j] = 0
end
end
myFPS = FPS(4)
end
function draw()
background(0)
clearOutput()
print("FPS: " .. myFPS:display())
if pause < .5 then
pause = math.floor(pause)
else
pause = math.ceil(pause)
end
delay = math.floor(delay)
DrawGrid()
if pause == 0 then
TouchGrid()
else
Simulate(delay)
end
end
function DrawGrid()
fill(0, 0, 255, 255)
strokeWidth(1)
for i = 0, gridX do
for j = 0, gridY do
if cell[i + 1][j + 1] == 1 then
rect(i * (WIDTH / gridX), j * (HEIGHT / gridY), (WIDTH / gridX), (HEIGHT / gridY))
end
end
end
end
function TouchGrid()
if CurrentTouch.state ~= BEGAN then
return
end
if priorX == CurrentTouch.x and priorY == CurrentTouch.y then
return
end
x = math.floor(CurrentTouch.x / (WIDTH / gridX))
y = math.floor(CurrentTouch.y / (HEIGHT / gridY))
priorX = CurrentTouch.x
priorY = CurrentTouch.y
if cell[x + 1][y + 1] == 0 then
cell[x + 1][y + 1] = 1
else
cell[x + 1][y + 1] = 0
end
end
function Simulate(delay)
print("Tick: " .. tick)
count = count + 1
if count >= delay then
count = 0
else
return
end
newCell = {}
for i = 0, gridX + 1 do
newCell[i] = {}
for j = 0, gridY + 1 do
newCell[i][j] = cell[i][j]
end
end
for i = 1, gridX do
for j = 1, gridY do
proxy = cell[i][j - 1] + cell[i][j + 1] + cell[i - 1][j] + cell[i + 1][j] + cell[i - 1][j - 1] + cell[i + 1][j + 1] + cell[i - 1][j + 1] + cell[i + 1][j - 1]
if cell[i][j] == 1 then
if proxy < 2 or proxy > 3 then
newCell[i][j] = 0
end
else
if proxy == 3 then
newCell[i][j] = 1
end
end
end
end
for i = 0, gridX + 1 do
for j = 0, gridY + 1 do
cell[i][j] = newCell[i][j]
end
end
tick = tick + 1
end
```