% Draw 5 user-selected rectangles, then color the biggest one red.

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')
n= 5; % number of rectangles

% Draw n rectangles
biggest= 0;
for k= 1:n
% get points from user
[x1,y1]= ginput(1);
[x2,y2]= ginput(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
drawRect(xLL, yLL, width, height, 'y')
% is it the biggest so far?
if area>biggest
biggest= area;
bx= xLL; by= yLL;
bw= width; bh= height;
end
end

% Draw red (biggest) rectangle
drawRect(bx, by, bw, bh, 'r')
title('Here''s the biggest rectangle you drew!')

hold off