1

In the programming of my 2d sandbox game, I decided to add a procedural generation engine to generate terrain. The way I have decided to implement it is by using the diamond square algorithm to generate values, then based on the values I will derive the matching terrain (each terrain has a range where it can generate. The only example I could find for the algorithm (found here) requires an odd grid size (i.e. 17 x 17, not 16 x 16) to generate. I understand why and was wondering if I should use a different algorithm, or if there was a way to make it work with this algorithm.

Community
  • 1
  • 1
  • The algorithm is usually explained in terms of 2^n x 2^n grids. But you can always compute the next larger size that's 2^n and use a subset. What's the problem? – Gene Aug 18 '15 at 00:54

1 Answers1

1

With numbers on a a 17x17 grid, you could just take the average of the 4 corners of each small square to get a number for the square. E.g., with 3x3 instead of 17x17, say you have

3--2--1
|  |  |
4--3--1
|  |  |
5--4--2

That grid defines 4 small squares. The squares would have values

(3+2+4+3)/4=3.00  (2+1+3+1)/4=1.75
(4+3+5+4)/4=4.00  (3+1+4+2)/4=2.50

Same idea for 17x17 grid into 16x16 squares. Or am I not understanding?

Edward Doolittle
  • 4,002
  • 2
  • 14
  • 27