MENU

Fun & Interesting

Coding Challenge 171: Wave Function Collapse

The Coding Train 576,428 3 years ago
Video Not Working? Fix It Now

Straight out of quantum mechanics, Wave Function Collapse is an algorithm for procedural generation of images. 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. Also, check out WFC's predecessor: Model Synthesis (more info below). Code: https://thecodingtrain.com/challenges/171-wave-function-collapse ๐Ÿš€ Watch this video ad-free on Nebula https://nebula.tv/videos/codingtrain-coding-challenge-171-wave-function-collapse ๐Ÿ’ป Github Repo: https://github.com/CodingTrain/Wave-Function-Collapse ๐Ÿ•น๏ธ p5.js Web Editor Sketch: https://editor.p5js.org/codingtrain/sketches/_kbz6Xq7l ๐ŸŽฅ Previous: https://youtu.be/0zac-cDzJwA?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH ๐ŸŽฅ Next: https://youtu.be/FfCBNL6lWK0?list=PLRqwX-V7Uu6ZiZxtDDRCi6uhfTH4FilpH ๐ŸŽฅ All: 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 ๐Ÿ—„ Model Synthesis: https://paulmerrell.org/model-synthesis/ ๐Ÿ“ฃ โ€‹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 ๐Ÿš‚ Matrix Transformations: https://thecodingtrain.com/tracks/transformations-in-p5 ๐ŸŽฅ Oskar Stalberg - Wave Function Collapse in Bad North: https://youtu.be/0bcZb-SsnrA Related Coding Challenges: ๐Ÿš‚ 10 Maze Generator: https://youtu.be/HyK_Q5rrcr4 ๐Ÿš‚ 162 Self Avoiding Walk: https://youtu.be/m6-cm6GZ1iw ๐Ÿš‚ 165 Slide Puzzle: https://youtu.be/uQZLzhrzEs4 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 asymmetry 1:12:06 First asymmetric 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 ๐Ÿš‚ Website: https://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://thecodingtrain.com/discord ๐Ÿ’– 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 This description was auto-generated. If you see a problem, please open an issue: https://github.com/CodingTrain/thecodingtrain.com/issues/new #wavefunctioncollapse #generativeart #p5js #javascript

Comment