[原创]Matlab模拟时针和数字时针

[记录数模集训期间Matlab的学习过程]

模拟时针


[原创]Matlab模拟时针和数字时针_第1张图片

clear,close all,clc
degree=[0:0.01:pi*2];
plot(cos(degree),sin(degree),'r-');
set(gca,'Xtick',[],'Ytick',[]);box on;
axis([-1.3 1.3 -1.3 1.3])
axis square
title('模拟时钟','Fontsize',22,'Fontname','华文行楷')
%时针刻度
for m=5*pi/2:-pi/6:pi/2
    a=line([9*cos(m)/10,cos(m)],[9*sin(m)/10,sin(m)],'color','r');
    if(m~=5*pi/2)
        text(17*cos(m)/20,17*sin(m)/20,int2str(12-(6*m-3*pi)/pi),'Fontsize',10,'Fontname','Times New Roman','Color','B','HorizontalAlignment','center');
    end
    pause(0.005)
end
text(0,-0.2,'CopyRight By D.C.','Fontsize',8,'Fontname','Times New Roman','Color','B','HorizontalAlignment','center');
%分针刻度
for n=0:pi/30:2*pi
    if mod(n,pi/6)~=0
        a=line([19*cos(n)/20,cos(n)],[19*sin(n)/20,sin(n)]);
    end
    pause(0.005)
end
clear m,clear n;
%秒针
while (1)
    timeNow=clock;
    timeN=[2*pi-timeNow(4:6)/30*pi+pi/2];
    %hou=2*pi-timeNow(5)/30*pi+pi/2;
    %mini=2*pi-timeNow(5)/30*pi+pi/2;
    %sec=2*pi-timeNow(6)/30*pi+pi/2;
    h=timeN(1);
    i=timeN(2);
    j=timeN(3);
    %画时针
    %ah=line([0,18*cos(h)/20],[0 18*sin(h)/20]);
    bh=line([1.5*cos(h+pi/2)/20 -3*cos(h)/20],[1.5*sin(h+pi/2)/20 -3*sin(h)/20]);
    ch=line([1.5*cos(h-pi/2)/20 -3*cos(h)/20],[1.5*sin(h-pi/2)/20 -3*sin(h)/20]);
    dh=line([1.5*cos(h+pi/2)/20 14*cos(h)/20],[1.5*sin(h+pi/2)/20 14*sin(h)/20]);
    eh=line([1.5*cos(h-pi/2)/20 14*cos(h)/20],[1.5*sin(h-pi/2)/20 14*sin(h)/20]);
    %画分针
    a=line([-4*cos(i)/20,17*cos(i)/20],[-4*sin(i)/20 17*sin(i)/20]);
    b=line([1*cos(i+pi/2)/20 -4*cos(i)/20],[1*sin(i+pi/2)/20 -4*sin(i)/20]);
    c=line([1*cos(i-pi/2)/20 -4*cos(i)/20],[1*sin(i-pi/2)/20 -4*sin(i)/20]);
    d=line([1*cos(i+pi/2)/20 17*cos(i)/20],[1*sin(i+pi/2)/20 17*sin(i)/20]);
    e=line([1*cos(i-pi/2)/20 17*cos(i)/20],[1*sin(i-pi/2)/20 17*sin(i)/20]);
    %画秒针
    f=line([-3*cos(j)/20,18*cos(j)/20],[-3*sin(j)/20 18*sin(j)/20]);
    %定时检测
    pause(1) 
    delete(bh),delete(ch),delete(dh),delete(eh)
    delete(a),delete(b),delete(c),delete(d),delete(e),delete(f)
end


 

----------------------------------------------------------------------可恶的分隔线----------------------------------------------------------------------------------

数字时针


[原创]Matlab模拟时针和数字时针_第2张图片

while 1
    c=clock;     
    axes('Position',[0.06,0.4,0.86,0.4]);
    title('数字时钟','Fontsize',22,'Fontname','华文行楷')
    set(gca,'Xtick',[],'Ytick',[]);box on;
    str=[int2strNew(c(4)),':',int2strNew(c(5)),':',int2strNew(c(6))];
    Ts=text(0.5,0.5,str,'Fontsize',80,...
    'Fontname','Times New Roman','Color','B',...
    'HorizontalAlignment','center');
    pause(1)
    clf
end

%---------------------------------

%int2strNew.m

%----------------------------------

function y=int2strNew(a)
if size(int2str(a),2)==1   
    y=['0',int2str(a)];
else
     y=int2str(a);
end


 

%----------------------------------------------------------可恶的分隔线--------------------------------------------------------------

                                                                                                                          CopyRight By D.C.  2011.7.22 0:21

                                                                                                                           转载请注明出处

你可能感兴趣的:(c,matlab,delete,plot)