9
\$\begingroup\$

I have implemented functions that can draw any polygonal shape, however I have been unable to generate a smooth shape that mimics the rounded edges of a lake. I tried generating two circles and joining the edges but there is not enough variation or smoothness to it. Does anyone have any pointers or ideas that could generate a shape like this?

asked Jan 10, 2012 at 7:52
\$\endgroup\$
1
  • \$\begingroup\$ I've been looking into bezier curves, it appears that I might be able to generate a lake from that. Anyone have any experience with them on a 2d array? \$\endgroup\$ Commented Jan 11, 2012 at 6:18

3 Answers 3

8
\$\begingroup\$

alwynd mentioned Perlin noise. Here's how I generated the island shapes for the polygon map generator:

  1. Generate perlin noise.
  2. For each location (x, y) in the noise bitmap, compute the distance from the center, normalized so that the bitmap is 2x2: (dx, dy) = (2 * x / width - 1, 2 * y / height - 1); d = sqrt(dx*dx + dy*dy).
  3. Location (x, y) is part of the island if noise[x, y] > 0.3 + 0.4*d*d. This step attempts to make the shape round by cutting off areas that are far from the center.

Islands are a little more ragged than lakes though, so I'm not sure if these shapes will be to your liking. I've put up a demo of the above algorithm, with buttons at the bottom to control the two magic numbers. There might be different values of the magic numbers 0.3 and 0.4 that produce shapes you like.

answered Jan 10, 2012 at 18:59
\$\endgroup\$
1
  • 2
    \$\begingroup\$ Your work is a major inspiration, Amit. +10k if I could, for the 5 years or so of wonder and enjoyment I've gotten out of reading your blog. \$\endgroup\$ Commented Jan 10, 2012 at 19:09
4
\$\begingroup\$

You could use a Perlin Noise algorithm to generate the lakes for you, if you are using a top down view (polygon shape, sounds like you are), this guy from Stanford did just that.

http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/

answered Jan 10, 2012 at 11:43
\$\endgroup\$
2
  • 1
    \$\begingroup\$ "That guy from Stanford" is also a user on this site, FYI. \$\endgroup\$ Commented Jan 10, 2012 at 11:58
  • \$\begingroup\$ who isn't? =) I might start off from some noise (perlin, fractal), but blur the results for less "jaggy" results. Great article, btw - love how he does the rivers. \$\endgroup\$ Commented Jan 10, 2012 at 12:47
0
\$\begingroup\$

One way would be to start with a basic polygon, maybe your 2 circles approach.

Firstly offset all points randomly, so doesn't look too much like a circle, then for every edge, split it in 2 and offset the middle point by some small random amount. Keep doing this until you have the required detail.
This is similar to what's done when generating forks of lightning.

answered Jan 10, 2012 at 8:20
\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.