MATL, 56 53 bytes
:"'!!((!((!!#*```).?p0```!!!]'8eP!P]'p(.' '.a-'XE&hqc
Try it online!
Explanation
Awake goat
The awake goat can be packed into the string
'' '' ")___(->o/___ \
and unpacked as will be explained shortly. However, the single-quote symbols would need to be duplicated in order to escape them, so the string literal would have to be defined as (note the enclosing single-quote symbols and the duplication of the original ones):
' '''' '''' ")___(->o/___ \'
To save bytes, we define the string using characters one code point above that, thus avoiding duplication. The string literal becomes
'!!((!((!!#*```).?p0```!!!]'
At the end of the code we will subtract 1 and convert to char. (We could do it now, right after the string literal; but leaving it for the end will save another single-quote duplication, as we will see).
To explain how the string is unpacked, we will work with the original characters (that are produced at the end of the code by subtacting 1), so the explanation is easier to follow. We first reshape the string
'' '' ")___(->o/___ \
into an 8-row 2D char array, in column-major order (down, then across). This automatically pads the last column with char 0 (at the end of the code, subtracting 1 will transform it into number −1, which converted to char gives again char 0). Char 0 is displayed as a space. So effectively we are padding with spaces. The result of reshaping is
>
"o\
')/
'__
__
'__
'(
-
We now flip vertically:
-
'(
'__
__
'__
')/
"o\
>
and then transpose and flip vertically again to produce the awake goat:
\
___/o>
-(___)"
'' ''
The two flip operations are needed because the original packed string is "in reverse". This is to exploit the fact that the actual 2D char array representing the goat has 6 initial spaces in its first row, which get automatically filled by padding when the string is reshaped into an 8-row 2D array. But the padding is done at the end (not beginning) of the last column (not row), hence the flips and transpose.
Sleeping goat
A sleeping goat is generated from an awake goat by transliterating chars o
, '
, -
into -
, `
, ,
respectively. Actually, because of the one-code-point-above transformation, we transliterate chars p
, (
, '
into .
, a
, -
, which again saves us from having to duplicate the single-quote symbol. This is why the subtract-one operation was left for the end of the program.
Code structure
- Generate an awake goat
N
times, working with code points increased by 1.
- Transform the last goat into a sleeping goat.
- Concatenate all goats horizontally. Subtract 1 to code points and cast to char.
Commented code
: % (Step 1) Implicitly input N. Push range [1 2 ... N]
" % For each (i.e. repeat N times)
'!!((!((!!#*```).?p0```!!!]' % Push this string. Quotes are escaped by duplicating
8e % Reshape into an 8-row 2D array of char, in
% column-major order, padding last column with
% char 0
P % Flip vertically
!P % Transpose and flip vertically
] % End
'p(.' % (Step 2) Push this string: source for transliteration
'.a-' % Push this string: target for transliteration
XE % Transliterate. Transforms last goat into sleeping
&h % (Step 3) Horizontally concat all 2D char arrays
qc % Subtract 1 and convert to char. 0 becomes −1, which
% is converted to char 0, which is displayed as a space
% Implicitly display