#P3326. 3D Block Projection
3D Block Projection
3D Block Projection
Little Obayashi is an imaginative kid who likes to present interesting stereoscopic views of stacked cubes. He has an m×n rectangular grid, where in each of the m×n cells a certain number of unit cubes (of side length 1) are stacked. Under a special lighting condition – where parallel light beams of one of the three primary colors (R, G, or B) come from one of nine prescribed directions (with incident angles in the x–y plane being multiples of 45° and the angle with the z–axis being 45°, 0°, or 315°) – each visible face of a cube is subdivided into 12 small triangles. When two beams overlap on a triangle, the resulting color is one of Cyan, Yellow, or Purple (represented by C, Y, and P respectively); with three beams the color becomes white (W).
For presentation purposes, each cube is drawn with a fixed ASCII art pattern (without any rotations or reflections) given below. Although the internal details of light‐mixing are complex, your task is simply to print the final isometric projection of the stacked cubes on the plane by overlaying the ASCII art of each cube in the correct order.
The fixed pattern for each cube is (6 rows × 7 columns):
+---+ / /| +---+ | | | + | |/ +---+
The cubes should be drawn in the proper order so that cubes in the front obscure those behind. For a cube located in row i and column j (with i=0 being the top row and j=0 the leftmost column) and at level h (0-based from the bottom), its topmost character (i.e. the upper‐left corner of its drawing pattern) should be placed at canvas coordinates:
Because some cubes may have negative row coordinates, you must shift the entire drawing downwards so that the topmost row is row 0. When overlaying two cubes, non–space characters in the cube pattern overwrite what was drawn previously. Finally, trim any trailing spaces at the end of each line before printing.
Input
The first line contains two positive integers m and n. Each of the next m lines contains n non–negative integers. The integer in the i–th row and j–th column indicates the number of cubes stacked in that cell.
Output
Print the final isometric projection of the cubes as described.
inputFormat
The input begins with two integers m and n (1 ≤ m, n ≤ 50). The following m lines each contain n non–negative integers (each ≤ 50), representing the number of cubes in that cell. The cell in the first line corresponds to the top row of the grid.
outputFormat
Output the rendered projection as a multi–line ASCII drawing. Make sure to trim trailing spaces at the end of each line.
sample
1 1
1
+---+
/ /|
+---+ |
| | +
| |/
+---+
</p>