function transpdemo(action);
%TRANSPDEMO Demonstrates Transparency in MATLAB.
%   This window lets you see transparency graphics 
%   in MATLAB by simply pushing the buttons on the 
%   right side of the window. The commands that 
%   generate the plots are shown in the MiniCommand 
%   Window.                   
%
%   If you like, you can even directly edit the  
%   commands in the MiniCommand Window.          
%   Type control-return to execute code in the   
%   MiniCommand Window. 
%
%   See also ALPHA, ALPHAMAP, ALIM.

%   Copyright 1984-2000 The MathWorks, Inc. 
%   $Revision: 1.3 $  $Date: 2000/09/08 19:21:22 $


if nargin<1,
    action='initialize';
end

if strcmp(action,'initialize'),
    figNumber=figure( ...
        'Name','Examples of transparency graphics in MATLAB', ...
        'NumberTitle','off', ...
        'Visible','off',...
	'doublebuffer','on');    
    axes( ...
        'Units','normalized', ...
        'Position',[0.10 0.45 0.60 0.45]);
 
    %===================================
    % Set up the MiniCommand Window
    top=0.35;
    left=0.05;
    right=0.75;
    bottom=0.05;
    labelHt=0.05;
    spacing=0.005;
    promptStr=str2mat(' ',' % Press the buttons at the right to see', ...
        ' % examples of transparency graphics in MATLAB');
    % First, the MiniCommand Window frame
    frmBorder=0.02;
    frmPos=[left-frmBorder bottom-frmBorder ...
        (right-left)+2*frmBorder (top-bottom)+2*frmBorder];
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
        'BackgroundColor',[0.50 0.50 0.50]);
    % Then the text label
    labelPos=[left top-labelHt (right-left) labelHt];
    uicontrol( ...
        'Style','text', ...
        'Units','normalized', ...
        'Position',labelPos, ...
        'BackgroundColor',[0.50 0.50 0.50], ...
        'ForegroundColor',[1 1 1], ...
        'String','MiniCommand Window');
    % Then the editable text field
    mcwPos=[left bottom (right-left) top-bottom-labelHt-spacing];
    mcwHndl=uicontrol( ...
        'Style','edit', ...
        'HorizontalAlignment','left', ...
        'Units','normalized', ...
        'Max',10, ...
        'BackgroundColor',[1 1 1], ...
        'Position',mcwPos, ...
        'Callback','transpdemo(''eval'')', ...
        'String',promptStr);
    % Save this handle for future use
    set(gcf,'UserData',mcwHndl);

    %====================================
    % Information for all buttons
    labelColor=[0.8 0.8 0.8];
    top=0.95;
    left=0.80;
    btnWid=0.15;
    btnHt=0.08;
    % Spacing between the button and the next command's label
    spacing=0.03;

    %====================================
    % The CONSOLE frame
    frmBorder=0.02;
    yPos=0.05-frmBorder;
    frmPos=[left-frmBorder yPos btnWid+2*frmBorder 0.9+2*frmBorder];
    uicontrol( ...
        'Style','frame', ...
        'Units','normalized', ...
        'Position',frmPos, ...
        'BackgroundColor',[0.50 0.50 0.50]);
    
	    
    %====================================
    % The simple button
    btnNumber=1;
    yPos=top-(btnNumber-1)*(btnHt+spacing);
    labelStr='Simple';
    callbackStr='transpdemo(''grafbutton'')';
    cmdStr=str2mat( ...
       'membrane',...
	   'alpha(.5)'...
	   );
    
    % Generic button information
    btnPos=[left yPos-btnHt btnWid btnHt];
    uicontrol( ...
        'Style','pushbutton', ...
        'Units','normalized', ...
        'Position',btnPos, ...
        'String',labelStr, ...
        'Callback',callbackStr, ...
        'UserData',cmdStr);
	
    %====================================
    % The isosurface button
    btnNumber=2;
    yPos=top-(btnNumber-1)*(btnHt+spacing);
    labelStr='Isosurface';
    callbackStr='transpdemo(''grafbutton'')';
    cmdStr=str2mat( ...
     	'load wind;',...
		'spd = sqrt(u.*u + v.*v + w.*w);',...
		'daspect([1 1 1]);',...	
		'p = patch(isosurface(x,y,z,spd,40));',...
		'isonormals(x,y,z,spd,p);',...
		' set(p,''FaceColor'',''red'',''EdgeColor'',''None'',''FaceAlpha'',.3);',...
    	' p = patch(isosurface(x,y,z,spd,45));',...
		' isonormals(x,y,z,spd,p);',...
		' set(p,''FaceColor'',''cyan'',''EdgeColor'',''None'',''FaceAlpha'',.5);',...
    	' axis tight; box on',...
    	' camproj perspective; camva(5); ',...
 		' campos([-125 230 275]); camtarget([100 35 10])',...
		' camlight left; lighting gouraud'...
    );
    
    % Generic button information
    btnPos=[left yPos-btnHt btnWid btnHt];
    uicontrol( ...
        'Style','pushbutton', ...
        'Units','normalized', ...
        'Position',btnPos, ...
        'String',labelStr, ...
        'Callback',callbackStr, ...
        'UserData',cmdStr);

    %====================================
    % The texture map button
    btnNumber=3;
    yPos=top-(btnNumber-1)*(btnHt+spacing);
    labelStr='Texture map';
    callbackStr='transpdemo(''grafbutton'')';
    cmdStr=str2mat( ...
   		' load topo;', ...
		' [x y z] = sphere(15);', ...
		' s = surface(x,y,z,''facecolor'',''texture'',''cdata'',topo);', ...
		' set(s,''edgecolor'',''none'',''facealpha'',''texture'',''alphadata'',topo);', ...
		' set(s,''backfacelighting'',''unlit'');',...
	 	' colormap(topomap1); alpha(''direct''); alphamap([.1;1])', ...
		' axis off vis3d; campos([2 13 10]); camlight; lighting gouraud;'...
    );
    
    % Generic button information
    btnPos=[left yPos-btnHt btnWid btnHt];
    uicontrol( ...
        'Style','pushbutton', ...
        'Units','normalized', ...
        'Position',btnPos, ...
        'String',labelStr, ...
        'Callback',callbackStr, ...
        'UserData',cmdStr);
	
	%====================================
		
    % The INFO button
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'Position',[left bottom+btnHt+spacing btnWid btnHt], ...
        'String','Info', ...
        'Callback','transpdemo(''info'')');

    %====================================
    % The CLOSE button
    uicontrol( ...
        'Style','push', ...
        'Units','normalized', ...
        'Position',[left bottom btnWid btnHt], ...
        'String','Close', ...
        'Callback','close(gcf)');

    % Now uncover the figure
    set(figNumber,'Visible','on');
   
elseif strcmp(action,'grafbutton'),
    cla reset;
    cmdStr=get(gco,'UserData');
    mcwHndl=get(gcf,'UserData');
    set(mcwHndl,'String',cmdStr);
    evalmcw(mcwHndl);
    
    drawnow;
    if ~strcmpi(get(gcf,'Renderer'),'OpenGL')
      errordlg('This demo requires OpenGL to look correct.');
    end

elseif strcmp(action,'eval'),
    cla reset;
    mcwHndl=get(gcf,'UserData');
    evalmcw(mcwHndl);

elseif strcmp(action,'info'),
    helpwin(mfilename);  

end;    % if strcmp(action, ...
