This is my research implementation of WaveFunctionCollapse in Python. It has two goals:
- Make it easier to understand how the algorithm operates
- Provide a testbed for experimenting with alternate heuristics and features
For more general-purpose WFC information, the original reference repository remains the best resource: https://github.com/mxgmn/WaveFunctionCollapse
git clone https://github.com/ikarth/wfc_2019f.git
cd wfc_2019f
conda create -n wfc2019 python=3.10
conda activate wfc2019
pip install -r requirements.txt
python wfc_run.py -s samples_reference.xml
If you want direct control over running WFC, call wfc_control.execute_wfc()
.
The arguments it accepts are:
filename=None
: path to the input image file, this is mostly for internal use and should be left asNone
, setimage
instead.tile_size=1
: size of the tiles it uses (1 is fine for pixel images, larger is for things like a Super Metroid map)pattern_width=2
: size of the patterns; usually 2 or 3 because bigger gets slower androtations=8
: how many reflections and/or rotations to use with the patternsoutput_size=[48,48]
: how big the output image isground=None
: which patterns should be placed along the bottom-most lineattempt_limit=10
: stop after this many triesoutput_periodic=True
: the output wraps at the edgesinput_periodic=True
: the input wraps at the edgesloc_heuristic="entropy"
: what location heuristic to use;entropy
is the original WFC behavior. The heuristics that are implemented arelexical
,hilbert
,spiral
,entropy
,anti-entropy
,simple
,random
, but when in doubt stick withentropy
.choice_heuristic="weighted"
: what choice heuristic to use;weighted
is the original WFC behavior, other options arerandom
,rarest
, andlexical
.visualize=False
: write intermediate images to disk? requiresfilename
.global_constraint=False
: what global constraint to use. Currently the only one implemented isallpatterns
backtracking=False
: do we use backtracking if we run into a contradiction?log_filename="log"
: what should the log file be named?logging=False
: should we write to a log file? requiresfilename
.log_stats_to_output=None
image
: an array of pixel data, typically in the shape: (height, width, rgb)
pytest
python setup.py build_sphinx
With linux the documentation can be displayed with:
xdg-open build/sphinx/index.html