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
- Lua Carousel: program on the device you have, with docs at your fingertips19 days ago
- Pong Wars, MMO editionFeb 16, 2025
- New version after 41 days, and stop-motion animationFeb 15, 2025
- Drawing with a pen on a pendulumJan 11, 2025
- New version after 16 daysJan 04, 2025
- New version after 9 daysDec 19, 2024
- New version after 3 daysNov 17, 2024
- New version after 40 daysNov 14, 2024
- Turn your phone or tablet into a chess clockNov 01, 2024
- Guest program: bouncing ballsOct 15, 2024
Leave a comment
Log in with itch.io to leave a comment.