Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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?

share|improve this question
    
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? –  Manderin87 Jan 11 '12 at 6:18
add comment

3 Answers

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.

share|improve this answer
add comment

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/

share|improve this answer
1  
"That guy from Stanford" is also a user on this site, FYI. –  Nick Wiggill Jan 10 '12 at 11:58
    
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. –  Jari Komppa Jan 10 '12 at 12:47
add comment

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.

share|improve this answer
1  
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. –  Nick Wiggill Jan 10 '12 at 19:09
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.