HackerReposA FIELD GUIDE TO OPEN SOURCE
ProSponsor the shelf♧ 0
← Back to top all-time
mxgmn
WaveFunctionCollapse
C#2016–2026
mxgmn / WaveFunctionCollapse

WaveFunctionCollapse

Bitmap & tilemap generation from a single example with the help of ideas from quantum mechanics

55Distinct people
63Mentions
2Explicit recommenders
25.5KGitHub stars
REPOSITORY AT A GLANCE

What to know before exploring

What it is

Bitmap & tilemap generation from a single example with the help of ideas from quantum mechanics

GitHub

Where it is used

No documented product use was verified in the last source check.

What people are saying

https://news.ycombinator.com/item?id=37485705 DonHopkins on Sept 12, 2023 | parent | context | favorite | on: CityDreamer: Compositional Generative Model of Unb... Here's some…

DonHopkins used a recommendation phrase. 3 indexed comments match. This is a phrase match, not a verdict.

No classified warning is attached to this page. Read the discussions before treating silence as approval.

Also in these discussions

Mentioned in the same Hacker News threads. That is not proof they are substitutes.

This week on Hacker News

Nov 7–Nov 14 UTC · Direct repository links and separately labeled related project stories. Indexed through 11/14/2026, 11:56:56 AM UTC.

No direct repository links were found in the indexed HN discussions over the past seven days. Older discussions are available below.

Mentions over time

HN mentions by year63 dated mentions

Observed mentions: 2016-09-30 13:20:43 UTC to 2026-08-04 14:46:46 UTC.

0510152016-01-01 00:00:00 UTC to 2017-01-01 00:00:00 UTC (exclusive): 3 mentions; 1 submissions, 2 comments20162017-01-01 00:00:00 UTC to 2018-01-01 00:00:00 UTC (exclusive): 1 mentions; 0 submissions, 1 comments2018-01-01 00:00:00 UTC to 2019-01-01 00:00:00 UTC (exclusive): 13 mentions; 1 submissions, 12 comments2019-01-01 00:00:00 UTC to 2020-01-01 00:00:00 UTC (exclusive): 6 mentions; 5 submissions, 1 comments2020-01-01 00:00:00 UTC to 2021-01-01 00:00:00 UTC (exclusive): 4 mentions; 1 submissions, 3 comments2021-01-01 00:00:00 UTC to 2022-01-01 00:00:00 UTC (exclusive): 6 mentions; 1 submissions, 5 comments20212022-01-01 00:00:00 UTC to 2023-01-01 00:00:00 UTC (exclusive): 10 mentions; 0 submissions, 10 comments2023-01-01 00:00:00 UTC to 2024-01-01 00:00:00 UTC (exclusive): 6 mentions; 1 submissions, 5 comments2024-01-01 00:00:00 UTC to 2025-01-01 00:00:00 UTC (exclusive): 3 mentions; 0 submissions, 3 comments2025-01-01 00:00:00 UTC to 2026-01-01 00:00:00 UTC (exclusive): 6 mentions; 0 submissions, 6 comments2026-01-01 00:00:00 UTC to 2027-01-01 00:00:00 UTC (exclusive): 5 mentions; 2 submissions, 3 comments. Incomplete calendar period.2026*

* An incomplete calendar period is marked with an outlined bar. Its count is not directly comparable with a full period.

Counts come from the repository’s dated source evidence. Index cutoff: 2026-11-02 08:16:59 UTC.

View mention counts and date ranges
UTC ranges include their start and exclude their end. Select a period to filter the source evidence.
PeriodStart (UTC)End (exclusive, UTC)MentionsSubmissionsComments
20162016-01-01 00:00:00 UTC2017-01-01 00:00:00 UTC312
20172017-01-01 00:00:00 UTC2018-01-01 00:00:00 UTC101
20182018-01-01 00:00:00 UTC2019-01-01 00:00:00 UTC13112
20192019-01-01 00:00:00 UTC2020-01-01 00:00:00 UTC651
20202020-01-01 00:00:00 UTC2021-01-01 00:00:00 UTC413
20212021-01-01 00:00:00 UTC2022-01-01 00:00:00 UTC615
20222022-01-01 00:00:00 UTC2023-01-01 00:00:00 UTC10010
20232023-01-01 00:00:00 UTC2024-01-01 00:00:00 UTC615
20242024-01-01 00:00:00 UTC2025-01-01 00:00:00 UTC303
20252025-01-01 00:00:00 UTC2026-01-01 00:00:00 UTC606
2026 (partial)2026-01-01 00:00:00 UTC2027-01-01 00:00:00 UTC523

