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
- Pong Wars, MMO edition3 days ago
- New version after 41 days, and stop-motion animation5 days ago
- Drawing with a pen on a pendulum40 days ago
- New version after 16 days47 days ago
- New version after 9 days63 days ago
- New version after 3 days95 days ago
- New version after 40 days97 days ago
- Turn your phone or tablet into a chess clockNov 01, 2024
- Guest program: bouncing ballsOct 15, 2024
- New version after 3 months, and turtle graphicsOct 05, 2024
Leave a comment
Log in with itch.io to leave a comment.