Uploaded January 2025 | Updated November 2026, 1 day ago
Wave Function Collapse is an algorithm for procedural image generation. In this long overdue follow-up to my tiled model video, I dive into the overlapping model, coding it step by step (complete with struggles and messy debugging interludes) in JavaScript with p5.js. Code: thecodingtrain.com/challenges/186-wfc-overlapping-model
π Watch this video ad-free on Nebula nebula.tv/videos/codingtrain-coding-challenge-186-wave-function-collapse
π» Github Repo: github.com/CodingTrain/Wave-Function-Collapse
p5.js Web Editor Sketches:
πΉοΈ Wave Function Collapse: Overlapping Model: editor.p5js.org/codingtrain/sketches/SI0c2D_tQ
πΉοΈ WFC Overlapping Model Refactored: editor.p5js.org/codingtrain/sketches/2sV4KtcoD
πΉοΈ WFC Overlapping Model: Shannon entropy: editor.p5js.org/codingtrain/sketches/PX0Hn6TF8
πΉοΈ WFC Overlapping Model: More tiles!: editor.p5js.org/codingtrain/sketches/z_N2TVjRH
π₯ Previous: youtu.be/MazpwQNdJYQ?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ All: youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
References:
π Wave Function Collapse GitHub Repo: github.com/mxgmn/WaveFunctionCollapse
π Model Synthesis: paulmerrell.org/model-synthesis
π Procedural Generation with Wave Function Collapse: gridbugs.org/wave-function-collapse
π Wave Function Collapse: github.com/CodingTrain/Wave-Function-Collapse
π p5.js copy(): p5js.org/reference/p5/copy
π p5.js web editor console log GitHub issue: github.com/processing/p5.js-web-editor/issues/3178
π JavaScript concat() method: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
π p5.js randomSeed(): p5js.org/reference/p5/randomSeed
Videos:
π₯ youtu.be/nMUMZ5YRxHI
π₯ youtube.com/watch?v=r5Iy3v1co0A
π₯ youtu.be/qmnH5MT_luk
π₯ youtu.be/mrYMzpbFz18
Creative Works Featured:
π¨ Townscaper: townscapergame.com
π¨ unity-wave-function-collapse: selfsame.itch.io/unitywfc
π¨ Super Mario WFC: observablehq.com/@makio135/super-mario-wfc
π¨ Zelda WFC: observablehq.com/@makio135/zelda-wfc
π¨ Infinite procedurally generated city: marian42.de/article/wfc
Related Coding Challenges:
π youtu.be/HyK_Q5rrcr4
π youtu.be/uQZLzhrzEs4
π youtu.be/rI_y2GAlQFM
Timestamps:
0:00:00 Introduction
0:01:12 The Nature of Code book!
0:02:20 WFC Resources and References
0:08:19 Extracting tiles from a source image
0:21:30 Calculating adjacency rules for tiles
0:24:34 Checking for overlapping pixel colors
0:32:20 Debugging tile adjacencies
0:43:30 Creating a Cell class
0:46:21 Incorporate code from WFC tile model
0:50:50 Reduce entropy of neighboring tiles
0:55:56 Rendering the center pixel for each tile
0:58:05 Cross checking valid tile options
1:01:57 Recursive entropy reduction
1:05:32 Limit recursion depth
1:06:32 Challenge complete?
1:08:26 Bugs found between Day 1 and Day 2
1:09:13 Starting Day 2
1:10:02 Correcting pixel color if statement
1:11:16 Refactoring redundant code
1:17:26 Running out of tile options
1:21:24 Optimizing the code
1:23:47 Rendering average pixel color of remaining tile options
1:26:23 How to handle redundant tiles?
1:28:30 More tiles with rotations and reflections
1:29:39 Additional performance optimizations
1:31:40 Thanks for watching!
Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound
π Website: thecodingtrain.com
πΎ Share Your Creation! thecodingtrain.com/guides/passenger-showcase-guide
π© Suggest Topics: github.com/CodingTrain/Suggestion-Box
π‘ GitHub: github.com/CodingTrain
π¬ Discord: thecodingtrain.com/discord
π Membership: youtube.com/thecodingtrain/join
π Store: standard.tv/codingtrain
ποΈ Twitter: twitter.com/thecodingtrain
πΈ Instagram: instagram.com/the.coding.train
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
π p5.js: p5js.org
π p5.js Web Editor: editor.p5js.org
π Processing: processing.org
π Code of Conduct: github.com/CodingTrain/Code-of-Conduct
This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecodingtrain.com/issues/new
#wavefunctioncollapse #overlappingmodel #proceduralgeneration #p5js #javascript
Wave Function Collapse is an algorithm for procedural image generation. In this long overdue follow-up to my tiled model video, I dive into the overlapping model, coding it step by step (complete with struggles and messy debugging interludes) in JavaScript with p5.js. Code: thecodingtrain.com/challenges/186-wfc-overlapping-model
π Watch this video ad-free on Nebula nebula.tv/videos/codingtrain-coding-challenge-186-wave-function-collapse
π» Github Repo: github.com/CodingTrain/Wave-Function-Collapse
p5.js Web Editor Sketches:
πΉοΈ Wave Function Collapse: Overlapping Model: editor.p5js.org/codingtrain/sketches/SI0c2D_tQ
πΉοΈ WFC Overlapping Model Refactored: editor.p5js.org/codingtrain/sketches/2sV4KtcoD
πΉοΈ WFC Overlapping Model: Shannon entropy: editor.p5js.org/codingtrain/sketches/PX0Hn6TF8
πΉοΈ WFC Overlapping Model: More tiles!: editor.p5js.org/codingtrain/sketches/z_N2TVjRH
π₯ Previous: youtu.be/MazpwQNdJYQ?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ All: youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
References:
π Wave Function Collapse GitHub Repo: github.com/mxgmn/WaveFunctionCollapse
π Model Synthesis: paulmerrell.org/model-synthesis
π Procedural Generation with Wave Function Collapse: gridbugs.org/wave-function-collapse
π Wave Function Collapse: github.com/CodingTrain/Wave-Function-Collapse
π p5.js copy(): p5js.org/reference/p5/copy
π p5.js web editor console log GitHub issue: github.com/processing/p5.js-web-editor/issues/3178
π JavaScript concat() method: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concat
π p5.js randomSeed(): p5js.org/reference/p5/randomSeed
Videos:
π₯ youtu.be/nMUMZ5YRxHI
π₯ youtube.com/watch?v=r5Iy3v1co0A
π₯ youtu.be/qmnH5MT_luk
π₯ youtu.be/mrYMzpbFz18
Creative Works Featured:
π¨ Townscaper: townscapergame.com
π¨ unity-wave-function-collapse: selfsame.itch.io/unitywfc
π¨ Super Mario WFC: observablehq.com/@makio135/super-mario-wfc
π¨ Zelda WFC: observablehq.com/@makio135/zelda-wfc
π¨ Infinite procedurally generated city: marian42.de/article/wfc
Related Coding Challenges:
π youtu.be/HyK_Q5rrcr4
π youtu.be/uQZLzhrzEs4
π youtu.be/rI_y2GAlQFM
Timestamps:
0:00:00 Introduction
0:01:12 The Nature of Code book!
0:02:20 WFC Resources and References
0:08:19 Extracting tiles from a source image
0:21:30 Calculating adjacency rules for tiles
0:24:34 Checking for overlapping pixel colors
0:32:20 Debugging tile adjacencies
0:43:30 Creating a Cell class
0:46:21 Incorporate code from WFC tile model
0:50:50 Reduce entropy of neighboring tiles
0:55:56 Rendering the center pixel for each tile
0:58:05 Cross checking valid tile options
1:01:57 Recursive entropy reduction
1:05:32 Limit recursion depth
1:06:32 Challenge complete?
1:08:26 Bugs found between Day 1 and Day 2
1:09:13 Starting Day 2
1:10:02 Correcting pixel color if statement
1:11:16 Refactoring redundant code
1:17:26 Running out of tile options
1:21:24 Optimizing the code
1:23:47 Rendering average pixel color of remaining tile options
1:26:23 How to handle redundant tiles?
1:28:30 More tiles with rotations and reflections
1:29:39 Additional performance optimizations
1:31:40 Thanks for watching!
Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound
π Website: thecodingtrain.com
πΎ Share Your Creation! thecodingtrain.com/guides/passenger-showcase-guide
π© Suggest Topics: github.com/CodingTrain/Suggestion-Box
π‘ GitHub: github.com/CodingTrain
π¬ Discord: thecodingtrain.com/discord
π Membership: youtube.com/thecodingtrain/join
π Store: standard.tv/codingtrain
ποΈ Twitter: twitter.com/thecodingtrain
πΈ Instagram: instagram.com/the.coding.train
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
π p5.js: p5js.org
π p5.js Web Editor: editor.p5js.org
π Processing: processing.org
π Code of Conduct: github.com/CodingTrain/Code-of-Conduct
This description was auto-generated. If you see a problem, please open an issue: github.com/CodingTrain/thecodingtrain.com/issues/new
#wavefunctioncollapse #overlappingmodel #proceduralgeneration #p5js #javascript