From the project README

An excerpt from the repository, fetched Nov 14, 2026.

Read the project’s introduction
WaveFunctionCollapse This program generates bitmaps that are locally similar to the input bitmap. Local similarity means that (C1) The output should contain only those NxN patterns of pixels that are present in the input. (Weak C2) Distribution of NxN patterns in the input should be similar to the distribution of NxN patterns over a sufficiently large number of outputs. In other words, probability to meet a particular pattern in the output should be close to the density of such patterns in the input. In the examples a typical value of N is 3. WFC initializes output bitmap in a completely unobserved state, where each pixel value is in superposition of colors of the input bitmap (so if the input was black & white then the unobserved states are shown in different shades of grey). The coefficients in these superpositions are real numbers, not complex numbers, so it doesn't do the actual quantum mechanics, but it was inspired by QM. Then the program goes into the observation-propagation cycle: On each observation step an NxN region is chosen among the unobserved which has the lowest Shannon entropy. This region's state then collapses into a definite state according to its coefficients and the distribution of NxN patterns in the input. On each propagation step new information gained from the collapse on the previous step propagates through the output. On each step the number of non-zero coefficients decreases and in the end we have a completely observed state, the wave function has collapsed. It may happen that during propagation all the coefficients for a certain pixel become zero. That means that the algorithm has run into a contradiction and can not continue. The problem of determining whether a certain bitmap allows other nontrivial bitmaps satisfying condition (C1) is NP-hard, so it's impossible to create a fast solution that always finishes. In practice, however, the algorithm runs into contradictions surprisingly rarely. Wave Function Collapse algorithm has been implemented in C++, Python, Kotlin, Rust, Julia, Go, Haxe, Java, Clojure, Free Pascal, Dart, p5js, JavaScript and adapted to Unity, Unreal Engine 5, Godot 4 and Houdini. You can build WFC from source, download an official release for Windows, download an interactive graphical version from itch.io or run it in the browser. WFC generates levels in Bad North, Caves of Qud, Dead Static Drive, Townscaper, Matrix Awakens, several smaller games and many prototypes. It led to new research. For more related work, explanations, interactive demos, guides, tutorials and examples see the ports, forks and spinoffs section. Watch a video demonstration of WFC algorithm on YouTube: https://youtu.be/DOQTr2Xmlz0 Algorithm Read the input bitmap and count NxN patterns. (optional) Augment pattern data with rotations and reflections. Create an array with the dimensions of the output (called "wave" in the source). Each element of this array represents a state of an NxN region in the output. A state of an NxN region is a superposition of NxN patterns of the input with boolean coefficients (so a state of a pixel in the output is a superposition of input colors with real coefficients). False coefficient means that the corresponding pattern is forbidden, true coefficient means that the corresponding pattern is not yet forbidden. Initialize the wave in the completely unobserved state, i.e. with all the boolean coefficients being true. Repeat the following steps: Observation: Find a wave element with the minimal nonzero entropy. If there is no such elements (if all elements have zero or undefined entropy) then break the cycle (4) and go to step (5). Collapse this element into a definite state according to its coefficients and the distribution of NxN patterns in the input. Propagation: propagate information gained on the previous observation step. By now all the wave elements are either in a completely observed state (all the coefficients except one being zero) or in the contradictory state (all the coefficients being zero). In the first case return the output. In the second case finish the work without returning anything. Tilemap generation The simplest nontrivial case of the algorithm is when NxN=1x2 (well, NxM). If we simplify it even further by storing not the probabilities of pairs of colors but the probabilities of colors themselves, we get what we call a "simple tiled model". The propagation phase in this model is just adjacency constraint propagation. It's convenient to initialize the simple tiled model with a list of tiles and their adjacency data (adjacency data can be viewed as a large set of very small samples) rather than a sample bitmap. Lists of all the possible pairs of adjacent tiles in practical tilesets can be quite long, so I implemented a symmetry system for tiles to shorten the enumeration. In this system each tile should be assigned with its symmetry type. Note that the tiles have the same symmetry type as their assigned letters (or, in other words, actions of the dihedral group D4 are isomorphic for tiles and their corresponding letters). With this system it's enough to enumerate pairs of adjacent tiles only up to symmetry, which makes lists of adjacencies for tilesets with many symmetrical tiles (even the summer tileset, despite drawings not being symmetrical the system considers such tiles to be symmetrical) several times shorter. Note that the unrestrained knot tileset (with all 5 tiles being allowed) is not interesting for WFC, because you can't run into a situation where you can't place a tile. We call tilesets with this property "easy". Without special heuristics easy tilesets don't produce interesting global arrangements, because correlations of tiles in easy tilesets quickly fall off with a distance. Many easy tilesets can be found on Guy Walker's website. Consider the "Dual" 2-edge tileset there. How can it generate knots (without t-junctions, not easy) while being easy? The answer is, it can onl
Read the full README on GitHub

