An interactive implementation of Conway's Game of Life using HTML5 Canvas with the following features:
- Responsive grid that adapts to window size
- Color-coded cells based on neighbor count
- Toroidal array implementation (edges wrap around)
- Page visibility optimization (pauses when tab is inactive)
The game is built using vanilla JavaScript with classes handling different aspects:
GameState
: Manages the application stateGridManager
: Handles grid initialization and game rulesCanvasManager
: Controls canvas setup and resizingRenderer
: Responsible for drawing cells with dynamic coloringGameLoop
: Manages animation and page visibility
classDiagram
class GameState {
+canvas
+ctx
+width
+height
+grid
+isPageVisible
+animationFrameId
}
class CanvasManager {
+init()
+resize()
}
class GridManager {
+init()
+countNeighbors(x, y)
+update()
}
class Renderer {
+getColorForNeighbors(neighbors)
+draw()
}
class GameLoop {
+animate()
+handleVisibilityChange()
}
GameState <.. CanvasManager : uses
GameState <.. GridManager : uses
GameState <.. Renderer : uses
GameState <.. GameLoop : uses
CanvasManager <.. GameLoop : uses
GridManager <.. Renderer : uses
- Clone the repository
- Open index.html in a web browser
- Watch the Game of Life evolve!
Contributions are welcome! Here are some ways you can contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
The project uses a simple structure:
- index.html: Main entry point
- script.js: Game logic and classes
- styles.css: Basic styling
- .github/workflows/main.yaml: GitHub Pages deployment
This project is open source and available under the MIT License.