Wednesday, April 25, 2018

Back In the Woods (Part 3): Tree Shapes

In the previous posting, I developed a basic approach to generating a roughly circular tree shape, as in these examples:
Circular tree shapes are not uncommon on fantasy maps:
However, even for deciduous trees many maps have more varied shapes, as in these icons taken from historical maps:
There's quite some variety across different maps, but one common shape is like a clump of fluffy balls (rather than just one).  Sometimes these are merged together into one shape, and sometimes they remain separate -- this is more obvious when the clumps are shaded (as in the fourth tree in the top row).  So let's see about implementing that.

To start with, I'll just generate a tree as overlapping smaller tree shapes.  Here's an initial attempt:
That's not really what I was imagining; the circles need to be smaller and more offset from each other.  But in a Bob Ross “happy accident" way, that actually looks interesting at map scale:
which is something to keep in mind.  Let me fill the clumps with white and reduce the size and increase the offset.
This is a little closer to what I'm imagining.  Some of the shapes (like the lowest leftmost one in the array) seem pretty good.  But many of them are too overlapping.  Right now I'm just randomly offsetting them from the center point, but often that doesn't move them far.  I can try adding a minimum offset.
That's a little better, but there are still lots of shapes that are too clumped and a lot of shapes that don't really look like trees.

In reality, trees aren't random shapes.  They're never bigger on the top than the bottom, or diagonal, for example.  (Well, maybe not *never* but rarely.)  After playing around a bit, I came up with this:
I'm basically stacking the clumps up in a rough pyramid.  The logic for this isn't very good, and probably wouldn't work for more than 3 clumps.  But I suspect that 3 clumps will be more than enough for this icons, so I'm going to use this until I need something better.

Drawing the clumps individually like this doesn't look much like a tree.  It looks more like a tree if I just draw the outline:
I've drawn in the clump outlines faintly so you can still see the structure of the trees, and to give a faint indication of shading.  Not every one of these looks perfect, but at map scale most look pretty good.

One drawback of this approach is that it's pretty slow.  Taking the union of two polygons (which I have to do twice on each 3 clump tree to get the outline) is expensive.

Now that I can generate a basic tree shape, I can try it out on a map.  Without tree trunks, this looks more like a top-down view of the trees.  You occasionally see maps done in this style, using many individual tree shapes to create a forest mass:
The colors are a bit bright for this map, but otherwise it looks pretty good.  You'll note that rivers are being obscured.  Right now this is using the river avoidance distance used by the forest mass style forests; they can come up much closer to the rivers without overlapping.  This method will require a greater avoidance distance.

Next time I'll look at adding trunks.

No comments:

Post a Comment