# Wave function collapse (random tilemap generation)

**URL:** https://forum.makecode.com/t/wave-function-collapse-random-tilemap-generation/27516
**Category:** Game Design
**Tags:** make, demo, graphics-and-math, game
**Created:** [March 5, 2024, 9:53pm UTC](https://forum.makecode.com/t/wave-function-collapse-random-tilemap-generation/27516 "2024-03-05T21:53:32Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Luke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/luke/32/32519_2.png) [@Luke](https://forum.makecode.com/u/Luke)
#### Post date: [March 5, 2024, 9:53pm UTC](https://forum.makecode.com/t/wave-function-collapse-random-tilemap-generation/27516/1 "2024-03-05T21:53:32Z")

</div>

> **[Wave Function Collapse](https://arcade.makecode.com/S48754-69575-79358-24537)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

10 random tiles are generated at the start (these are the seed tiles)  
A sprite is moved randomly about empty areas. (I have 4 to speed things up)  
It looks at neighbouring and diagonal tiles and places tiles at it’s location if it sees a tile.  
The tile placement rules are too long to explain, they’re in the code if you’re interested.

After 4 seconds, the tiles are all filled so no more generation  
But there a still a bunch of mistakes so 2 more sprites go to clean up the sand tile placement.  
Feel free to mess about with the code, try larger and smaller tilemaps and see if you can make some better tile generation code lol

> **Read me if you want to edit the code**
>
> This function should be adjusted to follow the dimensions of the tilemap  
> ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/4de34f732972b8a94547ae66dd6cccafa8aa74f5.png)  
> ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/a/a777919b5289890531fb517c572ec61906176a5a.png)  
> Change the repeat number to adjust the number of seed tiles
> 
> ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/8/838a2bab86545ab3013f2bb735e4481f113efbde.png)  
> Change the frequency of the seed tiles by adjusting the array after the dark blue tile (keep order from 0-4 in the array)  
> ![image](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/4/420bd4b2a4343e46b6f00639af6cace528e3d52e.png)  
> What number corresponds to what tile for the _set tile_ and _if tile next to_ functions

---

<div class="post-metadata">

### Author: ![Luke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/luke/32/32519_2.png) [@Luke](https://forum.makecode.com/u/Luke)
#### Post date: [March 5, 2024, 11:45pm UTC](https://forum.makecode.com/t/wave-function-collapse-random-tilemap-generation/27516/2 "2024-03-05T23:45:01Z")

</div>

New update!  
(update in original link)  
Customisable map sizes, sprite number and starting tiles  
Pressing B opens the options menu  
Press A in the menu to edit selected value  
To start, fill in all the values  
Menu button gives the option to reset settings

---

<div class="post-metadata">

### Author: ![randomuser](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/randomuser/32/32505_2.png) [@randomuser](https://forum.makecode.com/u/randomuser)
#### Post date: [March 6, 2024, 2:02am UTC](https://forum.makecode.com/t/wave-function-collapse-random-tilemap-generation/27516/3 "2024-03-06T02:02:38Z")

</div>

I uh, don’t know what a wave function collapse is… What’s happening here?

---

<div class="post-metadata">

### Author: ![DA\_PRO\_PLAYZ](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/da_pro_playz/32/19214_2.png) [@DA\_PRO\_PLAYZ](https://forum.makecode.com/u/DA_PRO_PLAYZ)
#### Post date: [May 23, 2024, 4:51pm UTC](https://forum.makecode.com/t/wave-function-collapse-random-tilemap-generation/27516/4 "2024-05-23T16:51:23Z")

</div>

wow, this is really cool! can you maybe make the menu normal-sized?

---

<div class="post-metadata">

### Author: ![Luke](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/luke/32/32519_2.png) [@Luke](https://forum.makecode.com/u/Luke)
#### Post date: [May 23, 2024, 5:21pm UTC](https://forum.makecode.com/t/wave-function-collapse-random-tilemap-generation/27516/5 "2024-05-23T17:21:22Z")

</div>

unfortunately the mini menu extension can’t handle larger font sizes (pretty sure)

---

<div class="post-metadata">

### Author: ![DA\_PRO\_PLAYZ](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/da_pro_playz/32/19214_2.png) [@DA\_PRO\_PLAYZ](https://forum.makecode.com/u/DA_PRO_PLAYZ)
#### Post date: [May 23, 2024, 9:11pm UTC](https://forum.makecode.com/t/wave-function-collapse-random-tilemap-generation/27516/6 "2024-05-23T21:11:46Z")

</div>

ok, thanks anyway.
