Jump to content


Photo
- - - - -

World Generation Example (Diamond-Square Algorithm)


  • Please log in to reply
3 replies to this topic

#1 Puhloo

Puhloo

    Intense Bleeding

  • GMC Member
  • 24 posts
  • Version:GM:Studio

Posted 19 March 2016 - 05:52 AM

  • Title:  World Generation Example (Diamond-Square Algorithm)
  • Description: This example displays how a world is generated using diamond-square algorithm
  • GM Version: Studio
  • Registered: No
  • File Type: .zip
  • File Size:  44.66 KB
  • File LinkDropbox Link
  • Required Extension: None
  • Required DLL: None
  • Tags: example, diamond, square, algoritm, random, generation, world, terrain

Summary:

This is a world generation example using the Diamond-Square algorithm. What is Diamond-Square? According to Wikipedia, The diamond-square algorithm is a method for generating heightmaps for computer graphics. But it isn't actually just for computer graphics, it can also be used for randomly generating worlds just like this one below!

 

JVscm9d.png

This image has a total of 410881 pixels and each pixel is an area type.


  • 3

#2 chance

chance

    GMC Member

  • Global Moderators
  • 8762 posts
  • Version:GM:Studio

Posted 19 March 2016 - 11:21 AM

This is a neat example.  The landscapes look good.   I might use this technique for generating heightmaps for my 3D landscapes. 

 

Your code looks fine.  And the wiki link you provided was useful.  So intermediate level programmers should be able to follow this fairly easily.   It's a good example of ds_grids and use of accessors.  And you could use this technique with normal arrays as well.

 

My only objection is how you draw the resulting landscape in the DRAW event.  It's not very efficient to loop through the entire grid, and assign the color values in every draw step.  It would make more sense to calculate a "color map" once, and then draw the landscape using draw_point_colour(i,j,color_map[i,j]).  You could avoid all the IF statements in every DRAW cycle.  Better yet, draw it once onto a surface.

 

But that's just a nitpick.  It's not really part of your tutorial anyway.  And users can easily make their own color maps.


  • 0

#3 Puhloo

Puhloo

    Intense Bleeding

  • GMC Member
  • 24 posts
  • Version:GM:Studio

Posted 20 March 2016 - 11:00 AM

This is a neat example.  The landscapes look good.   I might use this technique for generating heightmaps for my 3D landscapes. 

 

Your code looks fine.  And the wiki link you provided was useful.  So intermediate level programmers should be able to follow this fairly easily.   It's a good example of ds_grids and use of accessors.  And you could use this technique with normal arrays as well.

 

My only objection is how you draw the resulting landscape in the DRAW event.  It's not very efficient to loop through the entire grid, and assign the color values in every draw step.  It would make more sense to calculate a "color map" once, and then draw the landscape using draw_point_colour(i,j,color_map[i,j]).  You could avoid all the IF statements in every DRAW cycle.  Better yet, draw it once onto a surface.

 

But that's just a nitpick.  It's not really part of your tutorial anyway.  And users can easily make their own color maps.

 

Thanks for accepting the example! Well about how it's drawn, yeah I know that it is indeed not efficient it's just there to showcase what it can do. Users are to focus on the ds_grid.

 

EDIT: Forgot to mention the map warps on both horizontal and vertical ways.


Edited by Puhloo, 20 March 2016 - 11:05 AM.

  • 0

#4 RujiK

RujiK

    GMC Member

  • GMC Member
  • 841 posts
  • Version:GM:Studio

Posted 24 March 2016 - 01:48 PM

Woah! It wraps? Really cool! I made a midpoint displacement script awhile back, but it was very sloppily coded and didn't wrap. This is cooler.

 

 

This was my result if your interested. Although in this example I was testing extreme cases for river generation, the rest looks relatively similar to yours. I think this took about 20 seconds of completely frozenness to generate.

 

rujterrain8_zpsgmzldycr.png


  • 0