[Question]
  [
Given a square string, produce all the output for the string at every stage of unfurling.
The string must unfurl in a clockwise direction one quarter turn at a time.
## Examples
**Input**:
```
A
```
**Output**:
```
A
```
***Note**: I'll also accept the input duplicated for this particular test case **only** if this helps reduce your byte count.*
**Input**:
```
DC
AB
```
**Output**:
```
DC
AB
  D
ABC
ABCD
```
**Input**:
```
GFE
HID
ABC
```
**Output**:
```
GFE
HID
ABC
   HG
   IF
ABCDE
     IH
ABCDEFG
       I
ABCDEFGH
ABCDEFGHI
```
**Input**:
```
JIHG
KPOF
LMNE
ABCD
```
**Output**:
```
JIHG
KPOF
LMNE
ABCD
    LKJ
    MPI
    NOH
ABCDEFG
       NML
       OPK
ABCDEFGHIJ
          ON
          PM
ABCDEFGHIJKL
            PO
ABCDEFGHIJKLMN
              P
ABCDEFGHIJKLMNO
ABCDEFGHIJKLMNOP
```
## Rules
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") so the shortest code in bytes wins.
* Any reasonable format can be used for I/O assuming it is consistent.
* Spaces must be used to pad the top lines of the output.
* Must be able to handle input of all printable characters (including space: `\x20`-`\x7e`):
```
 !"#$%&'()*+,-./0123456789:;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~
```
* Leading/trailing whitespace is allowed.
* You can assume the string will always be a square.
* All [standard loopholes](https://codegolf.meta.stackexchange.com/q/1061/9365) are forbidden.
Inspiration: [Write a square program that outputs the number of times it has been “unrolled”](https://codegolf.stackexchange.com/q/39993/9365).
  
[Answer]
# [SOGL V0.12](https://github.com/dzaima/SOGL), ~~21~~ ~~20~~ ~~19~~ ~~18~~ 17 [bytes](https://github.com/dzaima/SOGL/blob/master/chartable.md)
```
ø;[;ο⁴№č▓┼№TJι;jI
```
[Try it Here!](https://dzaima.github.io/SOGLOnline/?code=JXUyMTkyJUY4JTNCJTVCJTNCJXUwM0JGJXUyMDc0JXUyMTE2JXUwMTBEJXUyNTkzJXUyNTNDJXUyMTE2VEoldTAzQjklM0JqSQ__,inputs=JTVCJTIySklIRyUyMiUyQyUyMktQT0YlMjIlMkMlMjJMTU5FJTIyJTJDJTIyQUJDRCUyMiU1RA__) (`→` added because this expects input on the stack)
Explanation:
```
ø;[;ο⁴№č▓┼№TJι;jI
ø;               push an empty string below the input           stack with the input GFE,HID,ABC
  [              while [ToS (the array) isn't empty] do       ["", [["G","F","E"],["H","I","D"],["A","B","C"]]]  
                                                                stack at the second time looping
   ;               duplicate 2nd from top                     [[[H,G], [I,F], [D,E]], "ABC"]
    ο              wrap it in an array                        [[[H,G], [I,F], [D,E]], ["ABC"]]
     ⁴             duplicate 2nd from top                     [[[H,G], [I,F], [D,E]], ["ABC"], [[H,G], [I,F], [D,E]]]
      №            reverse vertically                         [[[H,G], [I,F], [D,E]], ["ABC"], [[D,E], [I,F], [H,G]]]
       č▓          join the inner arrays (┼ fails otherwise)  [[[H,G], [I,F], [D,E]], ["ABC"], ["DE", "IF", "HG"]]
         ┼         add the 2 parts together                   [[[H,G], [I,F], [D,E]], ["ABCDE", "   IF", "   HG"]]
          №        reverse vertically again                   [[[H,G], [I,F], [D,E]], ["   HG", "   IF", "ABCDE"]]
           T       print that without popping                 [[[H,G], [I,F], [D,E]], ["   HG", "   IF", "ABCDE"]]
            J      take the last line off                     [[[H,G], [I,F], [D,E]], ["   HG", "   IF"], "ABCDE"]
             ι     remove the rest of the array               [[[H,G], [I,F], [D,E]], "ABCDE"]
              ;j   remove the last line of the original array ["ABCDE", [[H,G], [I,F]]]
                I  rotate it clockwise                        ["ABCDE", [[I,H], [F,G]]]
```
[Answer]
# [Python 2](https://docs.python.org/2/), ~~209 207 205 203 202 201 200~~ 196 bytes
-4 bytes thanks to [@Quelklef](https://codegolf.stackexchange.com/users/43266/quelklef)!
```
s=input();l=len;k=''.join;exec"print s;s=[x for x in[' '*l(s[0])+k(x[:-1]for x in s[-2::-1])[t::l(s[0])-1]for t in range(l(s[0]))][:-1]+[s[-1]+k(x[-1]for x in s)[-2::-1]]if x.strip()];"*(2*l(s)-1)
```
[Try it online!](https://tio.run/##VY7JDoIwFEV/5aUbWhSiLNt04TwP@6YLY0ArpDS0JvXrkRpYuLrJu@eePPNxz1pnbWu50ubtMGEVr3LNSh5F6atWmuU@vyPTKO3AMsuFh6JuwIPSIoIorrAVE0lGJfaCJlM5lGBFktFwIcJR2mM94ALQ3PQjx31B5G89Et2si2D7k5HBJlUBPrWuUQYTyVCMs/BDZyZtK9B@t92gMaDD9bIOeTydVyFn88USyS8 "Python 2 – Try It Online")
# [Python 2](https://docs.python.org/2/), ~~219 217 215 213 212 211~~ 207 bytes
```
s=input();l=len;k=''.join;exec"print'\\n'.join(s);s=[x for x in[' '*l(s[0])+k(x[:-1]for x in s[-2::-1])[t::l(s[0])-1]for t in range(l(s[0]))][:-1]+[s[-1]+k(x[-1]for x in s)[-2::-1]]if x.strip()];"*(2*l(s)-1)
```
[Try it online!](https://tio.run/##VY45D4MgAIX/CmEBtJrWUeLQ@z52ZGgabakGDdCE/noqrQ6dXvKOL699m0cjE@d0JmT7MpjQOqsLSasMofjZCEkLW9xgq4Q0KM/lz8SaUJ0xC8pGAQuEZAigoMaajTkJK2xZGk34EALNoiT1DmEmTftaXzC@oK7yXuA@IPy7Dlk368TT/mBkoHFRAhtro0SLCacwwIn/0JGJcwzutps1HAG4v5xXXg/H09LrdDZfQP4B "Python 2 – Try It Online")
The first one outputs as a list of Strings, the second one outputs as ASCII-art.
[Answer]
# [Charcoal](https://github.com/somebody1234/Charcoal), ~~42~~ 35 bytes
```
ＡＥθＳθＷ⊟θ«⪫θ¶ＡＥι⮌⪫Ｅθ§μλωθ⊞υι↙←⮌⪫υωＤ⎚
```
[Try it online!](https://tio.run/##XY3LDoIwEEXX9CsaV9Ok/gCuEHygokS3bohWaVJapC2YGL@9UtTEuLs398yZU1k0J1UI5yKt@VVCVtRwoziVtTUH03B5BUIovpEJ6kouGIZc9QQh@IGCvN8NrBSX/mZ0lCPSc8GPilO8Zy1rNHtjH31kUnlmd6goFl7fke@TILe6BEsx9yVTLYMwUZ3csIsZ5uFl6Ouf2r41PZPYqgYfYsGKxqenc6t0uUDrfDdHm2w7Q9E0Tty4dWMtXg "Charcoal – Try It Online") Link is to verbose version of code. Edit: Saved 7 bytes mostly by switching from character arrays to strings. Explanation:
```
ＡＥθＳθ
```
Read the input square as an array of strings into the variable `q`.
```
Ｗ⊟θ«
```
While the last string in the array is not empty, remove it.
```
⪫θ¶
```
Print the rest of the array.
```
ＡＥι⮌⪫Ｅθ§μλωθ
```
Rotate the rest of the array by looping through each character of the last string and joining the `l`th character of every remaining string in the reversed array.
```
⊞υι↙←⮌⪫υω
```
Append the previously removed last string to `u`, which holds the unfurled value, and print it.
```
Ｄ⎚
```
Output the result and then clear the canvas ready for the next iteration.
Note that this version outputs the final unfurl on a separate line, if this is undesirable then for 38 bytes:
```
ＡＥθＳθＷ⊟θ«⊞υι←Ｅ⁺⟦⪫υω⟧⮌θ⮌κＡＥι⮌⪫Ｅθ§μλωθＤ⎚
```
[Try it online!](https://tio.run/##TY7LCsIwFETXzVdkeS/EH9BVfVerBl2Ki6KxDcb0kcQK4rfHRhTdzTBnhjkWWXMsM@V9bIzMNayyCmpGE105u7ON1DkgMlrjgLSFVIICLzsCkT5IxJ0pwDEquzTiHWyhn4qzZTTMcOUM7Bel1IFp8cDoVtxEY0To/8wFMfT/Dshf@K5/TsU20SdxhyujKgy0@L0Wjd21giBGSmRNUE/vF8l8RpZ8MyXpaj0h8XA09r2b7xn1Ag "Charcoal – Try It Online") Link is to verbose version of code. Explanation: `←Ｅ⁺⟦⪫υω⟧⮌θ⮌κ` reverses the current array, prepends the unfurled line, then reverses the characters in each line, then prints everything upside-down, thus producing the desired result.
[Answer]
# [Haskell](https://www.haskell.org/), ~~127~~ 120 bytes
```
e=[]:e
i#[x]=[]
i#s|t<-foldl(flip$zipWith(:))e$init s,j<-i++last s=(map((j>>" ")++)(init t)++[j++last t]):j#t
f s=s:""#s
```
[Try it online!](https://tio.run/##LYzLCsJADEX38xWh7WKGWj@gtILv9wNcuChdFDrV1HFanAgi/nsN6iJw7s1JLoW7amO6TqdZHmuBfvbMGRncm5KoakxpZGWwDV7YnpAuMlZKB2iRwPXqJMIwNIXjkMpb0UpZDwYeeCoMlfxKxJjVf4lyFdc@iYp1F3ue77pbgRZSKBsBgLZ9ECQRnDWNG0vakuOa/25B8upI942FPjysQaudYqx4vgGC33m3Wi7mYn3Yz8Rmu5uK4Wg8@QA "Haskell – Try It Online")
Input is a list of lines, e.g. `["DC","AB"]` for the second test case, output is a list of lists of lines: `[["DC","AB"],[" D","ABC"],["ABCD"]]`. Use `mapM (putStrLn . unlines)` to pretty-print the result.
**Edit:** Saved 7 bytes by noticing that the [shorter `transpose`](https://codegolf.stackexchange.com/a/111362/56433) I found some while a go comes in handy because it can be modified to reverse each transposed directly.
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 18 bytes
```
[Dí.Bí»,¤UR¦ζŽ`Xì)
```
[Try it online!](https://tio.run/##MzBNTDJM/f8/2uXwWj2nw2sP7dY5tCQ06NCyc9uO7k2IOLxGEyin7uXp4a6uo@4d4O8GpHx8/VyBlKOTs4t6LAA "05AB1E – Try It Online")
**Explanation**
```
[            Ž       # while stack is not empty, do:
 D                   # duplicate current list
  í                  # reverse each element
   .B                # pad with spaces to equal length
     í               # reverse each element again
      »,             # join with newlines and print
        ¤U           # store the last element in X
          R¦         # reverse the list and remove the first element
            ζ        # zip with spaces as filler
              `      # split elements separately to stack
               Xì    # prepend X to the last element
                 )   # join the stack to a list
```
[Answer]
# J, 62 bytes
```
|."1@([:(#~[:-.[:*/"1' '=])|.@{:(}:@],{:@],[)|:@}:)^:(1<#)^:a:
```
[Try it online!](https://tio.run/##y/r/P03BVk@hRk/J0EEj2kpDuS7aSlcv2kpLX8lQXUHdNlazRs@h2kqj1sohVqcaRERr1lg51FppxllpGNooA6lEKy6u1OSMfIU0BRMgVFFQ9/L0cPcO8Hfz8fVzdXRydlH//x8A)
I'm sure this can be golfed a lot. This prints extra whitespace, but only because of the way that J formats the arrays contained within the outputted array to have the same shape.
I think once I go in and comment out exactly what I'm doing, I might get a better idea of how to golf this (having done that now, I don't really know...). For purposes of golfing, it's worth noting that
* I have to special case 1 row inputs (the while part of the loop)
* I have to eliminate all lines consisting solely of whitespace (surely there must either be a builtin for this or a better way to do it), which is the filter near the end
* There are a lot of caps, identity functions, and atops
# Explanation
In ungolfing this, I'll be splitting the main function in three.
```
unfurl_reversed   =. |.@{: (}:@] , {:@] , [) |:@}:
whitespace_filter =. #~ [: -. [: */"1 ' ' = ]
unfurl            =. |."1@(whitespace_filter @: unfurl_reversed) ^: (1 < #) ^: a:
test_case         =. 3 3 $ 'GFEHIDABC'
```
We'll be working with the second test case.
### unfurl\_reversed
```
|.@{: (}:@] , {:@] , [) |:@}:
```
This gives one the string unfurled once, but in reverse. All of this is being done in reverse and in a specific order so that the way J automatically pads strings with spaces to match the shape of the array they're in will give the right spacing.
`|:@}:` is the transpose of the curtail of the input
```
   |:@}: test_case
GH
FI
ED
```
`|.@{:` is the reverse of the tail of the input
```
   |.@{: test_case
CBA
```
I think you can see what we want to do: we want to append the reverse of the tail to the last part of the transpose of the curtail (that's a mouthful, but basically attach `CBA` to the end of `ED`). This will give us one step of unfurling, reversed.
`(}:@],{:@],[)` does just that.
It appends `CBA` to `ED`, then joins that with the rest of the array. Our output therefore is
```
   unfurl_reversed test_case
GH   
FI   
EDCBA
```
### whitespace\_filter
```
#~ [: -. [: */"1 ' ' = ]
                 ' ' = ]  Equate each element to space
            */"1          Product of each row (all true?)
      -.                  Negate
#~                        Filter rows that are true
```
Basically, this tests to see if any row is completely spaces, and removes it if it is. It doesn't do anything for the first iteration of the test case.
This is necessary (at least until I find an alternative) since otherwise we'll eventually be unfurling whitespace into our output string.
### unfurl
```
|."1@(whitespace_filter @: unfurl_reversed) ^: (1 < #) ^: a:
```
Unfurl basically puts the other functions together and special cases single character inputs.
When the power of verb (`^:`) is given the empty box (`a:`), it applies a function on an input until it converges and collects the results in an array.
`(1 < #)` checks that the rows are always greater than 1 (to special case 1 row inputs).
`|."1` reverses each row, so it inverts the results of `whitespace_filter @: unfurl`.
[Answer]
# [Python 2](https://docs.python.org/2/), ~~143~~ 132 bytes
```
a=input()
while 1:print'\n'.join(a);b=map(''.join,zip(*map(str.strip,a[-2::-1])));a[-1]+=b.pop();a[:-1]=[len(a[0])*' '+x for x in b]
```
[Try it online!](https://tio.run/##NYzJCsIwGITvPkVuSWpbbI8tObjvyz3mkEKlkZr81IjVl4@J4sDANzMw8LKN0blzkikND0vo4NmotkZZAZ3SFp81Tq9GaSJpWbGbBIJ/RfxWQKJQ3G2XeiuIJU/yokgyQSktfcjEkFUpGCAhhoHxtvZffCRohBEe9uhiOtQjpVElnOMYee22GxyjL@5P6z8ejquA48l0Nl8ssfgA "Python 2 – Try It Online")
In each iteration, `b` is the “head” of the string (first n−1 rows), rotated 90 degrees: if `a` is `[" NML", " OPK", "ABCDEFGHIJ"]` then `b` is `["ON", "PM", "KL"]`.
To unfurl a string once, we append the final line of `b` to `a[-1]` (giving `"ABCDEFGHIJKL"`) and then recompute `a[:-1]` by adding spaces to the rest of the strings in `b`.
We terminate by attempting to pop from `b` when it’s empty.
# [Python 2](https://docs.python.org/2/), 132 bytes
```
a=input()
while 1:s=str.strip;print'\n'.join(a);a[:-1]=[len(a[0])*' '+''.join(x)for x in zip(*map(s,a[-2::-1]))];a[-1]+=s(a.pop(-2))
```
[Try it online!](https://tio.run/##NYzJDsIgGITvPgW3H7rF9tiGg/u@3JEDh5piKpCCsfrySI1OMsk3ycyYl2u0KrwXVCrzcJiMno1sa5SXllrXZcHSVKaTysFFQXbTUmFBKsHKNOeUtXWIbMxJBAhi@BV6ctUd6pFU6C0Nju7CYJsIlhblMCOEh4MAMbVYZEYbnBaEeM8ABe13W0jQFw/nzR@Pp/WAk@lsvliugH8A "Python 2 – Try It Online")
Same idea, written differently. We terminate by attempting to `a.pop(-2)` when `a` has only one element.
[Answer]
# [Perl 5](https://www.perl.org/), 155 bytes
```
$"=$,;@a=map[/./g],<>;while(@a){say' 'x(length$s)."@$_"for@a[0..@a-2];say$s.="@{pop@a}";say@b=();for$i(0..$#a){$q=0;$b[$q++][$#a-$i]=$_ for@{$a[$i]}}@a=@b}
```
[Try it online!](https://tio.run/##FY5dC4IwGEbv@xWyXlAxpwVercXbd130C8aQCaaC5fyACvGvt9blczgcHp13dWIMEA4Lhoo/lBYRjQq5WG/Yq6zq3EPlj736uI779ur8WQwl9D4lCCm5Nx0qEVOKKlxJZi3oKSc46kajmsifYMY9n1kTKs@aMLc5aHnMIBPQBoEUFoVQSQ6p8w@OoISd02TvYDYZcz4dZ5frYbbd7b@NHqrm2ZvwltB4Gf8A "Perl 5 – Try It Online")
Saved a few bytes without really modifying the logic. The flow below is still basically correct.
~~# [Perl 5](https://www.perl.org/), 163 bytes~~
```
$"=$,;@a=map[/./g],<>;while(@a){say' 'x(length$s)."@{$a[$_]}"for 0..@a-2;say$s.="@{pop@a}";say@b=();for$i(0..$#a){$b[$_][$#a-$i]=$a[$i][$_]for 0..$#{$a[$i]}}@a=@b}
```
[Try it online!](https://tio.run/##LY7dCoIwFIDvfQqZB1TQaYFXtlj/ddETyIgJpgPToUKF7NVbG3V3@M53Po6shjbTGhCBKKecPLgsEpzULFqt82cj2iqgPJxH/vZd/xW0VVdPDYwhRnQGXsCNKXTvBzfFmPJ4mRsRRkzMVvaScoUsoSUJwtxoIAIjgmeKUNrjwswxCEZsSzCL/jXw5h9TyrxFS6X16Xhwzpe9s9nuPr2cRN@NOr5mOF2kXw "Perl 5 – Try It Online")
**How?**
```
$"=$,; #set the array output separator to null
@a=map[/./g],<>;   # take the input as a 2-D array @a
while(@a){         # repeat while there are still things to unfurl
  say' 'x(length$s)."@{$a[$_]}"for 0..@a-2; # output all but last
                                            # line of the remaining
                                            # square
  say$s.="@{pop@a}";  # remove bottom row, add it to the unfurled string $s
                      # and output it
  say@b=();           # clear temporary array; output empty array, causing
                      # a newline to output
                      # rotate remaining shape 90 degrees:
  for$i(0..$#a){$b[$_][$#a-$i]=$a[$i][$_]for 0..$#{$a[$i]}}
  @a=@b               # replace input with rotated array
}
```
]