Skip to content

The wave function collapse algorithm is a computational technique used in artificial intelligence and procedural generation. The algorithm iterates through cells with different potential patterns while considering neighbours and constraints. It reduces possibilities, causing patterns to "collapse" into a coherent and visually appealing result.

Notifications You must be signed in to change notification settings

Gurvirr/Wave-Function-Collapse

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Wave Function Collapse Algorithm

WFC

About

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.

Usage

To begin generating your own patterns...

  1. Enter git clone https://github.com/Gurvirr/Wave-Function-Collapse.git in the Command Prompt/Terminal
  2. Locate the cloned repository by typing Wave-Function-Collapse in Windows Start
  3. Run one of the three .exe files
OR
  1. Head over to the repository homepage: https://github.com/Gurvirr/Wave-Function-Collapse
  2. Click the green dropdown labelled Code
  3. Click Download ZIP
  4. Extract the zip folder onto your computer
  5. 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:

Connectivity modules

Connectivity modules

Module C:

C

Module S:

S

Module T:

T

Controls

Image capture:

Like what you generated? Save it!

Press v to capture your lovely render as a .png!

How does it work?

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:

WFC Demo

About

The wave function collapse algorithm is a computational technique used in artificial intelligence and procedural generation. The algorithm iterates through cells with different potential patterns while considering neighbours and constraints. It reduces possibilities, causing patterns to "collapse" into a coherent and visually appealing result.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages