Operator ASCII art
V, 78, 72, 71, 68, 65, 63, 62, 61 bytes
Ç=ü-/Àé X
ç^Ó/é Àä$
ç+/ÀÄM|ÀR+
ç=/Ä
ç¯/lòhYpX
çx/rxòl3Äjxlrx
Try it online!
As always, the neck-and-neck battle with 05AB1E is really fun!
Since this contains non-ASCII characters, here is a hexdump:
0000000: c73d fc2d 2fc0 e920 580a e75e d32f e920 .=.-/.. X..^./.
0000010: c0e4 240a e72b 2fc0 c44d 7cc0 522b 200a ..$..+/..M|.R+ .
0000020: e73d 2fc4 0ae7 af2f 6cf2 6859 7058 0ae7 .=/..../l.hYpX..
0000030: 782f 7278 f26c 33c4 6a78 6c72 78 x/rx.l3.jxlrx
This does create leading spaces in the output for =
and -
, but this seems to be allowed. If this is not allowed, feel free to comment and I'll roll it back.
Explanation
The "global command" (e.g. ç
) applies a certain set of commands to every line that matches a certain regex. The syntax is
ç<compressed regex>/<commands>
This is the easiest way of simulating a conditional/switch statement. In my original answer, I simply created the entire ASCII-art on the right-hand side for each different character we need to search for. However, a lot of these outputs require similar commands. So I combined them. The first command ('Ç') is actually the inverse of the global command, it applies the command to every line not matching the regex. So the first command is:
Ç=ü- " On every line not containing an '=' or an '-' (e.g. inputs '/', '+', and 'x'):
/Àé " Insert *n* spaces
X " Delete one of them
The following command is for inputs '=' and '-'. These two are conveniently easy and similar. After this command, we need no more processing for -
.
ç^Ó " On every line that starts with non-whitespace (e.g. every line not affected by our previous command):
/é " Insert one space
" Move back a character
À " Make *n* copies
ä$ " Of every character on this line
From here we just do some extra commands for each individual possible input. For +
:
ç+/ " On every line containing a '+':
ÀÄ " Make *n* copies of this line
M| " Move to the first character of the middle line
À " *n* times:
R+ " Replace the next two characters with '+ '
The command for equals is very straightforward. We just duplicate it with Ä
. For /
:
ç¯ " On every line containing a '/':
/l " Move one character to the right
ò " Recursively:
h " Move one character to the left
Yp " Make a copy of this line
X " Delete one character
ò " End loop (implicit)
The last one is the most complicated. It is basically a port of this answer.
çx " On every line containing a 'x':
/rx " Replace the first character with an 'x'
ò " Recursively:
l " Move one char to the right
3Ä " Make 3 copies of this line
j " Move down one line
x " Delete one char
l " Move one char to the right
rx " Replace this char with an 'x'
05AB1E, 81 76 74 73 70 69 68 65 64 62 60 59 57 56 bytes
Currently in war with the V answer. I'm coming for you Dr. McMoylex :p.
Also in war with the Pip answer. I'll be watching you Mr. DLosc.
Code:
Ç6&"¹s<ú.s.Bívy¹'xQiÂðñ}, ¹×S)»¹'=Qƒ= ;ƒ¹})D¦»»Rû.c"#è.V
Or in a more readable form:
Ç6&
"¹s<ú.s.Bívy¹'xQiÂðñ},
¹×S)»¹'=Qƒ=
;ƒ¹})D¦»»Rû.c"
#è.V
Uses the CP-1252 encoding. Try it online!
Python 3, 304 283 278 bytes
Simple enough, just makes a matrix of chars and applies the different operations based on which one it is. The =
and -
have trailing spaces if that's not too bad.
EDIT: Thanks to @Shebang and @Rod for their suggestions which ended up saving 21 bytes!
EDIT2: Thanks to @Artyer for saving 5 bytes!
t,s=input().split()
s=int(s)
r=range(s)
b=[[' ']*s for x in r]
exec(['for x in r:b[s//2][x]=b[x][s//2]=t','b=[t*s]'+'*2'*(t=='='),'for x in r:b[x][s-x-1]='+'b[x][x]='*(t=='x')+'t'][(t>'+')+(t in'x/')])
if t in'-=+':b=[[x+' 'for x in l]for l in b]
print(*map(''.join,b),sep='\n')