A Rust implementation of Conway's Game of Life with a graphical user interface built using egui/eframe.
- Interactive GUI: Modern, responsive interface with real-time controls
- Mouse Interaction: Click and drag to draw living cells directly on the grid
- Save/Load System: ✅ IMPLEMENTED - Save and load game states to/from files
- Support for .gol, .json, and .rle file formats
- RLE (Run Length Encoded) format for standard Game of Life pattern sharing
- Preserves grid state, generation count, and all settings
- File dialog integration for easy file management
- Comprehensive error handling and status feedback
- Rich Presets: Extensive collection of classic patterns including:
- Oscillators: Blinker, Toad, Beacon, Pulsar, Pentadecathlon
- Spaceships: Glider, LWSS, MWSS, HWSS
- Guns: Gosper Glider Gun, Simkin Glider Gun
- Miscellaneous: R-Pentomino, Diehard, Acorn, Block
- Population Statistics: ✅ IMPLEMENTED - Real-time population tracking and analysis
- Live cell count display in real-time
- Population history chart with interactive plotting
- Statistical analysis including max/min population tracking
- Dedicated statistics panel with zoom and drag capabilities
- Clear history functionality for fresh analysis
- Visual Enhancements: ✅ IMPLEMENTED - Enhanced user interface features
- Theme switching with smooth animations (dark/light mode)
- Zoom functionality with mouse wheel support
- Grid line display toggle for better visibility
- Responsive layout with optimized panel arrangement
- Configurable Parameters: Adjustable grid size, update speed, and cell density
- Generation Tracking: Real-time display of current generation count
- Game Controls: Play/pause, step-by-step execution, clear, and randomize
The game features a clean interface with:
- Left sidebar for controls and presets
- Central grid area for the game visualization
- Right sidebar for population statistics and charts (toggleable)
- Real-time generation counter and live cell count
- Interactive population growth visualization
- Organized preset categories with descriptions
- Rust 1.70 or later
- Cargo (comes with Rust)
- Clone the repository:
git clone https://github.com/yourusername/game_of_life.git
cd game_of_life- Build and run:
cargo run --release- Start/Pause: Begin or pause the automatic evolution
- Step: Advance the simulation by one generation
- Clear: Remove all living cells from the grid
- Random: Populate the grid with random living cells
- Save: Save current game state to a file (.gol or .json format)
- Load: Load a previously saved game state from file
- Click: Toggle individual cells between alive and dead
- Click and Drag: Draw continuous patterns by dragging across the grid
- Ctrl + Mouse Wheel: Zoom in/out on the grid
- Space: Start/Pause the simulation
- S: Step forward one generation
- C: Clear all cells from the grid
- R: Randomize the grid with current density setting
- T: Toggle between light and dark themes
- Ctrl + S: Save current game state to file
- Ctrl + O: Load game state from file
- Update Speed: Control simulation speed (1-30 FPS)
- Grid Size: Adjust grid dimensions (10-200 width, 10-150 height)
- Random Density: Set the probability of cells being alive when randomizing
Preserve and share your game states:
- Save: Click the Save button to export your current game state
- Choose between .gol (Game of Life), .json, or .rle file formats
- .rle format is the standard format for sharing Game of Life patterns
- Saves grid state, generation count, and all current settings
- Default filename:
game_state.gol
- Load: Click the Load button to import a previously saved game
- Supports .gol, .json, and .rle file formats
- RLE files can be downloaded from online pattern libraries
- Automatically restores all game settings and grid configuration
- Status messages confirm successful operations or report errors
Browse organized categories of classic patterns:
- Select any preset to load it centered on the grid
- Each preset includes a description of its behavior
- Patterns are automatically positioned in the center of the current grid
Analyze the dynamics of cellular automata:
- Real-time Monitoring: Live cell count updates automatically during simulation
- Population Charts: Interactive graphs showing population changes over time
- Statistical Analysis: Track maximum, minimum, and current population levels
- History Management: Clear population history for fresh analysis
- Visual Interface: Dedicated statistics panel with zoom and drag capabilities
- Toggle Display: Show/hide statistics panel as needed for optimal screen space
src/
├── main.rs # Application entry point and core structure
├── game.rs # Game logic and Conway's Game of Life rules
├── ui.rs # User interface rendering and interaction
├── patterns.rs # Preset pattern definitions
└── save_load.rs # Save/load functionality with JSON serialization
- Framework: Built with egui/eframe for cross-platform GUI
- Architecture: Modular design with clear separation of concerns
- Performance: Optimized for smooth real-time simulation
- Memory: Efficient grid representation using 1D vector for better cache performance
- Serialization: JSON-based save/load system using serde
- File Management: Native file dialogs with rfd crate
- Dependencies: serde, serde_json, rfd, chrono, egui_plot for enhanced functionality and data visualization
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes following conventional commits
- Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow Rust standard formatting with
cargo fmt - Ensure code passes
cargo clippylints - Add tests for new functionality
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- John Conway for creating the Game of Life
- The egui community for the excellent GUI framework
- Classic pattern contributors and the cellular automata community
The Game of Life follows simple rules:
- Survival: A living cell with 2 or 3 neighbors survives
- Birth: A dead cell with exactly 3 neighbors becomes alive
- Death: All other living cells die (underpopulation or overpopulation)
These simple rules create surprisingly complex and beautiful patterns!
- ✅ COMPLETED Save current grid state to file (JSON format) / 将当前网格状态保存为文件(JSON 格式)
- ✅ COMPLETED Load previously saved game states / 从文件加载之前保存的游戏状态
- ✅ COMPLETED Support RLE format import/export (Game of Life standard) / 支持 RLE 格式导入/导出(生命游戏标准格式)
- Implement generation history with undo/redo capabilities / 实现代数历史记录,允许回退到之前的状态
- Add play/pause/reverse controls / 添加播放/暂停/倒放控制
- GIF animation export functionality / 生成 GIF 动画导出功能
- Implement HashLife algorithm for large-scale simulation / 实现 HashLife 算法用于大规模模拟
- Add multi-threading support for improved computation speed / 添加多线程支持以提升计算速度
- Implement boundary detection to compute only active regions / 实现边界检测,只计算活跃区域
- ✅ COMPLETED Add color theme switching (dark/light mode) / 添加颜色主题切换(深色/浅色模式)
- ✅ COMPLETED Support zoom functionality (mouse wheel zooming) / 支持缩放功能(鼠标滚轮缩放)
- ✅ COMPLETED Add grid line display toggle / 添加网格线显示开关
- Implement cell age visualization (color gradient by survival time) / 实现细胞年龄可视化(颜色渐变显示存活时间)
- Add brush tools (different brush sizes) / 添加画笔工具(不同大小的笔刷)
- Implement select/copy/paste region functionality / 实现选择/复制/粘贴区域功能
- Add shape drawing tools (lines, rectangles, circles) / 添加形状绘制工具(线条、矩形、圆形)
- Support pattern rotation and mirroring / 支持图案旋转和镜像
- ✅ COMPLETED Real-time live cell count statistics / 实时显示活细胞数量统计
- ✅ COMPLETED Add population growth charts / 添加人口增长图表
- ✅ COMPLETED Interactive population analysis with max/min tracking / 交互式人口分析,包含最大/最小值追踪
- Detect stable states and periodic patterns / 检测稳定状态和周期性图案
- Add pattern recognition (auto-identify known patterns) / 添加模式识别(自动识别已知图案)
- Support other cellular automaton rules (e.g., Highlife, Day & Night) / 支持其他细胞自动机规则(如 Highlife、Day & Night)
- Allow users to define custom rules / 允许用户自定义规则
- Support larger neighborhoods (Moore/von Neumann) / 支持更大的邻域(如 Moore/von Neumann)
- Online pattern library browsing and downloading / 在线图案库浏览和下载
- Share custom pattern functionality / 分享自定义图案功能
- Add more preset pattern categories / 添加更多预设图案分类
- Add more unit tests and integration tests / 添加更多单元测试和集成测试
- Implement benchmark testing / 实现基准测试
- Add CLI mode for headless operation / 添加 CLI 模式支持无头运行
- Improve error handling and user feedback / 改进错误处理和用户反馈
- Web version support (WASM compilation) / Web 版本支持(WASM 编译)
- Mobile adaptation / 移动端适配
- Application packaging and distribution optimization / 应用打包和分发优化
- ✅ COMPLETED: Save/Load Functionality - Essential for preserving work / 保存/加载功能 - 保存工作的基础需求
- ✅ COMPLETED: Zoom and Visual Improvements - Better user experience / 缩放和视觉改进 - 更好的用户体验
- ✅ COMPLETED: Statistics and Analysis - Educational value / 统计和分析 - 教育价值
- History and Playback - Practical utility / 历史记录回放 - 实用功能
- More Preset Patterns - Content enrichment / 更多预设图案 - 内容丰富
- Cell Age Visualization - Enhanced visual feedback / 细胞年龄可视化 - 增强视觉反馈
If you're interested in implementing any of these features, please:
- Check existing issues and pull requests
- Create an issue to discuss the feature before starting
- Follow the contributing guidelines
- Ensure proper testing and documentation
如果您有兴趣实现任何这些功能,请:
- 检查现有的问题和拉取请求
- 在开始之前创建问题来讨论功能
- 遵循贡献指南
- 确保适当的测试和文档