function lighting(type)
%LIGHTING Lighting mode.
%   LIGHTING controls the lighting of SURFACE and PATCH objects.
%   SURFACE and PATCH objects are created by the functions SURF, MESH,
%   PCOLOR, FILL, and FILL3. 
%
%   LIGHTING FLAT sets the lighting of the current graph to flat.
%   LIGHTING GOURAUD sets the lighting to gouraud.
%   LIGHTING PHONG sets the lighting to phong.
%   LIGHTING NONE turns off lighting.
%
%   See also LIGHT, MATERIAL
 
%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.8 $  $Date: 1997/11/21 23:33:53 $


ax = gca;
fc = get(ax,'color');
if strcmp(lower(fc),'none')
  fc = get(gcf,'color');
end
kids = [findobj(ax,'type','surface'); findobj(ax,'type','patch')];
imesh = [];
isurf = [];
for i = 1:length(kids)
  face = get(kids(i),'facecolor');
  if strcmp(face,'none')
    imesh = [imesh ; kids(i)];
  elseif ~isstr(face)
    if (all(face == fc)) 
      imesh = [imesh ; kids(i)];
    else
      isurf = [isurf; kids(i)];
    end
  else
    isurf = [isurf; kids(i)];
  end
end

if (nargin == 0)
  error('Lighting methods are none, flat, gouraud, and phong.');
else
  if (strcmp(type, 'flat') | strcmp(type, 'f') )
    our_set(isurf,'facelighting','flat','edgelighting','none')
    our_set(imesh,'edgelighting','flat','facelighting','none')
  elseif (strcmp(type, 'gouraud')) | strcmp(type, 'g') 
    our_set(isurf,'facelighting','gouraud','edgelighting','none')
    our_set(imesh,'edgelighting','gouraud','facelighting','none')
  elseif (strcmp(type,'phong') | strcmp(type, 'p') )
    our_set(isurf,'facelighting','phong','edgelighting','none')
    our_set(imesh,'edgelighting','phong','facelighting','none')
  elseif (strcmp(type,'none') | strcmp(type, 'n') )
    our_set(isurf,'facelighting','none','edgelighting','none')
    our_set(imesh,'edgelighting','none','facelighting','none')
  else
    error('Lighting methods are none, flat, gouraud, and phong.');
  end
end

function our_set(h, p1, v1, p2, v2)

if (~isempty(h))
    set(h, p1, v1, p2, v2)
end

