PowerShell v2+, 217 205 190 187 184 bytes
param($b)"_"*(($a=[math]::Abs($b))*4);$z,$y='/\'[($b=$b-lt0),!$b]
((($x=1..$a|%{($w=" "*($_-1))+$z+" "*(2*($a-$_))+$y+(' ','_')[$_-eq$a]*($a*2-1)+$y+$w})|%{-join$_[($a*4)..0]}),$x)[$b]
Takes input $b
as an integer. Note that if $b
is negative, you need to explicitly surround it with parens to cast it appropriately (see examples), else PowerShell will think it's a string.
Regardless of which direction the tent is facing, the first line is the same, a bunch of underscores; exactly 4*abs(input)
many of them, actually. That number is also stored into $a
for use later. Additionally, now that we have the absolute value of $b
stored into $a
, we turn $b
into a Boolean for its sign, and choose our slashes stored into $y
and $z
.
The next line is constructing and formulating the output, and it's a doozy, so let's break it down.
We're essentially indexing into an array of two elements, (big long calculations saved into $x)
or $x
, based on $b
.
The calculations are where the tent body is constructed. We loop from 1..$a|%{...}
. Each iteration we're constructing a line of the tent body. We start with a number of spaces equal to the line # we're on -1
, so that it's appropriately left-aligned. That's stored into $w
for later, and concatenated with the appropriate slash ($z, based on $b
), then the doorframe number of spaces, then the other slash $y
, then either underscores or spaces depending upon if we're on the bottom line or not, then another slash $y
, and finally the appropriate number of trailing spaces ($w
) to construct a rectangular string. That resulting array of strings is stored into $x
.
If the left half of the array is selected (i.e., $b
is False
since the input was positive), then we need to loop through $x
and reverse each line item -- this is where the trailing spaces come into play; it allows us to simply reverse the lines rather than re-calculate distances.
If $b
is True
, then the right half of the array $x
is selected instead.
In either case, the pipeline now contains an array of strings. Implicit output via Write-Output
happens at program completion, with default newline between elements.
Examples
PS C:\Tools\Scripts\golfing> .\print-upside-down-tent.ps1 (-5)
____________________
\ / /
\ / /
\ / /
\ / /
\/_________/
PS C:\Tools\Scripts\golfing> .\print-upside-down-tent.ps1 (4)
________________
\ \ /
\ \ /
\ \ /
\_______\/
3
for example? \$\endgroup\$