83
22
Challenge
Write a program that takes an 11x11 array of integers, and constructs a 3D ASCII block building, where each value in the array represents the height of a column of blocks at the coordinates matching the array position. A negative height is a "floating" column - only the top block is visible.
Example
__________________
___ /\__\__\__\__\__\__\
3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /\__\ /\/\__\__\__\__\__\__\
2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /\/__/ /\/\/__/__/__/__/__/__/
2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /\/\__\ /\/\/\__\ /\/\/__/
1, 0, 0, 7,-7,-7,-7,-7, 7, 0, 0, \/\/\__\ /\/\/\/__/ /\/\/__/
0, 0, 0, 7,-7,-7,-7,-7, 7, 0, 0, \/\/__/ /\/\/\/\__\ /\/\/__/
0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, \/\__\ /\/\/\/\/__/ /\/\/__/
0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 0, \/__/ \/\/\/\/\__\_ \/\/__/
1, 0, 0, 4, 3, 2, 1, 0, 0, 0, 1, \/\/\/\/__/_\_ \/__/
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, ___ \/\/\/__/__/_\_ ___
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, /\__\ \/\/__/__/__/_\ /\__\
1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, \/\__\ \/__/__/__/__/ \/\__\
\/\__\_________ ______\/\__\
\/\__\__\__\__\ /\__\__\__\__\
\/__/__/__/__/ \/__/__/__/__/
Input
The input will be a list of 121 integers, either read from stdin (choice of separator is up to you), or passed in as an array (can be 1D or 2D).
Heights will be in the range -11 to 11.
Output
The generated building can be written to stdout, displayed directly on the screen, or returned as a newline-separated string.
Leading and trailing whitespace is allowed.
Building Rules
The shape of an individual 3D block looks like this:
___
/\__\
\/__/
And a 2x2x2 cube of blocks looks like this:
______
/\__\__\
/\/\__\__\
\/\/__/__/
\/__/__/
When blocks overlap, a higher block takes precedence over a lower one, blocks in front take precedence over those further back, and blocks to the left takes precedence over those to the right. The only special case is that the top line of a block should never overwrite any non-space character behind it.
The interpretation of column heights can best be explained by looking at a 2D representation from the side.
HEIGHT: 1 2 3 -3 -2 -1
__ __
__ |__| |__| __
__ |__| |__| |__| __
|__| |__| |__| |__|
Test Cases
If you want to try out your solution on a few more inputs, I've put together a couple of test cases here.
Winning
This is code-golf, so the shortest submission (in bytes) wins.
9Ohh boy, get ready for 300+ byte solutions. Good challenge. +1 – totallyhuman – 2018-01-12T20:11:13.723
7@totallyhuman Nah, Dennis is going to have a 9-byte solution for this in 20 minutes. – Deacon – 2018-01-12T20:50:46.763
3Does the perspective have to be as shown with the bottom left of the input data in the foreground? The fact that this is not the first or last element of data makes it harder. Is it acceptable to either 1. keep the mapping as is and draw output with the bottom right column in the foreground or 2. draw a mirror image or 90 deg rotation of the data? Either of these would make the last data element correspond with the column in the foreground, which would be easier. – Level River St – 2018-01-12T21:41:17.137
3I feel inclined to use a real game engine (or part of it) to render a photo and convert it to ASCII – Stan Strum – 2018-01-12T22:16:52.883
@LevelRiverSt That seems like a reasonable request - you can choose the order of the 121 input elements to be whatever makes the most sense for your solution, as long as your ordering is consistent. It must be possible to produce every kind of layout that can be produced with the default order. – James Holderness – 2018-01-12T22:24:29.360
related – flawr – 2018-01-13T22:17:55.380
This reminds me of Snake Rattle 'n' Roll
– QBrute – 2018-01-14T17:35:32.487@QBrute That's exactly the kind of thing I had in mind when I came up with this challenge. In my day, though, it was Knight Lore and Alien 8 that popularised the isometric style.
– James Holderness – 2018-01-14T19:17:47.680