# Enlarge ASCII art, Mark II

Related

Given a piece of ascii art and a factor to enlarge it by, which will always be an odd number >1, replace each character with the corresponding ascii-art, resized to fit on a grid the size of the input number:

Character What to do
\
\   \   \
A line of \ to the length of the enlarging factor, padded to form a line.
/
  / / /  
A line of / to the length of the enlarging factor, padded to form a line.
|
 |  |  | 
A line of | to the length of the enlarging factor, centred horizontally.
-
   ---   
A line of - to the length of the enlarging factor, centered vertically.
_
      ___
A line of _ to the length of the enlarging factor, at the bottom of the square it's in.

And of course, a space should be resized to a n-by-n grid of spaces. The input will only contain these six characters, plus newlines.

You may take input as a list of lines, a matrix of characters, whatever.

This is a bit confusing, so here's an example:

-\
/, 3 =>
\
--- \
\
/
/
/


Because each character is enlarged to size 3.

Any trailing whitespace is allowed.

# Scoring

This is , shortest wins!

# Testcases

\, 3 =>
\
\
\

---, 3 =>

---------

|
|
|, 3 =>
|
|
|
|
|
|
|
|
|

|\_/|
|   |
\_/ , 3 =>
| \       / |
|  \     /  |
|   \___/   |
|           |
|           |
|           |
\       /
\     /
\___/

_____
\   /
/   \
\___/, 3 =>

_______________
\             /
\           /
\         /
/         \
/           \
/             \
\             /
\           /
\_________/

/\
/  \
/____\
||
||
_/__\_, 3 =>
/\
/  \
/    \
/      \
/        \
/          \
/            \
/              \
/  ____________  \
|  |
|  |
|  |
|  |
|  |
|  |
/      \
/        \
___/  ______  \___

\/
\/, 5 =>
\        /
\      /
\    /
\  /
\/
\        /
\      /
\    /
\  /
\/

/-/
\-\, 7 =>
/             /
/             /
/             /
/   -------   /
/             /
/             /
/             /
\             \
\             \
\             \
\   -------   \
\             \
\             \
\             \

_   _
/ \_/ \
| | | |
|_| |_|, 11 =>

___________                                 ___________
/           \                               /           \
/             \                             /             \
/               \                           /               \
/                 \                         /                 \
/                   \                       /                   \
/                     \                     /                     \
/                       \                   /                       \
/                         \                 /                         \
/                           \               /                           \
/                             \             /                             \
/                               \___________/                               \
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|                     |                     |                     |
|     ___________     |                     |     ___________     |

__    __   __             __  ___
/\  /\    |  |\  |  |     /    |  |     /\    |     |
/  \/  \   |  | \ |  |--  |     |--\    /__\   |--   |
/        \  |  |  \|  |__   \__  |   \  /    \  |     | , 5 =>

__________                    __________               __________                                                                 __________          _______________
/\                  /\                          |              |  \                |              |                               /                      |              |                               /\                          |                             |
/  \                /  \                         |              |   \               |              |                              /                       |              |                              /  \                         |                             |
/    \              /    \                        |              |    \              |              |                             /                        |              |                             /    \                        |                             |
/      \            /      \                       |              |     \             |              |                            /                         |              |                            /      \                       |                             |
/        \          /        \                      |              |      \            |              |                           /                          |              |                           /        \                      |                             |
/          \        /          \                     |              |       \           |              |                        |                             |            \                            /          \                     |                             |
/            \      /            \                    |              |        \          |              |                        |                             |             \                          /            \                    |                             |
/              \    /              \                   |              |         \         |              |  ----------            |                             |  ----------  \                        /              \                   |  ----------                 |
/                \  /                \                  |              |          \        |              |                        |                             |               \                      /                \                  |                             |
/                  \/                  \                 |              |           \       |              |                        |                             |                \                    /    __________    \                 |                             |
/                                        \                |              |            \      |              |                           \                          |                 \                  /                    \                |                             |
/                                          \               |              |             \     |              |                            \                         |                  \                /                      \               |                             |
/                                            \              |              |              \    |              |                             \                        |                   \              /                        \              |                             |
/                                              \             |              |               \   |              |                              \                       |                    \            /                          \             |                             |
/                                                \            |              |                \  |              |  __________                   \__________            |                     \          /                            \            |                             |



