Coding Challenge 171: Wave Function Collapse

Subscribers:
1,740,000
Published on ● Video Link: https://www.youtube.com/watch?v=rI_y2GAlQFM



Duration: 1:18:37
423,519 views
13,113


Straight out of quantum mechanics, Wave Function Collapse is an algorithm for procedural generation of images. https://thecodingtrain.com/challenges/171-wave-function-collapse

In this video (recorded over 3 live streams) I attempt the tiled model and explore a variety of solutions to the algorithm in JavaScript with p5.js.

πŸ’» Github Repo: https://github.com/CodingTrain/Wave-Function-Collapse
πŸ•ΉοΈ p5.js Web Editor Sketch: https://editor.p5js.org/codingtrain/sketches/_kbz6Xq7l

πŸŽ₯ Previous video: https://www.youtube.com/watch?v=0zac-cDzJwA&list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH
πŸŽ₯ All videos: https://www.youtube.com/playlist?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH

References:
πŸ’‘ WFC Challenge Suggestion: https://github.com/CodingTrain/Suggestion-Box/issues/287
πŸ—„ Wave Function Collapse Algorithm: https://github.com/mxgmn/WaveFunctionCollapse
πŸ“£ Wave Collapse Function algorithm in Processing: https://discourse.processing.org/t/wave-collapse-function-algorithm-in-processing/12983
πŸ—„ Array.prototype.filter(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/filter
🐞 Encoding tiles symmetry and rotation #14: https://github.com/CodingTrain/Wave-Function-Collapse/issues/14
🐞 The issue with asymmetric tiles and an easy solution #16: https://github.com/CodingTrain/Wave-Function-Collapse/issues/16
πŸ—„ Array.prototype.reverse(): https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse

Creative Works Featured:
🎨 Oisín: Wave Function Collapse for poetry: https://github.com/mewo2/oisin
🎨 Townscaper: https://www.townscapergame.com/
🎨 unity-wave-function-collapse: https://selfsame.itch.io/unitywfc
🎨 Zelda WFC: https://observablehq.com/@makio135/zelda-wfc
🎨 Wave Function Collapse Demonstration: https://oskarstalberg.com/game/wave/wave.html
🎨 Infinite procedurally generated city: https://marian42.de/article/wfc/
🎨 Generating stairy scenes: https://twitter.com/exutumno/status/895683455299723265?lang=eu

Live Stream Archives:
πŸ”΄ Day 1: https://youtu.be/6Vag7NJUjJo
πŸ”΄ Day 2: https://youtu.be/FGmB5ZHhhiA
πŸ”΄ Day 3: https://youtu.be/QvoTSl60Y88

Videos:
πŸŽ₯ Solving Wordle with Information Theory: https://youtu.be/v68zYyaEmEA
πŸŽ₯ Pixel Array: https://youtu.be/nMUMZ5YRxHI
πŸŽ₯ Arrow Function: https://youtu.be/mrYMzpbFz18
πŸŽ₯ Higher Order Array Functions: https://youtu.be/H4awPsyugS0
πŸŽ₯ Transformations in p5.js: https://youtu.be/o9sgjuh-CBM
πŸŽ₯ Oskar Stalberg - Wave Function Collapse in Bad North: https://youtu.be/0bcZb-SsnrA

Timestamps:
0:00 Day 1! Wave Function Collapse!
2:00 Entropy in Sudoku.
5:41 Comparing Sudoku to WFC
9:24 Starting to code.
11:05 Collapsing cells.
13:30 Evaluating entropy.
18:47 Updating entropy after collapse.
22:45 Data structure for rules.
24:50 Implementing rules for next collapse.
36:28 Explaining the rules.
38:45 Day 2! Refactoring the code.
39:26 Create a Tile class
44:57 Generate the rules from Tile objects.
55:40 Using new circuit board tileset.
1:00:40 Day 3! Dealing with asymmetrical tiles
1:01:56 Assigning index values to edges.
1:06:53 Incorporating edges into code.
1:10:05 Change adjacency for assymetry
1:12:06 First assymetric WFC image!
1:12:40 Restart if no valid cell found.
1:15:48 Next steps!
1:18:05 Thanks for watching!

Editing by Mathieu Blanchette
Animations by Jason Heglund
Music from Epidemic Sound
Trailer by https://twitter.com/bernizeck

πŸš‚ 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
πŸ“š Books: https://www.amazon.com/shop/thecodingtrain
πŸ–‹οΈ 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

This description was auto-generated. If you see a problem, please open an issue: https://github.com/CodingTrain/thecodingtrain.com/issues/new