![Coding Train Live: Riding the Oregon Trail 2
π‘Sign up for the CuriosityStream + Nebula bundle with a 26% exclusive discount ($14.79 for a full year!) at https://curiositystream.com/choochoo. To access my Nebula class, upgrade for $1 per month or $10 for year!
Launching my next project, a p5.js port of the original Apple ][ Oregon Trail game!
π» https://github.com/CodingTrain/Oregon-Trail
Timestamps:
0:00 Waiting to start
6:28 Welcome to a pop-up episode of the Coding Train Live!
18:37 Curiosity Stream
21:39 Discord Help forum
52:44 Start working on Oregon Trail sketch
1:01:30 Create a game.json file to store the meta data for the game
1:40:28 Rob & Akiva podcast
1:42:10 Add issues to GitHub repo
1:46:05 Invite link to Coding Train Discord
1:48:00 Nebula
2:00:00 Bye everyone
Links:
π Rob & Akiva podcast https://www.podcastone.com/episode/Rob Akiva-Need-a-Podcast-The-Oregon-Trail
π Website: http://thecodingtrain.com/
πΎ Share Your Creation! https://thecodingtrain.com/guides/passenger-showcase-guide
π© Suggest Topics: https://github.com/CodingTrain/Suggestion-Box
π‘ GitHub: https://github.com/CodingTrain
π¬ Discord: https://discord.gg/hPuGy2g
π Membership: http://youtube.com/thecodingtrain/join
π Store: https://standard.tv/codingtrain
ποΈ Twitter: https://twitter.com/thecodingtrain
πΈ Instagram: https://www.instagram.com/the.coding.train/
π₯ Coding Challenges: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
π₯ Intro to Programming: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6Zy51Q-x9tMWIv9cueOFTFA
π p5.js: https://p5js.org
π p5.js Web Editor: https://editor.p5js.org/
π Processing: https://processing.org
π Code of Conduct: https://github.com/CodingTrain/Code-of-Conduct
#p5js #oregontrail #game Coding Train Live: Riding the Oregon Trail 2](https://i.ytimg.com/vi/7quQVO_K6Gg/mqdefault.jpg)


