% Script File: Smooth
%
% Solicits n, draws an n-gon, and then smooths it.
%
   close all
   n = input('Enter the number of edges:');
   plot([],[])
   title(sprintf('Click in %2.0f points.',n))
   axis([0 1 0 1])
   axis('square','equal')
   hold on
   x = zeros(n,1);
   y = zeros(n,1);
   for k=1:n
      [x(k) y(k)] = ginput(1);
	  plot(x(1:k),y(1:k), x(1:k),y(1:k),'*')
   end
   x = [x;x(1)];
   y = [y;y(1)];
   plot(x,y,x,y,'*')
   title('The Original Polygon') 
   hold off
   k=0;
   xlabel('Click anywhere in window to smooth.')  
   [a,b] = ginput(1);
   while (0<=a) & (a<=1) & (0<=b) & (b<=1);
	  k = k+1;
      x = [(x(1:n)+x(2:n+1))/2;(x(1)+x(2))/2];
	  y = [(y(1:n)+y(2:n+1))/2;(y(1)+y(2))/2];
	  figure
	  plot(x,y,x,y,'*')
	  axis([0 1 0 1])
	  axis('square','equal')
	  title(sprintf('Number of Smoothings = %1.0f',k)) 
      xlabel('Click anywhere in window to smooth.')  
      [a,b] = ginput(1);
 
   end
   

