clear all ; close all ; clc

xmin = -5;
xmax = +5;

% A = [1 1 ; 0 1];
A = [2 1 ; 1 3];

% while true
%theta = input('enter an angle (-1 to quit): ');
%if theta == -1
%    break;
%end
for theta = 0:5:360

v1 = [cosd(theta) ; sind(theta)];
v2 = [cosd(theta+90) ; sind(theta+90)];
u1 = A*v1;
u2 = A*v2;

subplot(1,2,1);
fill([0 v1(1) v1(1)+v2(1) v2(1)] , ...
     [0 v1(2) v1(2)+v2(2) v2(2)], 'r');
hold on;
    for x = (2*xmin):(2*xmax)
        if x == 0
            plot([2*xmin*v1(1) 2*xmax*v1(1)] , ...
                 [2*xmin*v1(2) 2*xmax*v1(2)] , ...
                 'k' , 'LineWidth' , 2);
            plot([2*xmin*v2(1) 2*xmax*v2(1)] , ...
                 [2*xmin*v2(2) 2*xmax*v2(2)] , ...
                 'k' , 'LineWidth' , 2);
        else    
            plot(2*v1(1)*[xmin xmax] + x * v2(1) , ...
                 2*v1(2)*[xmin xmax] + x * v2(2) , 'k');
            plot(2*v2(1)*[xmin xmax] + x * v1(1) , ...
                 2*v2(2)*[xmin xmax] + x * v1(2) , 'k');
        end
    end
hold off;
box on;
axis equal;
xlim([xmin xmax]);
ylim([xmin xmax]);
title(sprintf('theta = %d' , theta));

subplot(1,2,2);
fill([0 u1(1) u1(1)+u2(1) u2(1)] , ...
     [0 u1(2) u1(2)+u2(2) u2(2)], 'r');
hold on;
    for x = (2*xmin):(2*xmax)
        if x == 0
            plot([2*xmin*u1(1) 2*xmax*u1(1)] , ...
                 [2*xmin*u1(2) 2*xmax*u1(2)] , ...
                 'k' , 'LineWidth' , 2);
            plot([2*xmin*u2(1) 2*xmax*u2(1)] , ...
                 [2*xmin*u2(2) 2*xmax*u2(2)] , ...
                 'k' , 'LineWidth' , 2);
        else    
            plot(2*u1(1)*[xmin xmax] + x * u2(1) , ...
                 2*u1(2)*[xmin xmax] + x * u2(2) , 'k');
            plot(2*u2(1)*[xmin xmax] + x * u1(1) , ...
                 2*u2(2)*[xmin xmax] + x * u1(2) , 'k');
        end
    end
hold off;
box on;
axis equal;
xlim([xmin xmax]);
ylim([xmin xmax]);
drawnow();
input('<press enter>');
end
