Wave Function Collapse #508
Replies: 1 comment
-
Hi, @berinhard ! Thank you so much for posting this. It means a lot to me when people share their py5-related joy!
Couldn't agree more. Sometimes it is best to write something that works and does the right thing first. Later, alter the code for performance. Then you have a slow but working version to compare the fast version with, and can confirm it is done correctly. I don't know much about Wave Function Collapse but it looks interesting. What's the best way to run your code for this? It isn't clear from the code in that folder.
Great, that's excellent. BTW, py5 does have support for library extensions, just like Processing does. You can write a library that uses hooks to attach itself to a Sketch, telling py5 to call the library's functions before or after any user function such as |
Beta Was this translation helpful? Give feedback.
-
Hey people! I'm passing by as suggested by @villares to share with you my implementation of the Wave Function Collapse algorithm in Python on top of py5. Of course, I was heavily influenced by the coding traing challenge on this theme, but I went with some different data modeling decisions.
I feel that their solution is heavily based on loose objects and coupling between data structures indexes. For example, they represent a matrix of cells as a one-dimensional array. Although I know it makes sense in terms of performance and all of that, it's a strategy that hardly fits into my mind. I don't know, for me it's easier to read a code which says me something than doing math operations to understand the intentions of the code.
Guided by this principle, I came up with an more OOO-like implementation which, although is not the optimal in terms of performance, seemed kind of easier to grasp for me. My goal is to have a high-level API where I only need to define tiles with their adjacency rules and the dimension of the grid. In the end, the overall
setup
/draw
methods looks like this:The final code be found here. Thie
be5
directory is a set of helpers that I've used to have with PyProcessing and which I'm porting to py5 now. My idea is to release it as an independent utilities belt to have alongside py5 so I can have some more complex tools, such as WFC algorithm, easily reachable.There are still things that I wanna add to this code like, for example, to support non-symmetrical tiles rotations. But the base foundation for it is there.
See you =)
Beta Was this translation helpful? Give feedback.
All reactions