# Procedural Square World Generation Example

P

#### Puhloo

##### Guest
GM Version: GM:Studio (Works on Legacy GM)
Target Platform: All
Download: .gmz file , .exe demo

Summary:
This is basically an example which shows how a world is generated using the diamond square algorithm/method. You can also easily apply this to your own game by simply taking the script!

Tutorial:
So what is diamond square algorithm? Also known as random midpoint displacement fractal, it is a method for randomly generating heightmaps for computer graphics. The diamond-square algorithm starts with a 2D grid then randomly generates terrain height from four seed values arranged in a grid of points so that the entire plane is covered in squares. (Taken from Wikipedia)

The example itself shows how a world is generated using 3 differently generated maps to create a biome somehow is based on this graph that I found in stackexchange:

As for the mountains and water, it is all based in elevation. Basically there are 3 grids that are combined to generate a biome map like below. (Humidity, Temperature, & Elevation)

A 640 x 640 map. Each pixel is a biome.

If you play the .gmz file or open the demo, you can press SPACE to restart the room and press Z to zoom in at the pointed area.

#### RujiK

##### Member
Pretty cool! I would recommend seeding the temperature noise so the top (or somewhere) is colder than the bottom for more realistic biome distribution. Here is one I made a long time ago also using midpoint displacement:

Snow is at the top, jungle at the bottom. (Code was a complete mess though. Broke with a GMS update.)

P

#### Puhloo

##### Guest
Pretty cool! I would recommend seeding the temperature noise so the top (or somewhere) is colder than the bottom for more realistic biome distribution. Here is one I made a long time ago also using midpoint displacement:

Snow is at the top, jungle at the bottom. (Code was a complete mess though. Broke with a GMS update.)
Yeah I actually considered seeding the temperature noise but since it's just an example, well why bother? Thanks for stating that though!

O

#### OhGoodShepherd

##### Guest
Thanks for this example. I enjoyed seeing how it works and am experimenting with it now. I have a collection of world generation, chunk, noise and related tutorials though am having terrible trouble learning how to go from world generation to something like a top down exploration game... I'll keep poking away but if anyone has any suggestions for tutorials on where to go next from something like this - I'd love to see!

Thanks again!

#### gnysek

##### Member
Two additions should be that temperatures are based on Latitude, and it would be good if result is seamless, so you can infinity scroll.

Y

#### yokun51

##### Guest
I don't know if someone will reply me, but I want to know how to use this procedural generation to create a level. Like replacing all pixel with an instance, blue pixel with a water bloc of 32x32 pixel, green pixel with a grass bloc of 32x32 pixel, etc. If someone can help me with that it could be awesom.

#### Simon Gust

##### Member
I don't know if someone will reply me, but I want to know how to use this procedural generation to create a level. Like replacing all pixel with an instance, blue pixel with a water bloc of 32x32 pixel, green pixel with a grass bloc of 32x32 pixel, etc. If someone can help me with that it could be awesom.
For a System like this you just shouldn't use instances at all, your computer cannot handle that.

D

Woah

#### whale_cancer

##### Member
I've implemented this on a small scale (where N is never higher than 4). It seems that the corners and edges always look weird? That is to say, they show more variance than the middle of the map. What am I missing? Is it not possible to use this on such a small scale?

Six examples. Corners are set semi-randomly. The darker colors are deeper. The final colors are determined by integers, while the actual generated values are real numbers (is that my problem?)

Edit: Just read this on the wiki "...who described it as flawed because the algorithm produces noticeable vertical and horizontal "creases" due to the most significant perturbation taking place in a rectangular grid." I guess I can just discard the edges and keep the middle, then?

Last edited:
Y

#### yokun51

##### Guest
For a System like this you just shouldn't use instances at all, your computer cannot handle that.
What can we use instead of instances?

#### Simon Gust

##### Member
What can we use instead of instances?
Depends on what you need. You can go with tiles if it isn´t too many or grids like ds_grid or a 2D array.

Y

#### yokun51

##### Guest
Depends on what you need. You can go with tiles if it isn´t too many or grids like ds_grid or a 2D array.
If I use a grid, how can I draw all my sprite? And for now I want to use tile, but I dont know if it will be efficient if I have a huge world

#### Simon Gust

##### Member
If I use a grid, how can I draw all my sprite? And for now I want to use tile, but I dont know if it will be efficient if I have a huge world
Here is a good resource that will get you started in this whole proceedual thing.

Y

#### yokun51

##### Guest
Here is a good resource that will get you started in this whole proceedual thing.
Thanks you a lot I will watch that for sure.