# Rotate ASCII Art by 45 Degrees

Your task is to take an ASCII art image and output it rotated clockwise by 45 degrees and scaled by a factor of $$\\sqrt 2\$$. The scaling comes from using a lattice pattern which introduces space between the characters.

To explain it visually, a $$\3 \times 3\$$ block would be processed like so:

123
456
789


becomes

  1
4 2
7 5 3
8 6
9


Characters will not be transformed, so boxes will look strange after rotation:

+-+
| |
+-+


becomes

  +
| -
+   +
- |
+


To explain the process more explicitly, the output consists of a diamond lattice pattern where the top row corresponds to the top-left character of the input, the next row corresponds with the right and below neighbors, next row is those neighbors, and so forth until all of the characters have been placed on the lattice.

## Examples

           FISHKISSFISHKIS
SFISHKISSFISHKISSFISH            F
ISHK   ISSFISHKISSFISHKISS         FI
SHKISS   FISHKISSFISHKISSFISS       FIS
HKISSFISHKISSFISHKISSFISHKISSFISH    KISS
FISHKISSFISHKISSFISHKISSFISHKISS  FISHK
SSFISHKISSFISHKISSFISHKISSFISHKISSF
ISHKISSFISHKISSFISHKISSFISHKISSF  ISHKI
SSFISHKISSFISHKISSFISHKISSFISHKIS    SFIS
HKISSFISHKISSFISHKISSFISHKISS       FIS
HKISSFISHKISSFISHKISSFISHK         IS
SFISHKISSFISHKISSFISH            K
ISSFISHKISSFISHK


Source

Becomes

     H
