AlGOL is a Game of Life simulation that runs in your browser! It uses fragment shaders to run the simulation frame by frame, as well as loading specific patterns to show their evolution.
Game of Life is a cellular automata that simulates patterns of cells changing over time. Each cell is either "dead" or "alive".
- If an alive cell has more than 3 alive neighbours it dies of crowding
- If an alive cell has less than 2 alive neighbours it dies of loneliness
- If a dead cell has exactly 3 alive neighbours it becomes alive
- Each frame is then decided based on the state of the previous.
More about the game can be found at https://conwaylife.com/wiki/
Website: https://rayzchen.github.io/algol/
The page will automatically fill the world with a random pattern, and you can watch the evolution of the cells one frame at a time. On the right are simulation controls, which include play/pause, step, simulation speed and wrapping. The mouse cursor can be used to click and drag around the map, and the scroll wheel controls zoom. Keyboard shortcuts can be found in the legend on the right.
The minimap in the lower right shows where the current view is in the world. If wrapping is enabled and you have lost where the world is, the reset view button places you back in the centre.
The pattern bank (located at https://rayzchen.github.io/algol/patterns/) contains a collection of interesting patterns that produce controlled effects. These come in multiple categories: gliders (patterns that "move" across the map), guns (patterns that produce gliders periodically), puffers (patterns that leave objects as they move), breeders (patterns that produce other puffers/guns) and oscillators (patterns that cycle through multiple states but do not move). These can be loaded into the simulator to observe their motion.
This project was written in a whole host of languages: HTML and CSS for the user interface, JavaScript for the engine itself, GLSL for many of the GPU-intensive jobs and Python helper scripts to assist in development. Just like my previous project, minimal external dependencies are used, so almost all of the code has been written from scratch.
The project was surprisingly very streamlined in development: each new feature was added one on top of another without too many conflicts between. However, testing each feature always took multiple tries and implementations to find one that worked.
One surprisingly difficult feature was the controlling of framerate. I needed to create two types of simulation speeds: one involved frameskipping to run less than 60 generations per second, and another involved running multiple generations per frame. The user interface side also required multiple redesigns because I wanted the slider to be nonlinear (since changing from 40/s to 41/s had very little effect compared to 2/s to 3/s). In fact, some of the equations I used can be found here: https://www.desmos.com/calculator/3ipfxfsmlu
A feature that I wanted to implement was the placing of patterns in the grid rather than simply clearing and loading. The cursor aspect of this was implemented well, but I could not design a method to translate between GPU and world space coordinates to handle the placing, nor decide whether to use the GPU to place cells or to iterate and place cells individually. If I had more time to work on this project before Stardance ended, this would be the first thing I'd continue working on.
The website runs surprisingly smooth: with a 2048x2048 canvas it can handle 32x speed at 45 fps on an Intel Core Ultra 5 235U laptop. Additionally, the pattern bank gives a very good introduction into the types of patterns that appear in Game of Life, as well as provide an interface to input patterns of any kind from anywhere on the Internet.