A fast, clean implementation of Conway’s Game of Life built in Roblox Luau.
It renders the grid using EditableImage:WritePixelsBuffer with a single RGBA buffer, supports mouse painting, and runs at a configurable tick rate.
- ⚡ High-performance rendering using
EditableImage+buffer(RGBA pixels) - 🧠 Precomputed neighbor table (8 neighbors per cell) for fast stepping
- 🎨 Click-and-drag painting (LMB) to toggle cells
- ⏯️ Play/Pause, ⏭️ Step, 🧹 Clear, 🎲 Randomize
- 🧩 Modular structure:
Config,LifeGrid,ImageRenderer,InputController - 🔧
--!strictand--!optimize 2used throughout
- LMB: Paint cells (click sets a paint mode, drag continues painting)
- Space: Play / Pause
- Enter: Step (only when paused)
- C: Clear
- R: Randomize
-
LifeGrid- Stores
alive+next_aliveboolean arrays - Builds a flat neighbor index array (
neighbors) once at startup Step()counts live neighbors and applies Conway’s rules- Returns a list of changed cell indices for minimal updates
- Stores
-
ImageRenderer- Creates UI (
ScreenGui, buttons, status label) - Creates an
EditableImagesized to the grid (W×H) - Maintains a single RGBA pixel
buffer(GRID_WIDTH * GRID_HEIGHT * 4) - Updates pixels and flushes via
WritePixelsBuffer
- Creates UI (
-
InputController- Converts screen mouse position → grid index based on the ImageLabel bounds
Suggested layout inside your Roblox place (or Rojo project):
GameOfLife/
Client/
Main.client.lua
Modules/
Config.lua
LifeGrid.lua
ImageRenderer.lua
InputController.lua
If you’re using Rojo, keep the modules together and require them exactly as your setup expects (your code uses
require'@self/...').
Edit Config.lua:
GRID_WIDTH,GRID_HEIGHT— grid sizeWRAP_EDGES— wrap neighborsoroidal edges on/offTICK_RATE— simulation steps per second when runningRANDOM_DENSITY— random fill chanceDISPLAY_SCALE— how large the grid is displayed in UI- Colors + RGBA values:
ALIVE_RGBADEAD_RGBA
- Rendering is done by writing RGBA bytes into a
bufferand flushing it to theEditableImage. - The sim step loops the full grid each tick; most UI work is minimized by only rewriting changed cells (then flushing once).