📄 smallball.m
字号:
function varargout = SmallBall(varargin)
% SMALLBALL M-file for SmallBall.fig
% SMALLBALL, by itself, creates a new SMALLBALL or raises the existing
% singleton*.
%
% H = SMALLBALL returns the handle to a new SMALLBALL or the handle to
% the existing singleton*.
%
% SMALLBALL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in SMALLBALL.M with the given input arguments.
%
% SMALLBALL('Property','Value',...) creates a new SMALLBALL or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before SmallBall_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to SmallBall_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
% Edit the above text to modify the response to help SmallBall
% Last Modified by GUIDE v2.5 22-Sep-2006 09:25:10
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @SmallBall_OpeningFcn, ...
'gui_OutputFcn', @SmallBall_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
global key
% --- Executes just before SmallBall is made visible.
function SmallBall_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 SmallBall (see VARARGIN)
% Choose default command line output for SmallBall
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes SmallBall wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = SmallBall_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;
h1 = line([0,1.05],-0.04*[1 1]);
set(h1,'linewidth',5);
h2 = line([0,1.05],1.04*[1 1]);
set(h2,'linewidth',7);
set(gca,'Visible','off','XLim',[0 1.05]);
h_main=gcf;
uu={[1 0 0], 0.05 0.5};
set(h_main,'userdata',uu);
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%set the speed of the smallball
global key
uu=get(gcf,'userdata');
switch key
case 1
uu{2}=uu{2}*0.5;
case 2
uu{2}=uu{2}*2;
case 3
uu{2}=0.05;
case 4
kk=get(findobj(gcf,'tag','lstcolor'),'value');
switch kk
case 1
uu{1}=[1 0 0];
case 2
uu{1}=[0 1 0];
case 3
uu{1}=[0 0 1];
end
end
set(gcf,'userdata',uu);
%Start the bouncing of the small ball
[x,y,k]=ginput(1);uu{3}=x;set(gcf,'userdata',uu);
if x<0, x=0.1;end
if x>1, x=1;end
xx=[0];yy=[1];x0=0;x1=x;y1=1;
while(x1<=1+x)
xx=[xx x1];y1=~y1;yy=[yy y1];x0=x1;x1=x1+x;
end
dx=1/50;xx_l=[0:dx:1,xx];xx_l=sort(xx_l);
yy_l=interp1(xx,yy,xx_l);
h_mark=line([0 1],[0 1]);
set(h_mark,'Marker','o','markersize',8,'color','g','tag','h_ball','linewidth',5);
set(h_mark,'color',uu{1});
line(xx_l,yy_l);
for i=1:length(xx_l)
x0=xx_l(i);
y0=yy_l(i);
set(h_mark,'xdata',x0,'ydata',y0);pause(uu{2});
end
% --- Executes on button press in rdradio1.
function rdradio1_Callback(hObject, eventdata, handles)
% hObject handle to rdradio1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global key
key=1;
h1=findobj(gcf,'tag','rdradio1');set(h1,'value',1);
h2=findobj(gcf,'tag','rdradio2');set(h2,'value',0);
h3=findobj(gcf,'tag','rdradio3');set(h3,'value',0);
% Hint: get(hObject,'Value') returns toggle state of rdradio1
% --- Executes on button press in rdradio2.
function rdradio2_Callback(hObject, eventdata, handles)
% hObject handle to rdradio2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global key
key=2;
h1=findobj(gcf,'tag','rdradio1');set(h1,'value',0);
h2=findobj(gcf,'tag','rdradio2');set(h2,'value',1);
h3=findobj(gcf,'tag','rdradio3');set(h3,'value',0);
% Hint: get(hObject,'Value') returns toggle state of rdradio2
% --- Executes on button press in rdradio3.
function rdradio3_Callback(hObject, eventdata, handles)
% hObject handle to rdradio3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global key
key=3;
h1=findobj(gcf,'tag','rdradio1');set(h1,'value',0);
h2=findobj(gcf,'tag','rdradio2');set(h2,'value',0);
h3=findobj(gcf,'tag','rdradio3');set(h3,'value',1);
% Hint: get(hObject,'Value') returns toggle state of rdradio3
% --- Executes on selection change in lstcolor.
function lstcolor_Callback(hObject, eventdata, handles)
% hObject handle to lstcolor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global key
key=4;
tempdata=get(hObject,'userdata');
uu{1}=tempdata;
% Hints: contents = get(hObject,'String') returns lstcolor contents as cell array
% contents{get(hObject,'Value')} returns selected item from lstcolor
% --- Executes during object creation, after setting all properties.
function lstcolor_CreateFcn(hObject, eventdata, handles)
% hObject handle to lstcolor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox 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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -