This is an implementation of the Wave Function Collapse (WFC) algorithm in Python, based on the first half of Daniel Shiffman's video tutorial on the subject (https://youtu.be/rI_y2GAlQFM).
The Wave Function Collapse algorithm is used to generate tile-based patterns by propagating constraints through a grid of cells. Each cell has a set of possible tile states, and the algorithm collapses cells by eliminating incompatible states based on neighboring cells. The process continues until either all cells have collapsed or contradictions arise.
This implementation uses the Pygame library to provide a graphical representation of the generated patterns. The grid is displayed on a window, and the tiles are rendered as images.
This program requires the following dependencies:
- Python 3.x
- Pygame
- Make sure you have Python and Pygame installed on your system.
- Clone or download the code files to your local machine.
- Open a terminal or command prompt and navigate to the directory containing the code files.
- Run the following command to execute the program:
python main.py
- The generated patterns will be displayed in the Pygame window.
- Upon completion a clean screenshot of the result will be saved to the output folder and the time taken to generate will be displayed on the center of the screen.
- Press the Spacebar to reset the board and generate a new pattern.
- Press Escape or close the window to exit the program.
You can customize the following parameters in the main.py
file:
debug_mode
: Set toTrue
to display possible tile states.grid_size
: The size of the grid (number of cells per row and column).tileset
: a string, the name of the tileset folderweights
: weights to use when selecting a random tile
This project is provided without any specific license. You are free to use and modify the code for personal or educational purposes. However, please refer to the licenses of the dependencies (if any) for their usage terms.