No BSD License  

Highlights from
Pause / Resume

image thumbnail
from Pause / Resume by Roy Schestowitz
Pausing and resuming tasks.

prdemo(varargin)
function varargout = prdemo(varargin)
% PRDEMO: callback functions for GUI
%
%    ABOUT
%
%      -Created:     January 2004
%      -Last update: February 13th, 2004
%      -Revision:    0.0.5
%      -Author:      R. S. Schestowitz, University of Manchester
% ==============================================================

gui_Singleton = 0;
gui_State = struct('gui_Name',       mfilename, ...
    'gui_Singleton',  gui_Singleton, ...
    'gui_OpeningFcn', @prdemo_OpeningFcn, ...
    'gui_OutputFcn',  @prdemo_OutputFcn, ...
    'gui_LayoutFcn',  [] , ...
    'gui_Callback',   []);
if nargin & isstr(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end

% ==================================================================== %  

function prdemo_OpeningFcn(hObject, eventdata, handles, varargin)

% Choose default command line output for prdemo
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

if strcmp(get(hObject,'Visible'),'off')
    initialize_gui(hObject, handles);
end

set(handles.pause, 'cdata', pausebutton);

set(handles.resume, 'cdata', resumebutton);

% ==================================================================== %  

function varargout = prdemo_OutputFcn(hObject, eventdata, handles)

% Get default command line output from handles structure
varargout{1} = handles.output;

% ==================================================================== %  

function pause = pausebutton

pause = iconize(imread('pause.jpg'));
pause(pause>240) = .69*255;

% ==================================================================== %   

function resume = resumebutton

resume = iconize(imread('resume.jpg'));
resume(resume>240) = .69*255;

% note the thresholding above

function out = iconize(a)

% Ack. to button demo.

[r,c,d] = size(a);
r_skip = ceil(r/25);
c_skip = ceil(c/25);

% Create the 25x25 icon

out = a(1:r_skip:end,1:c_skip:end,:); 

% ==================================================================== %   

function initialize_gui(fig_handle, handles)

set(handles.pause, 'Enable', 'on');
set(handles.resume, 'Enable', 'off');


% ==================================================================== % 

function pause_Callback(hObject, eventdata, handles)

set(handles.pause, 'Enable', 'off');
set(handles.resume, 'Enable', 'on');
figure(1);
uiwait;

% ==================================================================== % 

function resume_Callback(hObject, eventdata, handles)

set(handles.pause, 'Enable', 'on');
set(handles.resume, 'Enable', 'off');
figure(1);
uiresume;

% ==================================================================== % 

function rotate_Callback(hObject, eventdata, handles)

set(handles.rotate, 'Enable', 'off');
rotate_surface;


% ==================================================================== % 

function rotate_surface

% create some data

[X,Y] = meshgrid(1:50 * 5 + 2, -50 / 2 - 1:1:50 / 2);

for i = 1:5,
            Z(2:50 + 1,1 + i * 5) = randn(50,1)+4;
            Z(2:50 + 1,1 + i * 5 - 1) = randn(50,1)+4;
            Z(2:50 + 1,1 + i * 5 - 2) = randn(50,1)+4;
            Z(2:50 + 1,1 + i * 5 - 3) = randn(50,1)+4;
            Z(2:50 + 1,1 + i * 5 - 4) = randn(50,1)+4;
end

Z(:,1) = zeros(1:50, 1);
Z(:, 5 * 5 + 2) = zeros(1:50, 1);
Z(1,:) = zeros(1, 1:5 * 5);
Z(50 + 2,:) = zeros(1, 1:50 * 5);    


figure(1);
axis off;

for current_viewpoint=1:720,
       % do two rotations
            view(current_viewpoint, 60); 
            surface(X(:,1:27),Y(:,1:27),Z, ...
              'EdgeColor','none', ...
              'FaceColor',[0.5 0.5 0.5], ...
              'FaceLighting','phong', ...
              'AmbientStrength',0.3, ...
              'DiffuseStrength',0.6, ... 
              'Clipping','off',...
              'BackFaceLighting','lit', ...
              'SpecularStrength',1.1, ...
              'SpecularColorReflectance',1, ...
              'SpecularExponent',7);
             l1 = light('Position',[40 20 100], ...
                  'Style','local', ...
                  'Color',[0 0.5 0.7]);
             l2 = light('Position',[.5 -1 .4], ...
                  'Color',[1 1 0]);
             pause(2);
end

Contact us at files@mathworks.com