TA的每日心情 | 衰 2019-11-19 15:32 |
|---|
签到天数: 1 天 [LV.1]初来乍到
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
2 }8 C5 `+ B9 D$ r, u7 `" i
一、简介1 y) }% s, r% e1 V# k" ~
基于matlab时钟设计
2 t/ G7 @4 o1 }9 V+ l: Y
3 y+ Z$ ?; }- [( m4 ?# R4 Z) O5 s) h: O ?
二、源代码5 a" w& P4 {0 ]2 \1 T5 l
8 z, |$ I1 U. B7 ^
- function timeCompass()
- %h_comaps = compass([x1;x2;x2],[y1;y2;y3])
- %x1y1 x2y2 x3y3 为三个指针向量 h_compass为句柄
- %%创建坐标轴做为显示表盘,并隐藏
- hAxes = axes('visible','off','DrawMode','fast');
- %%绘制表盘中心点
- hAxESDot = axes('Visible','off','DrawMode','fast');
- axis equal;
- line(0,0,'Parent',hAxesDot,'Marker','o','MarkeRFaceColor','k','MarkerSize',15)
- try
- while 1
- %%获取当前时间
- time = floor(clock); %向下取整 clock:将当前时间和日期返回到一个(6元)数组中。
- hour = time(4); % 2008 8 26 12 31 32.75
- min = time(5);
- sec = time(6);
- %fprintf(hour);
- argHour = pi/2 - (hour + min / 60) * pi / 6;
- argMin = pi/2 - (min + sec / 60) * pi / 30;
- argSec = pi/2 -sec * pi/30;
- %根据计算的指针弧度值创建表盘和指针
- hCompass = compass(hAxes,[0.5*cos(argHour);0.8*cos(argMin);cos(argSec)],[0.5*sin(argHour);0.8*sin(argMin);sin(argSec)]);
- set(hCompass,'LineWidth',3);%设置线宽
- set(hCompass(3),'LineWidth',1);%设置线宽
- set(hCompass(1),'Color','k');%时针红色
- set(hCompass(2),'Color','k');
- delete(findall(hAxes,'Type','text','-or','linestyle',':'));
- %%绘制数值
- ang = pi /3 ;
- for i=1:12
- if rem(i,3) %3d的倍数 字号12
- text(0.8*cos(ang),0.8*sin(ang),num2str(i),'horizontalAlignment','center','FontSize',12,'Parent',hAxes);
- else
- text(0.8*cos(ang),0.8*sin(ang),num2str(i),'horizontalAlignment','center','FontSize',20,'FontWeight','bold','Color','g','Parent',hAxes);
- end
- ang =ang -pi/6;
- end
9 c0 y; W: C; ] % Z4 F- D2 |, e8 y9 i
& V% ^1 P6 C1 j1 N# `( E+ b三、运行结果' \/ A9 i( S1 b4 O3 f' F+ i2 h
/ l" N6 ~. y% r: x1 k
! U" P+ V# L( I. G
: R( M% J. k& U* J" l! Z4 q0 E |
|