gI¨„+×Λ1Iθ8Λ
Try it online.
Explanation:
g # Push the length of the (implicit) input-string
I # Push the input-string again
¨ # Remove its last character
„+× # Push string "+×"
Λ # Use the Canvas builtin with these three arguments
# (after which the result is output immediately as result)
1 # Push 1
Iθ # Push the last character of the input
8 # Push 8
Λ # Use the Canvas builtin with these three arguments again,
# writing on top of the previous Canvas result
# (after which the result is output immediately as result)
The Canvas Builtin uses three arguments to draw a shape:
- Character/string to draw: the input minus its last character in this case
- Length of the lines we'll draw: the length of the input in this case
- The direction to draw in: the
"+×"
, which translates to directions [0,4,4,0,2,6,6,2,1,5,5,1,3,7,7,3]
, where each digit represents a certain direction:
7 0 1
↖ ↑ ↗
6 ← X → 2
↙ ↓ ↘
5 4 3
So the +×
/[0,4,4,0,2,6,6,2,1,5,5,1,3,7,7,3]
in this case translates to the directions \$[↑,↓,↓,↑,→,←,←,→,↗,↙,↙,↗,↘,↖,↖,↘]\$.
Here a step-by-step explanation of how it draws for example input abcd
with these steps (with the other two Canvas arguments being 4
and "abc"
):
Step 1: Draw 4 characters ("abca"
) in direction 0↑
:
a
c
b
a
Step 2: Draw 4-1 characters ("bca"
) in direction 4↓
:
a
b
c
a
Step 3: Draw 4-1 characters ("bca"
) in direction 4↓
:
a
b
c
a
b
c
a
Step 4: Draw 4-1 characters ("bca"
) in direction 0↑
:
a
b
c
a
c
b
a
Step 5: Draw 4-1 characters ("bca"
) in direction 2→
:
a
b
c
abca
c
b
a
Etc., resulting in:
a a a
b b b
ccc
abcacba
ccc
b b b
a a a
After which we replace the middle a
with the last character of the input-string with 1Iθ8Λ
, where Λ
is another call of the Canvas builtin with the options: 1
for the length; Iθ
is the last character of the input; and 8
to reset the direction-option back to the start (although in this case, the 8
could also be any of the eight directions 0-7
for the same result, since it already ended at the center anyway).