What Hacker News says

63 sources
No I just meant WFC as an algorithm for solving problems. https://github.com/mxgmn/WaveFunctionCollapse It's one of the coolest things I've ever seen. I guess I've been pronouncing it wrong though. It's wave function collapse, not waveform. I haven't studied it properly yet but it kind of looks like how sudokus work. You have a bunch of plausible options, and the various possible worlds overlap with each other but not completely and then you eliminate the things that are not possible until the actual possibility remains. I think thinking works similarly, and I wouldn't be surprised if artificial thinking also worked similarly.
In Ten advances in mathematics and theoretical computer science
I didn't want to nitpick terminology, but yes, the tile-placement algorithm here is just a way of solving constraint satisfaction problems with DFS using a "minimum remaining values" heuristic [0]. The original use case for generating textures [1] is different in that the constraints are implicit in the input bitmap, but this project is a more straightforward tile placement with explicit constraints. I think this algorithm is more efficient for generating maps with only local (adjacency) constraints, but setting this up as an integer linear program and plugging it into a constraint solver is more generalizable (say, if you wanted to enforce a constraint that rivers had to flow across the whole map and could not loop). But I agree "wave function collapse" is not really the best name, for two reasons: - the original repository mentions "it
Read the rest
doesn't do the actual quantum mechanics, but it was inspired by QM", but it implies something QM-related. - as an ORIE major in college that loved optimization, I think constraint satisfaction problems are really cool and actually somewhat approachable! So calling the heuristic something else like "wave function collapse" might limit people from finding previous work and known improvements (e.g. forward checking). [0] https://www.cs.cornell.edu/courses/cs4700/2011fa/lectures/05... [1] https://github.com/mxgmn/WaveFunctionCollapse
In Building a Procedural Hex Map with Wave Function Collapse
This is based off of Paul Merrell's Model Synthesis work [0]. Boris The Brave had a good writeup of the core of the algorithm [1]. Max Gumin focused on just the constraint solver and added a "minimum entropy heuristic", popularized the work and coined the term "wave function collapse", as the way the solver worked was evocative of (a naive view) of how quantum mechanics solves systems [2]. Gumin's repo also has many other resources of implementations and descriptions [3]. I've published a paper on an extension that adds in a type of backtracking to both the "WFC" portion of the solver and the modify in blocks portion of the solver, which can be found in [4], for those interested. [0] https://paulmerrell.org/model-synthesis/ [1] https://www.boristhebrave.com/2021/10/26/model-synthesis-and... [2] https://github.com/mxgmn/WaveFunctionCollaps
Read the rest
In Procedural generation with Wave Function Collapse (2019)
I think people went gaga over it due to the sample generations on the original repository (and the simplicity of implementation for arbitrary bitmaps), not so much the name. https://github.com/mxgmn/WaveFunctionCollapse As for global repetition, the original repo did have this to say, that selecting tiles is important. "Note that the unrestrained knot tileset (with all 5 tiles being allowed) is not interesting for WFC, because you can't run into a situation where you can't place a tile. We call tilesets with this property "easy". Without special heuristics easy tilesets don't produce interesting global arrangements, because correlations of tiles in easy tilesets quickly fall off with a distance. "
In Generating an infinite world with the Wave Function Collapse algorithm
DonHopkins·Jan 18, 2025Recommendation phrase
https://news.ycombinator.com/item?id=37485705 DonHopkins on Sept 12, 2023 | parent | context | favorite | on: CityDreamer: Compositional Generative Model of Unb... Here's some comments and links about Wave Function Collapse I wrote recently: https://news.ycombinator.com/item?id=34561910 [...stuff about SandSpielStudio and block visual programming languages like Scratch and Snap!, Long Now talk between Will Wright and Brian Eno about Cellular Automata, etc ...] The other really cool rabbit hole to explore for generating tiles and even arbitrary graph based content (I'm sold: hexagons are the bestagons!) is "Wave Function Collapse", which doesn't actually have anything to do with quantum mechanics (it just sounds cool), but is actually a kind of constraint solver related to sudoku solvers. https://escholarship.org/content/qt3rm1w0mn/qt3rm1w
Read the rest
0mn_noSpl... Maxim Gumin's work: https://github.com/mxgmn/WaveFunctionCollapse Paul Merrell's work: https://paulmerrell.org/model-synthesis/ https://paulmerrell.org/research/ Oskar Stålberg's work: https://twitter.com/OskSta/status/784847588893814785 https://oskarstalberg.com/game/wave/wave.html There's a way to define cellular automata rules by giving examples of the before and after patterns, and WFC is kind of like a statistical constraint solving version of that. So it's really easy for artists to define rules just by drawing! Not even requiring any visual programming, but you can layer visual programming on top of it. That's something that Alexander Repenning's "AgentSheets" supported (among other stuff): you could define cellular automata rules by before-and-after examples, wildcards and variables, and attach additional conditions and actions with a visual programming language. AgentSheets and other cool systems are described in this classic paper: “A Taxonomy of Simulation Software: A work in progress” from Learning Technology Review by Kurt Schmucker at Apple. It covered many of my favorite systems. http://donhopkins.com/home/documents/taxonomy.pdf Chaim Gingold wrote a comprehensive "Gadget Background Survey" at HARC, which includes AgentSheets, Alan Kay's favorites: Rockey’s Boots and Robot Odyssey, and Chaim's amazing SimCity Reverse Diagrams and lots of great stuff I’d never seen before: http://chaim.io/download/Gingold%20(2017)%20Gadget%20(1)%20S... Chaim Gingold has analyzed the SimCity (classic) code and visually documented how it works, in his beautiful "SimCity Reverse Diagrams": >SimCity reverse diagrams: Chaim Gingold (2016). >These reverse diagrams map and translate the rules of a complex simulation program into a form that is more easily digested, embedded, disseminated, and and discussed (Latour 1986). >The technique is inspired by the game designer Stone Librande’s one page game design documents (Librande 2010). If we merge the reverse diagram with an interactive approach—e.g. Bret Victor’s Nile Visualization (Victor 2013), such diagrams could be used generatively, to describe programs, and interactively, to allow rich introspection and manipulation of software. >Latour, Bruno (1986). “Visualization and cognition”. In: Knowledge and Society 6 (1986), pp. 1– 40. Librande, Stone (2010). “One-Page Designs”. Game Developers Conference. 2010. Victor, Bret (2013). “Media for Thinking the Unthinkable”. MIT Media Lab, Apr. 4, 2013. https://lively-web.org/users/Dan/uploads/SimCityReverseDiagr [... stuff about AgentSheets, KidSim, Lex Fridman interviews of Michael Levin and Steven Wolfram discussing Cellular Automata, CAM6 simulator, etc ...] More: https://news.ycombinator.com/item?id=34561910
In Generating an infinite world with the Wave Function Collapse algorithm
I'm working on an extension to the Modify in blocks Model Synthesis algorithm [0] and the Wave Function Collapse algorithm [1] called "Punch Out Model Synthesis": https://github.com/zzyzek/PunchOutModelSynthesis Here's a gallery of sample outputs from the algorithm: https://github.com/zzyzek/PunchOutModelSynthesis/blob/main/r... I have an online demo of the algorithm in action for different tilesets (it's a little rough, so be warned): https://zzyzek.github.io/PunchOutModelSynthesis/ The idea is you take an example image, chop it into little segments and infer tile rules depending on the overlap. It's very much old fashioned "machine learning/artificial intelligence" (that is, without any neural networks involved). There's also a demo of tile rule inference idea here: https://zzyzek.github.io/TileRuleHighlighter/ [0] https://github.com/mx
Read the rest
In Ask HN: What are you working on (September 2024)?
Fascinating in-depth write up > Another idea would be to render tiles and modifying the tiles content by just modulating the bit fields or map a set of tiles differently or do simple transforms using bitwise operations such as mirroring, once you have a complete set of tile operations you can combine them to compose detailed patterns / images, ones could also animate tiles individually by switching values in a cyclic fashion… Could something like the wave function collapse algorithm[1] be used for this, ie. generating tiles that are similar to a certain base pattern? [1] https://github.com/mxgmn/WaveFunctionCollapse
In Tiny bitfield based text renderer (2022)

Showing the 15 most recent of 63 sources. Enable JavaScript to search and browse every indexed mention.

MAKE YOURSELF AT HOME

A few shortcuts

/
Search the collection
?
Open this guide
Esc
Close dialogs and navigation

Your saved repositories and interests stay in this browser.