2d implementation of the Wave Function Collapse algorithm in JavaScript running on the web.

What is Wave Function Collapse?

In quantum mechanics, wave function collapse occurs when a wave function—initially in a superposition of several eigenstates—reduces to a single eigenstate due to interaction with the external world. This interaction is called an observation, and is the essence of a measurement in quantum mechanics, which connects the wave function with classical observables such as position and momentum.
— Wikipedia

How does Wave Function Collapse work?

WFC initializes output bitmap in a completely unobserved state, where each pixel value is in superposition of colors of the input bitmap (so if the input was black & white then the unobserved states are shown in different shades of grey). The coefficients in these superpositions are real numbers, not complex numbers, so it doesn't do the actual quantum mechanics, but it was inspired by QM. Then the program goes into the observation-propagation cycle:
  • On each observation step an NxN region is chosen among the unobserved which has the lowest Shannon entropy. This region's state then collapses into a definite state according to its coefficients and the distribution of NxN patterns in the input.
  • On each propagation step new information gained from the collapse on the previous step propagates through the output.
On each step the number of non-zero coefficients decreases and in the end we have a completely observed state, the wave function has collapsed.
It may happen that during propagation all the coefficients for a certain pixel become zero. That means that the algorithm has run into a contradiction and can not continue. The problem of determining whether a certain bitmap allows other nontrivial bitmaps satisfying condition (C1) [(C1): the output should contain only those NxN patterns of pixels that are present in the input] is NP-hard, so it's impossible to create a fast solution that always finishes. In practice, however, the algorithm runs into contradictions surprisingly rarely.
— mxgmn
More information: https://github.com/mxgmn/WaveFunctionCollapse#algorithm

(Note: My implementation approximately follows this)

Wave Function Collapse parameters explained

COMING SOON! (For now see: https://github.com/mxgmn/WaveFunctionCollapse for the best explanations)

Main Resources Used

Image Sources

Download

Download NowName your own price

Click download now to get access to the following files:

Web Build.zip

Comments

Log in with itch.io to leave a comment.

(+1)

Amazing work