Coding Challenge 186: Wave Function Collapse

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



Duration: 0:00
69,175 views
2,541


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: https://thecodingtrain.com/challenges/186-wfc-overlapping-model

šŸš€ Watch this video ad-free on Nebula https://nebula.tv/videos/codingtrain-coding-challenge-186-wave-function-collapse

šŸ’» Github Repo: https://github.com/CodingTrain/Wave-Function-Collapse

p5.js Web Editor Sketches:
šŸ•¹ ļø Wave Function Collapse: Overlapping Model:https://editor.p5js.org/codingtrain/sketches/SI0c2D_tQ.
šŸ•¹ ļø WFC Overlapping Model Refactoredhttps://editor.p5js.org/codingtrain/sketches/2sV4KtcoD..
šŸ•¹ ļø WFC Overlapping Model: Shannon entrophttps://editor.p5js.org/codingtrain/sketches/PX0Hn6TF8...
šŸ•¹ ļø WFC Overlapping Model: More tilehttps://editor.p5js.org/codingtrain/sketches/z_N2TVjRHs...

šŸŽ„ Previous:    • CodingĀ ChallengeĀ 185:Ā UnfoldingĀ FractalsĀ Ā 
šŸŽ„ All:    • CodingĀ ChallengesĀ Ā 

References:
šŸ—„ Wave Function Collapse GitHub Rehttps://github.com/mxgmn/WaveFunctionCollapsen...
šŸ—„ Model Syntheshttps://paulmerrell.org/model-synthesis/sis/
šŸ—„ Procedural Generation with Wave Function Collaphttps://www.gridbugs.org/wave-function-collapse/o...
šŸ—„ Wave Function Collaphttps://github.com/CodingTrain/Wave-Function-CollapseF...
šŸ”— p5.js copyhttps://p5js.org/reference/p5/copy/opy/
šŸ”— p5.js web editor console log GitHub isshttps://github.com/processing/p5.js-web-editor/issues/3178w...
šŸ”— JavaScript concat() methhttps://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/concatd...
šŸ”— p5.js randomSeedhttps://p5js.org/reference/p5/randomSeed/S...

Videos:
šŸŽ„    • 11.3:Ā TheĀ PixelĀ ArrayĀ -Ā p5.jsĀ TutorialĀ Ā 
šŸŽ„    • GuestĀ TutorialĀ #6:Ā TheĀ ModuloĀ Operato...Ā Ā 
šŸŽ„    • 16.8:Ā ArrayĀ Functions:Ā filter()Ā -Ā Top...Ā Ā 
šŸŽ„    • 16.3:Ā ES6Ā ArrowĀ FunctionĀ -Ā TopicsĀ ofĀ ...Ā Ā 

Creative Works Featured:
šŸŽØ Townscaphttps://www.townscapergame.com/com/
šŸŽØ unity-wave-function-collaphttps://selfsame.itch.io/unitywfcywfc
šŸŽØ Super Mario Whttps://observablehq.com/@makio135/super-mario-wfcu...
šŸŽØ Zelda Whttps://observablehq.com/@makio135/zelda-wfce...
šŸŽØ Infinite procedurally generated cihttps://marian42.de/article/wfc/wfc/

Related Coding Challenges:
šŸš‚    • CodingĀ ChallengeĀ #10.1:Ā MazeĀ Generato...Ā Ā 
šŸš‚    • CodingĀ ChallengeĀ 165:Ā SlideĀ PuzzleĀ Ā 
šŸš‚    • CodingĀ ChallengeĀ 171:Ā WaveĀ FunctionĀ C...Ā Ā 

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

šŸš‚ Websihttps://thecodingtrain.com/com/
šŸ‘¾ Share Your Creatihttps://thecodingtrain.com/guides/passenger-showcase-guides...
🚩 Suggest Topihttps://github.com/CodingTrain/Suggestion-Boxs...
šŸ’” GitHhttps://github.com/CodingTrainrain
šŸ’¬ Discohttps://thecodingtrain.com/discordcord
šŸ’– Membershjoin
šŸ›’ Storhttps://standard.tv/codingtrainain
šŸ–‹ ļø Twitthttps://twitter.com/thecodingtraininĀ Ā 
šŸ“ø Instagrhttps://www.instagram.com/the.coding.train/inĀ Ā 

šŸŽ„    • CodingĀ ChallengesĀ Ā 
šŸŽ„    • StartĀ learningĀ here!Ā Ā 

šŸ”— p5.https://p5js.org/.org
šŸ”— p5.js Web Edithttps://editor.p5js.org/org/
šŸ”— Processihttps://processing.org/.org

šŸ“„ Code of Conduhttps://github.com/CodingTrain/Code-of-Conducto...

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

#wavefunctioncollapse #overlappingmodel #proceduralgeneration #p5js #javascript