Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

ЛР2 / lazer

.m
Скачиваний:
10
Добавлен:
26.06.2022
Размер:
10.61 Кб
Скачать
function varargout = lazer(varargin)
% LAZER M-file for lazer.fig
% LAZER, by itself, creates a new LAZER or raises the existing
% singleton*.
%
% H = LAZER returns the handle to a new LAZER or the handle to
% the existing singleton*.
%
% LAZER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in LAZER.M with the given input arguments.
%
% LAZER('Property','Value',...) creates a new LAZER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before lazer_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to lazer_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help lazer

% Last Modified by GUIDE v2.5 14-Mar-2007 19:04:21

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @lazer_OpeningFcn, ...
'gui_OutputFcn', @lazer_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(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
% End initialization code - DO NOT EDIT


% --- Executes just before lazer is made visible.
function lazer_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to lazer (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes lazer wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = lazer_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

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


% --- Executes on button press in otv.
function otv_Callback(hObject, eventdata, handles)
% hObject handle to otv (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in start.
function start_Callback(hObject, eventdata, handles)
% hObject handle to start (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

set(handles.otv, 'Visible', 'on');
h = get(handles.otv, 'position');
x = get(handles.lazer, 'position');
h(1) = x(1)
y = get(handles.metal, 'position');
h(2) = y(1) + y(4) - 8;
h(3) = str2num(get(handles.D, 'String'));
h(4) = 1;

set(handles.otv, 'position', h);
N = str2num(get(handles.L, 'string')) - 8;
for i=1:N
h = get(handles.otv, 'position');
h(2) = h(2) - 1;
h(4) = h(4) + 1;
set(handles.otv, 'position', h);
pause(0.1);
if (ceil(i/2)-floor(i/2)) == 1
set(handles.lazer, 'visible', 'off');
else
set(handles.lazer, 'visible', 'on');
end;
set(handles.timer, 'string', num2str(i));

end;


% --- Executes on button press in togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)
% hObject handle to togglebutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton1





function D_Callback(hObject, eventdata, handles)
% hObject handle to D (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of D as text
% str2double(get(hObject,'String')) returns contents of D as a double
p = get(handles.lazer, 'position');
d = str2num(get(handles.D, 'string'));
if (d > 60)
d = 60;
set(handles.D, 'string', '60');
end
if (d < 10)
d = 10;
set(handles.D, 'string', '10');
end
p(3) = d;
s = get(handles.stanina, 'position');
p(1) = s(1) + (s(3)-d)/2;
set(handles.lazer, 'position', p);


% --- Executes during object creation, after setting all properties.
function D_CreateFcn(hObject, eventdata, handles)
% hObject handle to D (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end




% --- Executes on button press in lazer.
function lazer_Callback(hObject, eventdata, handles)
% hObject handle to lazer (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)




% --- Executes on button press in stanina.
function stanina_Callback(hObject, eventdata, handles)
% hObject handle to stanina (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)





function L_Callback(hObject, eventdata, handles)
% hObject handle to L (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of L as text
% str2double(get(hObject,'String')) returns contents of L as a double
L = str2num (get(handles.L, 'String'))

if (L < 50)
L = 50;
set(handles.L, 'string', '50');
end;
if (L > 200)
L = 200;
set(handles.L, 'string', '200');
end;
h = get(handles.metal, 'position');
h(4) = L;
set(handles.metal, 'position', h);



% --- Executes during object creation, after setting all properties.
function L_CreateFcn(hObject, eventdata, handles)
% hObject handle to L (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end





function W_Callback(hObject, eventdata, handles)
% hObject handle to W (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of W as text
% str2double(get(hObject,'String')) returns contents of W as a double


% --- Executes during object creation, after setting all properties.
function W_CreateFcn(hObject, eventdata, handles)
% hObject handle to W (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end



function r_Callback(hObject, eventdata, handles)
% hObject handle to r (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of r as text
% str2double(get(hObject,'String')) returns contents of r as a double


% --- Executes during object creation, after setting all properties.
function r_CreateFcn(hObject, eventdata, handles)
% hObject handle to r (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in podves.
function podves_Callback(hObject, eventdata, handles)
% hObject handle to podves (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)


% --- Executes on button press in move_left.
function move_left_Callback(hObject, eventdata, handles)
% hObject handle to move_left (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
p = get(handles.stanina, 'position');
if (p(1) > 50)
p(1) = p(1) - 2;
set(handles.stanina, 'position', p);
p = get(handles.lazer, 'position');
p(1) = p(1) - 2;
set(handles.lazer, 'position', p);
end

% --- Executes on button press in move_right.
function move_right_Callback(hObject, eventdata, handles)
% hObject handle to move_right (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
p = get(handles.stanina, 'position');
if (p(1) < 250)
p(1) = p(1) + 2;
set(handles.stanina, 'position', p);
p = get(handles.lazer, 'position');
p(1) = p(1) + 2;
set(handles.lazer, 'position', p);
end



Соседние файлы в папке ЛР2