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?
alwynd mentioned Perlin noise. Here's how I generated the island shapes for the polygon map generator:
- Generate perlin noise.
- 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).
(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.
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.
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.