function donut(action)
% DONUT Displays a donut shape for lighting example.

%   $Revision: 1.9 $
%   Copyright (c) 1984-98 by The MathWorks, Inc. All Rights Reserved
%   $Date: 1998/10/16 23:07:35 $

if nargin <1 
  action = 'initialize';
end
figpos = getfgpos(450, 450);

if strcmp(action, 'initialize')
  
  fig = figure('Numbertitle', 'Off',...
               'Visible', 'off',...
               'Name', 'Lighting of a donut',...
               'Position', figpos,...
               'resize', 'off');
  [X,Y,Z]=sphere(60); [Phi,Theta]=cart2sph(X,Y,Z);
  R=cos(Theta); [X,Y,Z]=sph2cart(Phi,Theta,R);
  Z(30:40,30:40)=ones(11,11)*nan;
  z=plot3([0 0],[0 0],[-.7 .7],'r','linewidth',3);
  hold on
  axis('square'),axis([-1 1 -1 1 -1 1]),grid on
  y=plot3([0 0],[-1.05 1.05],[0 0],'r','linewidth',3);
  x=plot3([-1.05 1.05],[0 0],[0 0],'r','linewidth',3);
  colormap bone; colormap(cool)
  h=surf(X,Y,Z);
  axis([-1.05 1.05 -1.05 1.05 -.75 .75]);
  l=light;set(l,'Position',[2 2 2])
  view(145,20)
  axis vis3d;
  set(gca, 'DataAspectRatio', [1 1 1]);
  axis square;
  axis off;
  set(gcf, 'Color', [1 1 1]);
  %  The frame
  ypos = .05;
  frm = uicontrol('Style','frame',...
      'BackGroundColor', [.3 .3 .3],...
      'Units', 'Normalized', 'Position', [.78 ypos .14 .16]);
  
  % The Close button
  closebtn = uicontrol('Style', 'push',...
      'Units', 'Normalized', 'Position', [.8 ypos+.02 .1 .05],...
      'String', 'Close','callback', 'close');
  
  % The info button
  infobtn =  uicontrol('Style', 'push',...
      'Units', 'Normalized', 'Position', [.8 ypos+.09 .1 .05],...
      'String', 'Info','callback', 'donut(''info'')');
  
  % The Text
  figcolor = get(fig, 'color');
  txt = uicontrol('Style', 'text',...
      'Units', 'Normalized', 'Position', [.23 .88 .55 .1],...
      'BackGroundColor', figcolor',...
      'fontsize', 14,'Fontweight', 'bold',...
      'String', 'Lighting Example');
  
  txt2 =uicontrol('Style', 'text',...
      'Units', 'Normalized', 'Position', [.15 .87 .7 .05],...
      'BackGroundColor', figcolor',...
      'Fontsize', 14,...
      'String', 'Use the Mouse to rotate the object');
 rotate3d on; 
 set(fig, 'Visible','on');
elseif strcmp(action, 'info')
  
  ttl = 'Lighting Example';
  
  str = {' '
  'This example demonstrates MATLAB''s capabilities'
  'in lighting objects. Here the light is placed in a position'
  'so that for certain angles, the inside of the object looks brighter'
  'than the outside.'
  ' '
  ' '
  'Use the mouse to rotate and view different angles of the'
  'object.' 
  ' '
  'Filename: donut.m'
  ' '
  ' '};
  helpwin(str, ttl);
end

