https://github.com/FeatheredSnek/phpwfc
Tiled Wave Function Collapse in PHP
https://github.com/FeatheredSnek/phpwfc
coding-train creative-coding generative-art map-generator php tiles-generator wave-function-collapse wfc
Last synced: about 1 month ago
JSON representation
Tiled Wave Function Collapse in PHP
- Host: GitHub
- URL: https://github.com/FeatheredSnek/phpwfc
- Owner: FeatheredSnek
- Created: 2023-07-16T15:47:28.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-08-31T15:11:27.000Z (about 2 years ago)
- Last Synced: 2024-12-31T04:33:05.365Z (9 months ago)
- Topics: coding-train, creative-coding, generative-art, map-generator, php, tiles-generator, wave-function-collapse, wfc
- Language: PHP
- Homepage: https://dorianm.com/demos/php-wfc
- Size: 85.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PHP-WFC
A simple WFC tiled model generator made with PHP. Check it out at [my website](https://dorianm.com/demos/php-wfc).
## Background and purpose
Having watched [Dan Shiffman's video on WFC](https://thecodingtrain.com/challenges/171-wave-function-collapse/) I really wanted to have a go at the code -- and, even more so, at designing a tileset. At the same time, I strongly believe in using wrong tools for the job, as it really helps with creativity and problem solving. PHP feels like an absolute wrong choice for generative art, so there it is.## How it's made
The WFC itself is made with plain PHP 8.2 (though it does not use features above 8). Simple HTML/CSS UI added on top. Custom space station tileset made with Krita.## Concluding remarks
My goal here was to implement WFC with clean OOP, which turned out fine. There are base abstract classes which are currently being extended by Grid2D -- but they can readily be used to make hex or even 3d version. Output renderer is also separated form the generator, so you could theoretically render to xml, three.js compatible JSON etc. At the same time, I spent no time on thinking about the algorithm itself whatsoever, so it's absolutely not optimized and will always kill the PHP runner when asked for a grid bigger than 30x30. If I'd ever come back to the project, I'd like to add a JSON importer to TilesetManager. It would receive a file with tile definitions (image links + slot setups) and would then output a generated map.Demo tiles courtesy of Coding Train (link above).
Circuit and Floor Map tilesets grabbed from the original WFC repo https://github.com/mxgmn/WaveFunctionCollapse.
All code and the space station tileset licensed MIT.