Wave Function Collapse

I’m trying to generate terrain using wfc and i read alot of papers and implementations but i can’t wrap my head around it. Can someone make a simple implementation? I’ll expand it from there

Here’s a simple image of what wfc can do, but it can get alot more complex from that:

1 Like

Hi @hasanchik !
Thank you for introducing WFC, even I don’t know that before, so I searched and study a little, so interesting and powerful algorithm. I gonna to make a “3D” maze with it later.
Then I tried to migrate the codes from https://github.com/mxgmn/WaveFunctionCollapse, as below:

Totally worked, but only one tilesets (Circuit) by now. Try different subset (tiles combinations) by change the subset enum, and the size in main.ts.

For example, WiresOnly:


Hi bros!
This update is more interesting to play. You can participate into whole generating process.
There are 2 steps in each loop of generation:

  • choose a position
  • choose a tile in all possible tiles


  • Arrow key to move the cursor
  • A for choose,
  • or B for cancel (chosen by WFC with its random logic).

You can choose manually, or automatically by WFC, at any step.
So you can “Predefine” what and at where tiles you want, and then let WFC random the rest.

Maybe we can use it to generate tilemap (include maze map or so), or textures, or something else I haven’t thought out. And I wondering weather should I make it as a extension, cause it is more likely a editor. :upside_down_face:
Let me know please, what feature/interface you want, if you think it’s useful.

How WFC algorithm do these steps?

  • position: it always choose the one having the least possible tiles at that time (the lowest entropy)
  • tiles: randomly choose one base on the weight of possible tiles
    This strategy can make it the most possibility to complete the generation. Or it may fail midway, caused rule conflict by a serials of tiles already chosen. (Rules are defined in wfc_data.ts)
1 Like