This is a CC-BY-SA challenge from the CCSC Mid-South Programming Contest 2018.
Author(s): Brent Yorgey
Source: Consortium for Computing Sciences in Colleges Mid-South Programming contest 2018
Good news: you have been hired to do all the special effects for a film! One of the scenes will take place outside, on a windswept plain with a towering mountain range in the background. Your job is to turn a description of the mountain range into a rendered image.
The bad news: the film’s producers have an extremely small budget, and so they can’t afford luxuries like rendered 3D graphics made up of pixels. Hence, you will be making your image out of ASCII characters.
Write a function or full program to produce mountain range ASCII art according to the spec below. This is code-golf; tie breaker is earlier submission.
You will receive a list of 5-tuples in any standard input format for PPCG and/or your language. Each 5-tuple is the values (x, h, z, t, s) representing one mountain of the range you will draw.
- x is the x-coordinate of the mountain's peak, with 1≤x≤199.
- h is the height of the mountain, with 1≤h≤100.
- z indicates the relative distance of the mountain from the viewer, with 1≤z≤m. The smaller the value of z, the closer the mountain is to the viewer. Closer mountains hide ones that are farther away.
- t is the height of the treeline. The side of the mountain up to the treeline should be filled with trees, represented by the ASCII character
- s is the height of the snowline. The side of the mountain above the snowline should be filled with snow, represented by the ASCII character
The base of each mountain will not extend beyond 0 or 200 horizontally; you may assume that 0≤x−h and x+h≤200. The height of each mountain is no more than 100, so all mountains will fit within a 100x200 grid. The snow and trees will not overlap or exceed the height of the mountain; you may assume that 0≤t≤s≤h. All numbers are non-negative, and all z-values will be unique.
The output should consist of an ASCII drawing of the specified mountain range. Each mountain is triangular in shape with its sides drawn using
\ characters. For example, here is a mountain of height 4:
/\ / \ / \ / \
This mountain has x-coordinate 4, since the horizontal distance from the left margin to its peak is 4 units.
Trees and snow should fill the interior of the mountain but not obscure the sides of the mountain. For example, here is a mountain with height 6, treeline height 2, and snowline height 3:
/\ /**\ /****\ / \ /YYYYYYYY\ /YYYYYYYYYY\
That is, the trees extend from the base of the mountain up to a height of 2 units, and the snow starts at a height of 3 units and extends to the top of the mountain.
Mountains with a smaller z-coordinate may hide all or part of a mountain with a larger z-coordinate; see the third sample input/output below.
Leading whitespace is significant, and should be as specified by the x-position and width of the drawn mountains. Leading/trailing newlines are allowed, and any amount of spaces after each line.
(8, 5, 1, 2, 3)
/\ /**\ / \ /YYYYYY\ /YYYYYYYY\
(2, 2, 1, 0, 1)
/\ / \
(8, 5, 2, 2, 3), (2, 2, 1, 0, 1), (9, 8, 3, 1, 4), (17, 4, 4, 4, 4)
/\ /**\ /****\ /*/\***\ / /**\ \ /\ / / \ \/YY\ /\ /YYYYYY\ \YYY\ / \YYYYYYYY\YYY\YYY\
If you find other interesting examples, please share in your answers!