In quantum physics, a wave function collapses when it transitions from a hypothetical superposition -- a phenomenon that allows a quantum system to exist in multiple states at once -- to a singular state.
The Wave Function Collapse Algorithm on the other hand is a computational technique used in artificial intelligence and procedural generation. The algorithm iterates through each cell in a definitive grid which all begin with the same possiblity of potential, distinct patterns called tiles. The initial possibility of unique tiles in a singular cell is equal to the total number of tiles. These possibilities are named the entropy of the cell and begin to decrease when the program accounts for tile neighbours and the preset constraints of each tile. This causes these patterns to collapse into a coherent and visually appealing result.
- Enter
git clone https://github.com/Gurvirr/Wave-Function-Collapse.git
in the Command Prompt/Terminal - Locate the cloned repository by typing
Wave-Function-Collapse
in Windows Start - Run one of the three
.exe
files
- Head over to the repository homepage:
https://github.com/Gurvirr/Wave-Function-Collapse
- Click the green dropdown labelled
Code
- Click
Download ZIP
- Extract the zip folder onto your computer
- Run one of the three
.exe
files
You can also run the Python source file
named WFC.py
if you have the Pygame library
installed. Note that in order to switch between the 3 connectivity modules, you will have to update line 4:
Like what you generated? Save it!
Press v to capture your lovely render as a .png
!
The Wave Function Collapse Algorithm can become very difficult to comprehend and oftentimes unnecessarily convoluted, especially with more advanced adaptations. My goal while working on this adaptation of the algorithm was to make it as straightforward, efficient and simplified as possible, which I believe I have accomplished seeing how the entire program is only 65 lines!
As previously established, the algorithm procedurally generates a pattern by considering the potential neighbours and constraints of the various tiles. To better understand how this really works, let's step back and take a look at the Wave Function Collapse Algorithm in action: