Conway's Game of Life
Lua Carousel » Devlog
Perhaps my favorite program.
curr, new = {}, {} for x=1,Safe_width do table.insert(curr, {}) table.insert(new, {}) for y=1,Safe_height do table.insert(curr[x], 0) table.insert(new[x], 0) end end -- R pentomino cx = math.floor(Safe_width/2) cy = math.floor(Safe_height/2) curr[cx][cy] = 1 curr[cx][cy+1] = 1 curr[cx][cy+2] = 1 curr[cx-1][cy] = 1 curr[cx+1][cy+1] = 1 function car.draw() color(0,0,0) for x=1,Safe_width do for y=1,Safe_height do if curr[x][y] > 0 then pt(x,y) end end end end function car.update(dt) step() end function step() for x=2,Safe_width-1 do for y=2,Safe_height-1 do local n = nghs(x,y) if n < 2 or n > 3 then new[x][y] = 0 elseif n == 2 then new[x][y] = curr[x][y] elseif n == 3 then new[x][y] = 1 end end end curr, new = new, curr end function nghs(x,y) return curr[x-1][y-1] +curr[x-1][y] +curr[x-1][y+1] + curr[x][y-1] +curr[x][y+1] + curr[x+1][y-1] +curr[x+1][y] +curr[x+1][y+1] end
If you try pasting this program into Lua Carousel, remember to first run the abbreviations on one of the example screens. Or if you've deleted that screen, here are the abbreviations this program uses:
g = love.graphics pt = g.points color = g.setColor
Get Lua Carousel
Lua Carousel
Write programs on desktop and mobile
Status | In development |
Category | Tool |
Author | Kartik Agaram |
Tags | LÖVE |
More posts
- New version after 3 days3 days ago
- New version after 40 days6 days ago
- Turn your phone or tablet into a chess clock20 days ago
- Guest program: bouncing balls36 days ago
- New version after 3 months, and turtle graphics47 days ago
- Interactively zooming in to the Mandelbrot set on a touchscreen66 days ago
- A little timer app67 days ago
- New version after 4 monthsJun 28, 2024
- Visualizing the digits of πMay 04, 2024
- A little recursion problemApr 15, 2024
Leave a comment
Log in with itch.io to leave a comment.