Tuesday, December 13, 2016

How to Decorate a Mountain, Part 2

In the previous post, I cleaned up the algorithm for drawing mountains a bit, and then I added some extra details / decorations to the drawings.  In this posting, I'm going to continue on with adding details.

Looking back at my hand-drawn samples for inspiration, I notice that one style features scribbles on the mountain face:
These scribbles suggest extra texture or features and help to break up the empty area of the mountain face.

One immediate challenge in adding scribbles is just finding a spot on the mountain face.  Just picking a random spot inside a polygon is non-trivial.  Fortunately I'm not too worried about performance, so I'm free to use inefficient but easier-to-implement algorithms.  My approach to finding a a random spot inside the face of the mountain is to construct a bounding box for the mountain face:
And then randomly select points within the bounding box until I get one that is also inside the mountain face.
This works but is not generally a recommended algorithm because it can take an indeterminate amount of time to find a point inside the polygon.  But in my case roughly 50% of the points are going to be inside the polygon, so I'm willing to take that risk.

(ADDENDUM:  After implementing this and using it for a while, I realized I was rarely starting scribbles up near the top of the mountain.  I didn't like that much, so I switched how I pick the starting point for a scribble.  Now, I draw a line from the peak of the mountain to a random spot on the right side of the mountain, like these examples:

Hey, maybe I should implement volcanoes...  Uh, anyway, I then pick a random spot on the line as a starting point for the scribble.  As it turns out, this fits in well with the next step.)

Now that I have a point, I want to identify the area where I'm going to draw the scribble.  To do this, I project a line from the peak down through the point and create a box where the scribble will fall.
Projecting a line down from the peak ensures that the box for the scribble will have the right slope for it's placement on the mountains -- if the scribble is near to the right side of the mountain it will be sloped about like the right side of the mountain; if it is near the center of the mountain it will be close to straight up and down.

Once I've established the box, I need to check to see if it goes outside the mountain or if it interferes with any of the existing decorations.  In the example above, it does both.  When this happens, I throw the box and the point away, generate a new starting point and try again.  (Again, this can take an indeterminate amount of time -- possibly forever if it isn't possible to position a scribble.  So the algorithm has to have a guard on it that gives up entirely after a few hundred attempts.)

If there isn't a problem, then I can draw the scribble.  To do the drawing, I'm using a different approach than with scribbling in the shaded side of the mountain.  In this case, I don't have to fully fill the area, and I also want this to look different than the shading.  So I'm just taking a line and perturbing it side-to-side.
Here are some more examples, with various size scribbles:
My intention is to use these face scribbles as an accent, but it turns out to look interesting if you put a lot of scribbles on each mountain:
And maybe even more interesting at map scale:
The scribbles give the mountains a "textured" look.  I'm not sure this is my favorite style, but in some ways it looks pretty good.

Another option I'd like to add is to have more flat-topped mountains.  Currently, every mountain starts off as an upside-down V.  Both sides do get perturbed, so occasionally that results in mountains with round or flat tops:
But I'd like to be able to intentionally generate mountains with flat tops.  Then (for example) I could have an area of the map with "old" mountains that are generally flattened, and another area with "new" mountains that are sharper.

To get flattened mountains, I need to insert a flat section between the two sides of the mountain.  Hopefully the perturbation and smooth line drawing routines should turn that into some interesting shapes.
The look of the mountains is also dependent on the curve algorithm I use to draw them, so I can relax that to get mountains that look more rounded.
In the next posting I'll talk about how I combine multiple mountains.

No comments:

Post a Comment