% Draw user-specified rectangles

close all
figure
axis ([0 1 0 1])
axis equal off
hold on

% Background
DrawRect(0,0,1,1,'k')
title('Make two clicks to paint a rectangle')

% get points from user
[x1,y1]= ginput(1);
[x2,y2]= ginput(1);
while  x1>=0 && x1<=1 && y1>=0 && y1<=1 && ...
       x2>=0 && x2<=1 && y2>=0 && y2<=1
    % properties of the indicated rectangle
      xLL= min(x1,x2);
      yLL= min(y1,y2);
      width= abs(x1-x2);
      height= abs(y1-y2);
      area= width*height;
    % draw rectangle
      if area>0
          DrawRect(xLL, yLL, width, height, 'y')
      end
    % get next set of points
      [x1,y1]= ginput(1);
      [x2,y2]= ginput(1);
end
title('No more rectangles')

hold off
