%animates the Dragon curve fractal
clf; %clears the figure
C=[0 1; 0 0]; %start with two points: (0,0) and (1,0)
r = 1/2;
M1 = [r r; -r r]; %rotate 45 degrees clockwise and shrink
M2 = [-r r;-r -r]; %rotate 135 degrees clockwise and shrink
for i = 1:20
    L = M1*C; 
    R = M2*C + [ones(1,length(C)); zeros(1,length(C))]; %rotate and shift right
    R = fliplr(R); %gets the correct order of points
    C = [L R]; 
    plot(C(1,:),C(2,:)) %plots the curve 
    axis([-0.5 1.5 -1 0.5]); axis equal;
    pause(1);
end
 