# Procedural terrain generation

**URL:** <https://forum.makecode.com/t/procedural-terrain-generation/10136>\
**Category:** Show & Tell\
**Tags:** graphics-and-math\
**Created:** [September 20, 2021, 3:59pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136 "2021-09-20T15:59:35Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![yoxd707](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yoxd707/32/8506_2.png) [@yoxd707](https://forum.makecode.com/u/yoxd707)\
**Post date:** [September 20, 2021, 3:59pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/1 "2021-09-20T15:59:35Z")

</div>

> **[Terrain2D](https://arcade.makecode.com/94402-93728-60346-73496)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

I leave you a procedural generation project done in a few hours, I am not going to continue modifying it but if someone comes up with how to optimize it a little more I would like you to tell me 😃

![terrain2d-1](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/f/f0d5b7ffbed66d24bcb145e16e403d69c083d9c2.png)

---

<div class="post-metadata">

**Author:** ![danger\_kitty](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/danger_kitty/32/32006_2.png) [@danger\_kitty](https://forum.makecode.com/u/danger_kitty)\
**Post date:** [September 20, 2021, 4:48pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/2 "2021-09-20T16:48:39Z")

</div>

Did you use any type of tile map

---

<div class="post-metadata">

**Author:** ![yoxd707](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yoxd707/32/8506_2.png) [@yoxd707](https://forum.makecode.com/u/yoxd707)\
**Post date:** [September 20, 2021, 6:18pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/3 "2021-09-20T18:18:41Z")

</div>

no, just use sprites, and the whole project is programmed in typescript.

---

<div class="post-metadata">

**Author:** ![Kiwiphoenix364](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kiwiphoenix364/32/14368_2.png) [@Kiwiphoenix364](https://forum.makecode.com/u/Kiwiphoenix364)\
**Post date:** [September 20, 2021, 8:01pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/4 "2021-09-20T20:01:04Z")

</div>

just wondering, how does this work(especially cave systems) and can this project use seeds?

---

<div class="post-metadata">

**Author:** ![yoxd707](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yoxd707/32/8506_2.png) [@yoxd707](https://forum.makecode.com/u/yoxd707)\
**Post date:** [September 21, 2021, 4:44am UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/5 "2021-09-21T04:44:26Z")

</div>

I am not going to explain how the perlin noise function works as it is complex, but I recommend looking for information on the subject.  
Summarizing my implementation of the function it returns a number between 0 and 1, for the surface I use perlin noise 1d and for the caves perlin noise 2d.  
In the terrain.ts file there is a variable called CAVES\_FREQ, which is used to know if an air block should be generated based on the value returned by the perlin noise 2d. If the value is greater than CAVES\_FREQ, stone is generated, otherwise air is generated.

And yes, the project internally uses seeds, it is also a variable from terrain.ts, although I did not set an option for the user to modify it, so the seed is random and its range is from -10000 to 10000.

```auto
// terrain.ts line 10
static readonly SEED = randint(-10000, 10000)

```

Although the seed is not used to generate the transition between stone and dirt, so every time you generate the same chunk, the transition between these blocks will be generated again at random.

---

<div class="post-metadata">

**Author:** ![yoxd707](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yoxd707/32/8506_2.png) [@yoxd707](https://forum.makecode.com/u/yoxd707)\
**Post date:** [September 21, 2021, 4:45am UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/6 "2021-09-21T04:45:10Z")

</div>

I just changed how the BlockPool class works, now around 1000 blocks are created on average, before it was around 1500, so the performance has increased and the initial load has been reduced. 😃

> **[Terrain2D](https://arcade.makecode.com/22902-49230-42519-94813)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![Kiwiphoenix364](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/kiwiphoenix364/32/14368_2.png) [@Kiwiphoenix364](https://forum.makecode.com/u/Kiwiphoenix364)\
**Post date:** [September 21, 2021, 3:52pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/7 "2021-09-21T15:52:08Z")

</div>

I just realized, It seems like the chunks generate procedurally on the y axis, so you can go down forever! that’s cool! Minecraft doesn’t even do that

---

<div class="post-metadata">

**Author:** ![yoxd707](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yoxd707/32/8506_2.png) [@yoxd707](https://forum.makecode.com/u/yoxd707)\
**Post date:** [September 27, 2021, 3:30pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/8 "2021-09-27T15:30:09Z")

</div>

I rebuilt the project with some changes and performance may have improved, does it show?  
Now the blocks are Tiles, but I keep generation infinite 😉

> **[TerrainGenerator v0.01](https://arcade.makecode.com/18843-88989-30661-03228)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![Salex](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/salex/32/15835_2.png) [@Salex](https://forum.makecode.com/u/Salex)\
**Post date:** [October 31, 2022, 5:37pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/9 "2022-10-31T17:37:50Z")

</div>

i tried to make it so you couldn’t go through the blocks, and add physics, as if it were a game like terraria, but it didn’t work… could you try make something like that? pls

---

<div class="post-metadata">

**Author:** ![yoxd707](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yoxd707/32/8506_2.png) [@yoxd707](https://forum.makecode.com/u/yoxd707)\
**Post date:** [October 31, 2022, 8:42pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/10 "2022-10-31T20:42:49Z")

</div>

I’ll do it why not, but I’m in midterms so it’ll be in my spare time. And I don’t remember much of what I did on that project either, so I probably changed a few things.

---

<div class="post-metadata">

**Author:** ![Salex](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/salex/32/15835_2.png) [@Salex](https://forum.makecode.com/u/Salex)\
**Post date:** [November 1, 2022, 4:43pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/11 "2022-11-01T16:43:10Z")

</div>

k thanks, jut an idea for when you’re bored maybe

---

<div class="post-metadata">

**Author:** ![isoffline](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/isoffline/32/8791_2.png) [@isoffline](https://forum.makecode.com/u/isoffline)\
**Post date:** [November 1, 2022, 4:44pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/12 "2022-11-01T16:44:37Z")

</div>

Yo bro Welcome to the Forums

---

<div class="post-metadata">

**Author:** ![Salex](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/salex/32/15835_2.png) [@Salex](https://forum.makecode.com/u/Salex)\
**Post date:** [November 1, 2022, 5:47pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/13 "2022-11-01T17:47:00Z")

</div>

thanks

---

<div class="post-metadata">

**Author:** ![yoxd707](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yoxd707/32/8506_2.png) [@yoxd707](https://forum.makecode.com/u/yoxd707)\
**Post date:** [November 3, 2022, 11:57pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/14 "2022-11-03T23:57:14Z")

</div>

I’ve added the collisions, biomes and a map (although the map was actually used for debugging).  
I would need to add the caves and I want to do some optimizations.  
I would like to see your project when you have it ready 👍

> **[TerrainGenerator V0.02.1101](https://arcade.makecode.com/S76233-28274-51613-13994)**
>
> Made with ❤️ in Microsoft MakeCode Arcade.

---

<div class="post-metadata">

**Author:** ![Salex](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/salex/32/15835_2.png) [@Salex](https://forum.makecode.com/u/Salex)\
**Post date:** [November 5, 2022, 1:44am UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/15 "2022-11-05T01:44:03Z")

</div>

Thank you!

---

<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:54pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/16 "2024-05-23T16:54:17Z")

</div>

hi, will this run smoothly on an XTRON pro, and is the terrain infinite?

---

<div class="post-metadata">

**Author:** ![yoxd707](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yoxd707/32/8506_2.png) [@yoxd707](https://forum.makecode.com/u/yoxd707)\
**Post date:** [May 23, 2024, 5:21pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/17 "2024-05-23T17:21:16Z")

</div>

Hi, I’m not sure what hardware is required to run it. As for whether the terrain is infinite, it is, or at least as infinite as a number can be within the framework haha.

---

<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 28, 2024, 5:56pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/18 "2024-05-28T17:56:49Z")

</div>

on the most recent link, it is the same terrain every time…

---

<div class="post-metadata">

**Author:** ![yoxd707](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/yoxd707/32/8506_2.png) [@yoxd707](https://forum.makecode.com/u/yoxd707)\
**Post date:** [May 29, 2024, 2:52am UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/19 "2024-05-29T02:52:22Z")

</div>

I accidentally left the seed 9650 haha. You can enable randomness by uncommenting line 19 and commenting out line 20. Regards!

 ![Screenshot_20240528-182142](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/2X/7/7748669cef4362dd43f50ce770637516e51a1d84.png)

---

<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 29, 2024, 10:25pm UTC](https://forum.makecode.com/t/procedural-terrain-generation/10136/20 "2024-05-29T22:25:42Z")

</div>

that fixed it, thanks!

[Next page](https://forum.makecode.com/t/procedural-terrain-generation/10136.md?page=2)
