Python3 Wave Function Collapse Algorithm implementation
Project description
PyWFC
Overview
PyWFC is an implementation of the Wave Function Collapse Algorithm.
Installation
Use pip install pywfc
to install via pip
Or use git clone https://github.com/FoxNerdSaysMoo/PyWFC && python PyWFC/setup.py
(not tested yet)
Usage
Contains 3 main classes: Wave
, State
, Rule
from wfc import Wave, State, Rule
Rule
determines where a state can be, and State
contains a Rule
and a name.
grass = State(
"grass",
Rule(
lambda x, y : { # Rule uses a lambda
(x, y+1): ["air"], # Which takes the x and y coordinate of the state
(x, y-1): ["dirt", "stone"] # And returns what the states relative to it must be
}
)
)
dirt = State(
"dirt",
Rule(
lambda x, y: {
(x, y+1): ["dirt", "grass"],
(x, y-1): ["stone", "dirt"]
}
)
)
stone = State(
"stone",
Rule(
lambda x, y : {
(x, y+1): ["stone", "dirt"]
}
)
)
air = State(
"air",
Rule(
lambda x, y : {
(x, y+1): ["air"]
}
)
)
A Wave
takes in the dims of the output grid, along with the states that will populate it.
landscape_wave = Wave(
(10, 40),
[grass, dirt, stone, air]
)
Now all you need to do is collapse the wave!
landscape = landscape_wave.collapse()
Now you have a multidimensional list of Potential
s that have one single state now.
Potential
is a class used inside of wfc, which represents the potentials states before, during, and after the wave function collapse.
import colorama
cmap = {
"air": colorama.Fore.WHITE,
"grass": colorama.Fore.GREEN,
"dirt": colorama.Fore.YELLOW,
"stone": colorama.Fore.BLACK
}
for row in landscape:
for item in row:
print(cmap[item.state.name] + "█" + colorama.Fore.RESET, end="")
print()
There you go! Those are the current classes and example usages of them. There are many planned features and expansions to be added to PyWFC, however we are taking our time to ensure they are the best possible they can be.
Thanks for checking out PyWFC, and we hope you like it ;)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pywfc-0.0.0.tar.gz
.
File metadata
- Download URL: pywfc-0.0.0.tar.gz
- Upload date:
- Size: 3.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.8.0 tqdm/4.59.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f60bcb49584a8d29ae45f1ffd4c1c851ff83c61ab68dc9d9c4b398cc3fab3a3c |
|
MD5 | 1e50a0315893d611e8c4e365f51cbe83 |
|
BLAKE2b-256 | d7aae9d65dff8ed52334370662ed4dceb473f78ac36ebaa152079e8449302aa2 |
File details
Details for the file pywfc-0.0.0-py3-none-any.whl
.
File metadata
- Download URL: pywfc-0.0.0-py3-none-any.whl
- Upload date:
- Size: 3.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.8.0 tqdm/4.59.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b30787886d25cc0d2e8805ac02c53bf3754bde097d0631a24531e9db2b75cdf |
|
MD5 | 25810b5e72f90a2bdaa9c12dafbf960a |
|
BLAKE2b-256 | b370400cf2c8d73648e6455c3f3b9781342eeb4121c980111f344739b77b7e3c |