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
- Visualizing the digits of π14 days ago
- A little recursion problem33 days ago
- Drawing histograms46 days ago
- The simplest possible dither49 days ago
- All the 1-D cellular automata57 days ago
- A Sokoban client based on Lua Carousel68 days ago
- Lots of charts85 days ago
- A little programming game88 days ago
- New version after 51 days92 days ago
- Pong WarsJan 30, 2024
Leave a comment
Log in with itch.io to leave a comment.