function varargout = clockv2(varargin)
% CLOCKV2 M-file for clockv2.fig
% CLOCKV2, by itself, creates a new CLOCKV2 or raises the existing
% singleton*.
%
% H = CLOCKV2 returns the handle to a new CLOCKV2 or the handle to
% the existing singleton*.
%
% CLOCKV2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CLOCKV2.M with the given input arguments.
%
% CLOCKV2('Property','Value',...) creates a new CLOCKV2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before clockv2_OpeningFunction gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to clockv2_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 clockv2
% Last Modified by GUIDE v2.5 30-May-2007 09:06:11
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @clockv2_OpeningFcn, ...
'gui_OutputFcn', @clockv2_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 clockv2 is made visible.
function clockv2_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 clockv2 (see VARARGIN)
% Choose default command line output for clockv2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
handles.Line = line('parent',handles.myAxes,'Color','Black','LineWidth',2);
handles.HLine = line('parent',handles.myAxes,'Color','Blue','LineWidth',2);
handles.MLine = line('parent',handles.myAxes,'Color','Green','LineWidth',2);
handles.SLine = line('parent',handles.myAxes,'Color','Red','LineWidth',2);
set(handles.myAxes,'XTick',[],'YTick',[],'Visible','off','XLim',[-15 15],'YLim',[-15 15]);
set(handles.checkbox2, 'Value', 1);
t1=timer('Period',1);
set(t1,'TimerFcn',{@timerfcn,handles},'ExecutionMode','fixedDelay');
start(t1)
hObject=handles.text3;
t2=timer('Period',1);
set(t2,'TimerFcn',{@timerfcn2,handles},'ExecutionMode','fixedDelay');
start(t2)
set(handles.figure1,'closerequestfcn',{@clsfcn, t1, t2})
% UIWAIT makes clockv2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = clockv2_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;
function timerfcn(t1,event,handles)
clock_value=fix(clock);
H=clock_value(4);
M=clock_value(5);
S=clock_value(6);
thetaH=pi/2-(H-12)/12*2*pi;
thetaM=pi/2-M/60*2*pi;
thetaS=pi/2-S/60*2*pi;
R=10;
RH=5;
RM=2;
RS=1;
cx=0;
cy=0;
cxH=(R-RH)*cos(thetaH);
cyH=(R-RH)*sin(thetaH);
cxM=cxH+(RH-RM)*cos(thetaM);
cyM=cyH+(RH-RM)*sin(thetaM);
cxS=cxM+(RM-RS)*cos(thetaS);
cyS=cyM+(RM-RS)*sin(thetaS);
[X,Y]=circle_data(cx,cy,R);
[HX,HY]=circle_data(cxH,cyH,RH);
[MX,MY]=circle_data(cxM,cyM,RM);
[SX,SY]=circle_data(cxS,cyS,RS);
set(handles.Line,'XData',X,'YData',Y);
set(handles.HLine,'XData',HX,'YData',HY,'Color','Blue','LineWidth',2);
set(handles.MLine,'XData',MX,'YData',MY,'Color','Green','LineWidth',2);
set(handles.SLine,'XData',SX,'YData',SY,'Color','Red','LineWidth',2);
%line1=plot(X,Y,HX,HY,MX,MY,SX,SY);
%set(hObject,'Children',line1)
drawnow
function timerfcn2(t2,event,handles)
clock_value = fix(clock);
H=num2str(clock_value(4));
M=num2str(clock_value(5));
S=num2str(clock_value(6));
if (length(S)==1)
S=['0' S];
end
if (length(M)==1)
M=['0' M];
end
if (length(H)==1)
H=['0' H];
end
set(handles.text3,'String',[H ':' M ':' S],'FontSize',18,'FontWeight','Bold');
function clsfcn (src, evnt, t1, t2)
stop (t1);
stop (t2);
delete (gcf);
% --- Executes on button press in checkbox2.
function checkbox2_Callback(hObject, eventdata, handles)
% hObject handle to checkbox2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if get(hObject,'Value')
set(findobj('Color','Red'), 'Visible', 'on');
else
set(findobj('Color','Red'), 'Visible', 'off');
end
% Hint: get(hObject,'Value') returns toggle state of checkbox2