The Image of the Dragon I saw a cool gif of the twin dragon curve made from a square, and wondered what would happen if we started from another base image.  So I wrote a program to do this.

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

It's so cool that I thought it would be fun to do it as a challenge.

Task

You will take in a square image with an edge length that is a power of 2 (greater than 4).

To make this image you should start by dividing your image into 4 vertical bands of equal size and shifting adjacent bands one 8th of the size of the image in opposite directions (shifted bands should wrap around to the other side).  You should then repeat this process each time splitting the image into twice as many divisions and shifting by half as far as the previous time.  Each iteration you should alternate between vertical and horizontal shifts.  You should iterate until the shift requires you to shift by a fractional number of pixels (this will always be 1/2) at which point you are done.

When shifting vertically odd numbered bands from the left (zero-indexed) should shift down while even shift up.  When shifting horizontally odd numbered bands from the top should shift left while even numbered bands should shift right.

You need only output/display the end result of the transformation, not all the intermediate steps like in the gif.

This is code-golf so the goal is to minimize the length of you source code as measured in bytes.

Worked through example

I will work through the cat gif shown at the top of the page frame by frame.

Here is the starting image:



This image is 512 by 512 pixels.  We will break it in 4 bands to start and shift each band by 1/8 the image size (64 pixels) vertically.



We will now divide it into twice as many bands (8 bands) and shift it half as far as last time (32 pixels).  This time we will shift horizontally.



We will now shift vertically again this time splitting into 16 bands and shifting each band by 16 pixels.



32 bands, 8 pixels, horizontal shift



64 bands, 4 pixels, vertical shift.



128 bands, 2 pixels, horizontal shift.



256 bands, 1 pixel, vertical shift.



Since the next shift would require us to move each band by half a pixel we will stop at this point and output the result.

Test cases

I have a working script that can make these images so I thought I would let you guys choose the images for the test cases.  So if you have a square image that is a power of 2 wide that you would like to see become dragonified.  Feel free to send it to me and I'll make it a test case.







You should also test on a plain white or solid black image so that you can determine whether or not pixels are disappearing or not.
MATLAB, 237 bytes

function A=r(A);n=size(A,1);p=@(a,v)permute(a,[v,3]);k=n/8;v=1:2;while k&gt;=1;b=mod(0:n-1,4*k)&lt;2*k;x=find(b);y=find(~b);c=[k+1:n,1:k;n-k+1:n,1:n-k];A=p(A,v);c=c(3-v,:);A(x,:,:)=A(x,c(1,:),:);A(y,:,:)=A(y,c(2,:),:);A=p(A,v);k=k/2;v=3-v;end


Took a little bit of guess work as I did not understand the procedure from the specs, but with the help of the image it worked.