%% Matrix Transformations

% A pretty square
x = [0 0 1 1 0 0 1 1 0]; 
y = [0 1 0 1 1 0 0 1 0];
X = [x;y]

T = @(a) [cos(a) -sin(a); sin(a) cos(a)];

figure; hold on; axis([-2 2 -2 2]);
for i = pi*[0 1/4 1/2 3/4 1 1.25 1.5 1.75 2];
S = T(i)*X
fill(S(1,:),S(2,:),'b')
pause(.1);
drawnow;
end


V=S;

for j = 1:5
    figure; hold on; 
m = norm(S)/floor((.20+j^.5)); axis([-m m -m m]);

for i = pi*[0 1/4 1/2 3/4 1 1.25 1.5 1.75 2];
    S = T(i)*S;
    S = [V S+ones(size(S))];
fill(S(1,:),S(2,:),'b')
pause(.2);
drawnow;
end
%S = [V V + j^2*ones(size(V))];
end


% 
% % A ploygon
% t=[0:.5:1]'*2*pi;
% x=sin(t); y=cos(t);
% X = [x;y]
% S = T(pi/4)*X
% fill(S(1,:),S(2,:),'r')
% for i = pi*[0 1/4 1/2 3/4 1 1.25 1.5 1.75 2];
% S = T(i)*X
% fill(S(1,:),S(2,:),'r')
% pause;
% drawnow;
% end