%%%%%%%%%%%%%%%%%%%%%%%%%%
% Draw arrows on screen. %
%%%%%%%%%%%%%%%%%%%%%%%%%%
function arrow (degree)
 istep = 0;
 thisx = 0;
 thisy = 0;
 QUIT=0;
 hold on;
 fprintf(1, 'Arrow drawing program by Ju Li:\n');
 fprintf(1, 'Press right button to draw, press left button to quit.\n');
 while(1)
  [xnow ynow button] = ginput(1);
  if (button==1) 
    istep = istep+1;
    lastx = thisx;
    lasty = thisy;
    thisx = xnow;
    thisy = ynow;
  elseif (button==3)
    QUIT=1;
  end;
 if (istep==2)
  istep = 0;
  directionx = thisx - lastx;
  directiony = thisy - lasty;
  length = sqrt(directionx^2+directiony^2);
  normalx = -directiony / length;
  normaly =  directionx / length;
  length = tan(degree/2/180*pi) * length;
% plot ([lastx thisx],[lasty thisy]);
% fprintf(1,'plot ([%f %f],[%f %f]);\n',lastx,thisx,lasty,thisy); 
  plot ([lastx+length*normalx thisx],[lasty+length*normaly thisy]); 
  plot ([lastx-length*normalx thisx],[lasty-length*normaly thisy]); 
  fprintf(1,'plot ([%f %f],[%f %f]);\n',lastx+length*normalx,thisx,lasty+length*normaly,thisy); 
  fprintf(1,'plot ([%f %f],[%f %f]);\n',lastx-length*normalx,thisx,lasty-length*normaly,thisy); 
 end;
  if (QUIT==1) break; end;
 end;
end;
 