K S
I H I
F S K S
S     I S I H S
S I   S F S K F
F S   H I S   I
H I H   K S     S F
K S K S I H     H I
I H I S S K   I K S
H S K S F S I F S I H
K S I S I F S I S S K
I F S F S I S S F S I
S I S I H S F H I F S
S S S F S K H I K S I S
F F H I H I K S I H S F
I I K S K S I H S K H I
I S S I H I S S K S I K S
S H H S K S F S I F S I H
S K K S I S I F S I S S K
F I I F S F S I S S F S I
I S S I S I H S F H I F S
S S S S F S K H I K S I
H F F H I H I K S I H S
K I I K S K S I H S K H
I S S I H I S S K S I
S H H S K S F S I F S
S K K S I S I F S I S
F I I F S F S I S S
I S S I S I H S F S
S S S S F S K H I
H F F H I H I K S
K I I K S K S I H
S S I H I S S
H H S K S F S
K S I S I
S F S
H F K F F F
K I I I I
I I S S S
S S H S
S H S K
F K F
F I I
I S
I S
S
K


      _,,ddF"""Ybb,,_
,d@#@#@#@g,   "Yb,
,d#@#VV@#@#b      "b,
d@#@#I    I@#@8        "b
d@#@#@#A..A@#@#P         b
8#@#@#@#@#@#@8"           8
8@#@#@#@#@#@J             8
8#@#@#@#@#P               8
Y@#@#@#@#P    ,db,       ,P
Y@#@#@#@)    @DWB      aP
"Y#@#@#b    69'    aP"
"Y@#@#g,,     _,dP"
""YBBgggddP""'


Source

Becomes

     d d ,
8 @ @ d ,
8 # # # # d _
8 @ @ @ @ @ @ ,
Y # # # # # # # ,
@ @ @ @ @ I V @ d
Y # # # # #    # d
@ @ @ @ @ A    @ F
" # # # # # .   V # "
Y @ @ @ @ @ .   @ @ "
# # # # # # A I # g "
" @ @ @ @ @ @ @ @ @ , Y
Y # # # # # # # # #   b
@ @ @ P P @ @ @ @ b   b
 # # )     J 8 # 8     ,
" @ b         " P      ,
" #                   " _
Y g                   Y
B ,     ,             b
B ,   @ d             ,
g    D b           "
g   6 W ,           b
g   9 B             ,
d   '             "
d                 b
P _
" ,             b
" d           8
' P a       8
" P a , 8
" P P


                             ...,?77??!~~~~!???77?<~....
..?7                           7!..
.,=          ..~7^   I                  ?1.
........  ..^            ?  ..?7!1 .               ...??7
.        .7        .,777.. .I.    . .!          .,7!
..     .?         .^      .l   ?i. . .       .,^
b    .!        .= .?7???7~.     .>r .      .=
.,.?4         , .^         1             4...
J   ^         ,            5                ?<.
.%.7;         .     .,     .;                   .=.
.+^ .,       .%      MML     F       .,             ?,
P   ,,      J      .MMN     F        6               4.
l    d,    ,       .MMM!   .t        ..               ,,
,    JMa..         MMM   .         .!                .;
r   .M#            .M#   .%  .      .~                 .,
dMMMNJ..!                 .P7!  .>    .         .         ,,
.WMMMMMm  ?^..       ..,?! ..    ..   ,  Z7        ?^..  ,,
?THB3       ?77?!        .Yr  .   .!   ?,              ?^C
?,                   .,^. .%  .^      5.
7,          .....?7     .^  ,        ?.
<.                 .= .'           1
....dn... ... ...,7..J=!7,           .,
..=     G.,7  ..,o..  .?    J.           F
.J.  .^ ,,,t  ,^        ?^.  .^  ?~.      F
r %J. $5r J ,r.1 .=. .% r .77=?4. , l ., 1 .. <. 4., .$..    .X..   .n..  ., J. r .  J.       '
.?  .5         .%   .% .' L.'    t
,. ..1JL          .,   J .$.? . 1. .=  .J7??7<.. .; JS.. ..^ L 7.: > .. J. 4. + r t r ~=..G. =$  ,.  J
2   r   t  .;
.,7!  r   t7~..  j..
j   7~L...$=.?7r r ;?1. 8. .= j ..,^ .. r G . .,7, j, .>=. .J??, T....... % .. ..^ <. ~. ,. .D .? 1 L .7.........?Ti..l , L . .% .! j, .^ . .. . .^ .?7!?7+. 1 . . ...7. .^ , .i.; .7<..........~<<3?7! 4. r  G% J. .! % JiJ . .1. J ?1. .' 7<..%  Source Becomes  . . . . . . b . . . , . . J . . . % ? . + . 4 . . P ^ 7 ! ? . l ; ^ 7 . , .  . d , ^ . . M r , , W M , = M M d  . M N J , . ? M J . M ? T M . M a , . 7 H M . # . = .  . ? B m ! . . . , . ^ . . , 3  , J %  ^ . , . ? 7 , 7 ? 7 7 ? r . , ^ ? 7 7 . r J . . ? . ? 7 , ? . % . .  . ? .  . ? . $ . J   = . <                     .     7 .     .   ?
. 7 .     . .                 . M ,     ~ l .   ~   !
.   . 7   .   .       ?         . M M       .   I . 7   ~
. .   = $^ . 7 M M L . . ^ ~ 1 5 ? d 7 M M N 1 ?  ~ J 4 , n ? . M M ? 7 ~ L . , G . ! M M ! 5 i ! ! . , . . . #  . . 1 ? . . 1 X 5 t , . . . ; . . I ? .  ^ , . . . r 7 . , F > . . ? 7  ? . J . . . ? . F r . 7 <  . S  J , . . ! . . . t . ! 7 . ^ . . .  ^ . . . P % .  ? . J j ,  .  , . ? . 7  < . ? . 7 >  . , . 7 . . !  ~ . ? , r 8 ! + n o . , . . . . , 7 . = . . . . . ^ Y . . , 7 2 . . % . . , . r . . . . < ~ r . , 7  > , . . .  L r . l . . . 6 4 . . 1 T .$     ^ .     .       . . = . . . .       .         . = .
.           .       .   r        =   . , .   ? ? J   ^ %         . .         .   ,       7
~     L   ~ .       . t     t      J %   ,   ^   = .           . !           .   ^ .     !
<   .     . .     . $ , J . !  . ~ , . < . L . G = = 7 .  . . . 1 7 ' , . . , ? 7 . 3 . . . ~ t J$ '     ,     ,    ^ !                 <       ! .
?   .       . j     ? .     r .   . .   r   r . J                           .         .
7 . .       . ,     7 .   J     L J ? L   . . ^ .           Z                         . ?
!        ,         r   .   ~     7  . . . 1               7             .           ? 1
 .       . %     j     ;   = 4   ?   '                  ?              =           ? .
.   . .             j     . .   ?       <              ,               .           7
 . % 7         .   .     .     7       .   ?
7    .         . r .     G     <     J     ~         5               ?
.     .         ,         .     .     .     .         .     .         ,
4       .         ^ ;             .   t               ?
.       .           ?               .       .         .               4
J   . . . .           1           7 .         =       1                 .
. r ^ ^  .           .           . ;         .     .                 ,
! .         .             :                 ,                ,
J           .     . . .                       4     F           ?     .
i .  , .   .     >                           . . F             ^     ;
J !    ?   ?     =                          , %               .   .
.         7   T     .                         '                   .   ,
1         !   i . .                                                 ,
.         ?   . D .                                                 ,
7   .                                                 ? ,
?           +  l                                                 ^ ,
1           . j                                                   C
.         .   ,
i 1
.
7         G ;
<         %
.     . %
. . J
% '


## Rules and Notes

• Input and output may be in any convenient format and character encoding as long as it supports all printable ASCII characters (U+0020 - U+007E, LF)
• You may assume the input contains only printable ASCII characters (defined above)
• You must support art up to $$\100 \times 100\$$ characters.
• You may assume the input is right-padded, as to be a perfect rectangular grid of characters.
• If it conveniences you, you may also assume the input is padded to be exactly $$\100 \times 100\$$ characters.
• Use the ASCII space to align and space characters.
• Characters may be overpadded (or even underpadded) in any direction as long as the result is properly aligned.

Happy Golfing!

• Poor Sonic, he just wanted to live D: – Benjamin Urquhart Apr 2 '19 at 19:46
• you may want to use full-width characters so that after rotating it's still has a quite square shape Display characters on a square grid?, Converting full-width characters to half-width characters (perl, regex, Japanese) – phuclv Apr 3 '19 at 4:22
• – Shaggy Apr 12 '19 at 23:26
• @Shaggy I'd say just related, but yeah, that bears a lot of similarities for sure. The only substantial difference is this challenge requires space padding in the output. In other news, you are impressively good at finding dupes. – Beefster Apr 12 '19 at 23:32
• If that were true, I'd've found that challenge while this one was still in the Sanbox! I stumbled across it completely by accident while searching for a dupe of a challenge idea I had and instantly remembered yours. – Shaggy Apr 13 '19 at 19:59

# Charcoal, 2 bytes

↘Ａ


Try it online! Link is to verbose version of code. Takes input as either a single newline-delimited string literal or as an array of strings. Explanation: Ａ reads the input and ↘ outputs it in the desired diagonal direction. Version which accepts a blank-line terminated list of lines from STDIN:

ＷＳ⊞υι↘υ


Try it online! Link is to verbose version of code.

• Wow. The right tool for the job. – connectyourcharger Nov 12 '19 at 22:09

# Canvas, 6 bytes

／⤢ ＊＼⤢


Try it here!

/        pad each line with one less space than the previous
⤢       transpose the object
*     place a space between every character
\    pad each line with one more space than the previous
⤢   transpose the object back


Example:

123
456
789
/:
123
456
789
⤢:
7
48
159
26
3
*:
7
4 8
1 5 9
2 6
3
\:
7
4 8
1 5 9
2 6
3
⤢:

1
4 2
7 5 3
8 6
9


• Are your code and explanation not using differing slashes? – Adám Apr 2 '19 at 18:21
• @Adám I usually ASCII-fy the explanations for them to align better – dzaima Apr 2 '19 at 18:22

# Python 3.8 (pre-release), 104 bytes

lambda a:[" "*abs(l+~i)+" ".join(a[i-j][j]for j in range(i+1)if j<l>i-j)for i in range((l:=len(a))*2-1)]


Try it online!

-5 bytes thanks to ovs (Python 3.8 things)

• 5 bytes shorter in Python 3.8 – ovs Apr 3 '19 at 7:31
• @ovs wait 3.8 is out? :o inline assignment. i like this. thanks! – HyperNeutrino Apr 3 '19 at 16:17

# J, 56 45 bytes

-11 bytes thanks to FrownyFrog!

-@}:@(i.@-@#,#\@{.)|."_1+/@${."1|.@,@,.&' '/.  Try it online! • here's 45 – FrownyFrog Apr 3 '19 at 13:33 • @FrownyFrog Thank you! Brilliant as always! – Galen Ivanov Apr 3 '19 at 14:11 # 05AB1E, 18 12 bytes RāRú€Sζðýāú»  Port of @dzaima's Canvas answer, so make sure to upvote him!! Input as a list of lines. Try it online. Explanation: R # Reverse the (implicit) input-list ā # Push a list in the range [1, length of input-list], # without popping the list itself R # Reverse this list to [length, 1] ú # Pad the reversed input-list with that many leading spaces €S # Split each string on spaces ζ # Zip/transpose; swapping rows/columns, with space default as filler ðý # Join each inner character-list by spaces ā # Push a list in the range [1, length of this string-list], # without popping the list itself ú # Pad the list of strings with that many leading spaces » # Join the string-list by newlines (and output the result implicitly)  Original 18 17 bytes answer: €g2.ýIεNFR]JŽE5SΛ  Input as a list of lines. Try it online. Explanation: €g # Get the length of each line of the (implicit) input # (assumes they are all padded with spaces to make them of equal length) 2.ý # Intersperse this list with 2 (i.e. [3,3,3] becomes [3,2,3,2,3]) Iε # Map the strings in the input to: NF # Loop the 0-based index amount of times: R # And reverse the current string that many times ]J # After the loop and map: join the strings to a single string ŽE5S # Push compressed integer 3575, converted to a list of digits: [3,5,7,5] Λ # Use the canvas with these three options (which is output immediately by default)  See this 05AB1E tip of mine (section How to compress large integers?) to understand why ŽE5 is 3575. Some more info about the 05AB1E Canvas builtin can be found in this tip of mine. The Canvas builtin takes three parameters: • $$\a\$$ Length: The size(s) of the line(s). This can be a single integer, or a list of integers • $$\b\$$ String: The character(s) we want to display. This can be a single character, a string, a list of characters, or a list of strings (in the last three cases it will use all of them one-by-one including wrap-around) • $$\c\$$ Direction: The direction the character-lines should be drawn in. In general we have the digits [0,7] for the directions, for which we can use one or multiple. There are also some special options that require a certain character (+, ×, 8). In this challenge I use the following options: $$\c\$$: Let's start with the directions. For this I use $$\[3,5,7,5]\$$ which translates to $$\[↘,↙,↖↙]\$$. This means the string is printed in the following matter:  S ↘ ↙↖ ↘ ↘ ↖ ↘ ↙↖ ↘ ↖↙ ↘ ↖ ↘ . ↖ ↙ .  $$\b\$$: Since we print in this direction, this means the list of strings we input has to be modified slightly, which is what we do with the reverse on each 0-based odd-indexed string in the list. $$\a\$$: Finally, the lengths of how it is printed. This will be the length of each lines for the directions $$\3\$$ ($$\↘\$$) and $$\7\$$ ($$\↖\$$). The $$\2\$$ for the directions $$\5\$$ ($$\↙\$$), which means to print one character (with a character overlap of the trailing part of the previous line) in a south-west direction, and then we print the next line (with again one character overlap, hence the use of $$\2\$$ instead of $$\1\$$). This overlapping is better explained in the tip I linked earlier. # Jelly, 26 bytes JU’;ZJ$x@€⁶ðżµUŒDUṙLN‘ƊṚK€


Try it online!

# Jelly, 19 bytes

ỴṚµLḶṚŒḄ⁶ẋżŒDṙLK€ƲY


Try it online!

# JavaScript (ES6), 102 bytes

f=
s=>(z=[...Array(100)],o=z.map(v=>z.map(_=>" ")),s.map((r,y)=>r.map((c,x)=>o[y+x][s.length+~y+x]=c)),o)


Try it online!

Input and output as list of lists.

Explanation:

Creates a 100x100 grid of spaces. Then loops through the input, setting the appropriate entry in the grid. The index of the character to set is calculated as x' = length of input - 1 + y + x and y' = y + x.

The returned result is a 100x100 list of lists, with the output in the upper left corner.

# Ruby, 94 bytes

->l{w=(2..y=l.size+b=l[z=0].size).map{' '*y};l.map{|r|b.times{|x|w[x+z][b+~z+x]=r[x]};z+=1};w}


Try it online!

# C# (Visual C# Interactive Compiler), 153 bytes

z=>{var m=new char[100,100];var s=z.Split('\n');var l=s[0].Length;for(int x=0;x<l-1;x++)for(int y=0;y<s.GetLength(0);y++)m[x+y,l+~y+x]=s[y][x];return m;}


Try it online!

Asks for a string and returns a 2D char 100 x 100 array.

I tried using LINQ/Collections, but I eventually give up.

# Wolfram Language (Mathematica), 79 bytes

SparseArray[100+{#2+#,#2-#}&@@#&/@Range@100~Tuples~2->Flatten@#,{301,301}," "]&


Try it online!

The input should be padded as exactly 100x100. The output is an array of 301x301. The result of rotating sonic (with proper formatting):