Reference implementation

• Can you take input as a matrix of characters? Jul 30, 2021 at 15:23
• @Jonah yes. Adding Jul 30, 2021 at 20:43
• Related. Aug 13, 2021 at 15:30

# APL(Dyalog Unicode), 118 114 90 88 83 80 bytes SBCS

{⊃,/⍪⌿⍵{' '⍺[⍵]}¨1+(⍺ ⍺∘⍴¨o(⌽o←∘.=⍨⍳⍺)i(⌽⍺/⍺↑1)(⍉⍺ ⍺⍴i←(⌈⍺÷2)=⍳⍺)0)['\/|_- '⍳⍵]}


Try it on APLgolf!

A dfn submission which takes a char matrix on the right and a scale factor on the left.

Indexes each character into its specific pattern, and then uses the original matrix to index back into it.

More byte saves can be done by figuring out a formula for getting the boolean arrays.

# V (vim), 311 bytes

"aDj:%s:$$[ \-_]$$:=repeat("\\1",a)
:g
:%s:\\:\\=repeat(" ",a-1)
:g
:%s:/:=repeat(" ",a-1)
/:g
:%s:|:=repeat(" ",a/2)
|=repeat(" ",a/2)
:g
{qqYp:s:\\ : \\:ge
:s: /:/ :ge
qdkG{Go
ggqtjjkk@a@qdd@tq@tggqb@ajk:s:_:Y:ge
j@bq@bi=a/2+1
D@"kkqc:s:-:X:ge
@ak@cq@c:%s:[-_]: :g
:%s:X:-:g
:%s:Y:_:g
gg:s:-: :g


Try it online!

Thanks to PyGamer for the idea of solving this in Vim. It's not extremely well golfed, can change some substitutions and bad hacks around the many macros that are in use.

Outputs the required art with two trailing newlines.

# C (clang), 170 147 143 137 bytes

a,j,i;f(*m,x,z){for(;*m;m+=x)for(j=z;j--;puts(""))for(i=-1;++i<x*z;putchar((a-92?a-47?a-45?a-95|j:j-~j-z:i%z-j:~j+z-i%z)?32:a))a=m[i/z];}


Try it online!

• thanks to @ceilingcat suggestion !
• thanks to @Johan du Toit for suggesting using int*array as input!

f(*m,x,z){ function taking:

• m : char int array without newlines
• x : width
• z : scale

m+=x;*m&&f(m,x,z); => for(;*m;m+=x)
for every row of input, loop actually better than recursion.

for(j=z;j--;puts(""))
we iterate z times every row of input and put \n each time.

for(i=-1;++i<x*z;putchar(..) )
we put x*z characters.

a=m[i/z]
we use a to save on m[i/z] repetitions which is current input being enlarged.

putchar(( ... )?32:a
... => many nested ternary operators to select proper character based on a and i / j relations which evaluates to 1 or 0 , we then puts a space or a.

[(a{~[:,/[:,./"3[*({0:0}(,:|.)@=@i.,/@,~(1,>.@-:)(,:~|:)@|."{1:0},~$0:))~(a=.' _|-\/')i.]  Try it online! # K (oK), 261184165163 159 bytes {k:y;v:" ";a:{[g]{(x#v),g,(k-x+1)#v}'!k};h:{[s]{k#s@x=_k%2}'!k};,/{,/'+{$[92=x;a x;47=x;|:'a x;45=x;h v,x;95=x;{k#" _"@x=k-1}'!k;v=x;(k;k)#v;+h v,x]}'x}'";"\x}


Try it online!

I lost my sanity several times while creating this. Thanks to ngn and Razetime for helping me with this.

Thanks to Razetime for helping me to golf off a lot.

The basic approach is to split by newlines, replace each character with a list of subrows, take the transpose of that, join each line, and flatten.

{,/,'/'c$32|x*(a@<a;+a;|=y;=y;a=:|a:y#'!y)8!19!-x}  Try it online! # Python 2, 135 bytes Takes input as a list of lines. s,f=input() R=range(f) for r in s: for w in R:print''.join([i-w,i-~w-f,w-f/2,f+~w,i-f/2][ord(c)%23%5]and' 'or c for c in r for i in R)  Try it online! • This is a neat answer. Although unless I'm reading wrong, the task requires you to also input an enlarge factor (it's not assumed to be 3). Aug 2, 2021 at 18:24 • @dingledooper Thank you for telling me, I should really spend a bit more time reading the challenges. Now fixed for a couple of bytes (And no big numbers involved anymore :/). – ovs Aug 2, 2021 at 20:49 • The thing is, I had also made this exact same mistake when I tried the challenge a few days ago, only to realize it as I was ready to submit. Not just you :P. Aug 2, 2021 at 21:59 # Charcoal, 55 bytes Ｎθ≔⊘⊕θη↑ＷＳ«Ｊ⁰⁺θⅉＦι¿⁼κ_×θκ«Ｍ⊖η↗≡κ-Ｐ-η/Ｐ/η|Ｐ|η\Ｐ\ηＰκＭ⊖η↘→  Try it online! Link is to verbose version of code. Explanation: Ｎθ≔⊘⊕θη  Input the scale factor n and calculate half, rounded up. ↑ＷＳ«Ｊ⁰⁺θⅉ  Output each transformed row on its own set of n lines. Ｆι  Loop through the characters on each line. ¿⁼κ_×θκ«  If the next character is a _ then print n of them, otherwise... Ｍ⊖η↗  Move to the centre of the square. ≡κ-Ｐ-η/Ｐ/η|Ｐ|η\Ｐ\ηＰκ  Print a line in the desired direction. (TIO's version of Charcoal doesn't support computed multidirectionals, so I'm not sure whether that would beat a switch statement.) Ｍ⊖η↘→  Move to the bottom left of the next square. # JavaScript (ES2020), 157151148 147 bytes Takes a 2D character array A and a size n as f(A)(n). A=>n=>A.flatMap(L=>(N=[...Array(n)]).map((_,y)=>L.flatMap(c=>N.map((_,x)=>[a=y-n+1,a+y,a+=x,a+x-y]['_-/|'.indexOf(c)]??x-y?' ':c)).join)).join   Try it online! # JavaScript (ES2020), 157151148 147 bytes A=>n=>A.flatMap(L=>(N=[...Array(n)]).map((_,y)=>L.flatMap(c=>N.map((_,x)=>({_:a=y-n+1,'-':a+y,'/':a+=x,'|':a+x-y})[c]??x-y?' ':c)).join)).join   Try it online! # JavaScript (ES2019), 161158152149 148 bytes A=>n=>A.flatMap(L=>(N=[...Array(n)]).map((_,y)=>L.flatMap(c=>N.map((_,x)=>[a=y-n+1,x-y,a+y,a+=x,a+x-y]['_\\-/|'.indexOf(c)]?' ':c)).join)).join   Try it online! • 151 I think Aug 5, 2021 at 5:35 • @emanresuA Nice, managed to take it several bytes even lower! Aug 7, 2021 at 22:34 # Haskell, 97 bytes n%a|z<-[1-n,3-n..n]=[do c<-r;x<-z;max" "[c|(l,0)<-zip"|_/\\-"[x,y-n+1,y+x,y-x,y],c==l]|r<-a,y<-z]  Try it online! I/O: size%listOfLines is a new list of lines. # PowerShell, 162152149143 138 bytes param($k,$o)$o|%{$l=$_;1..$k|%{$y=$_ -join($l|% t*y|%{$c=$_;1..$k|%{"$c"[@{1=$y-$_+$k+1 8=$_+$y 7=2*$_
6=2*$y 4=$y+1}[$c%13]-eq$k+1]}})}}


Try it online!

Less golfed:

param($k,$origLines)
$origLines|%{$line = $_ 1..$k|%{                            $y =$_
-join($line|% toCharArray|%{$char = $_ 1..$k|%{                    $x =$_
$rasterFont = @{ 1 =$y-$x+$k+1                      # \
8 = $x+$y                           # /
7 = 2*$x # | 6 = 2*$y                            # -
4 = $y+1 # _ } "$char"[$rasterFont[$char%13]-eq$k+1] # space or$char
}
})
}
}
`