英语翻译function clk% clf;shg;h=figure('menubar','none',...'color','white',...'position',[200 200 320 360],...'name','CLOCK');e1=uicontrol('parent',h,...'style','edit',...'fontsize',12,...'position',[110 20 120 30]);b1=uicontrol('parent',h,...'st
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/26 09:48:39
英语翻译function clk% clf;shg;h=figure('menubar','none',...'color','white',...'position',[200 200 320 360],...'name','CLOCK');e1=uicontrol('parent',h,...'style','edit',...'fontsize',12,...'position',[110 20 120 30]);b1=uicontrol('parent',h,...'st
英语翻译
function clk
% clf;shg;
h=figure('menubar','none',...
'color','white',...
'position',[200 200 320 360],...
'name','CLOCK');
e1=uicontrol('parent',h,...
'style','edit',...
'fontsize',12,...
'position',[110 20 120 30]);
b1=uicontrol('parent',h,...
'style','text',...
'string','12',...
'fontsize',12,...
'position',[156 275 20 20]);
b2=uicontrol('parent',h,...
'style','text',...
'string','9',...
'fontsize',12,...
'position',[60 175 20 20]);
b3=uicontrol('parent',h,...
'style','text',...
'string','6',...
'fontsize',12,...
'position',[156 75 20 20]);
b4=uicontrol('parent',h,...
'style','text',...
'string','3',...
'fontsize',12,...
'position',[260 175 20 20]);
s1=[0:pi/1000:2*pi];
hl=plot(cos(s1),sin(s1),'b-');
time=datestr(now);
set(e1,'string',time(1:11));
sita1=pi/2-str2num(time(19:20))*pi/30;
sita2=pi/2-str2num(time(16:17))*pi/30+sita1/60;
sita3=pi/2-str2num(time(13:14))*pi/6+sita2/12;
w1=-pi/30;
w2=-pi/1800;
w3=-pi/108000;
pausetime=1;
axis off;axis equal
hold on
plot(0,0,'or');
%设置刻度
for n=pi*2:-pi/30:pi/30
a1=0.95*cos(n):0.05*cos(n)/2:cos(n);b1=0.95*sin(n):0.05*sin(n)/2:sin(n);
plot(a1,b1,'r-');
end
for n=pi*2:-pi/6:pi/30
a1=0.9*cos(n):0.1*cos(n)/2:cos(n);b1=0.9*sin(n):0.1*sin(n)/2:sin(n);
plot(a1,b1,'r-');
end
%时钟指针
while 1
x1=0:0.75*cos(sita1)/2:0.75*cos(sita1);y1=0:0.75*sin(sita1)/2:0.75*sin(sita1);
x2=0:0.6*cos(sita2)/2:0.6*cos(sita2);y2=0:0.6*sin(sita2)/2:0.6*sin(sita2);
x3=0:0.45*cos(sita3)/2:0.45*cos(sita3);y3=0:0.45*sin(sita3)/2:0.45*sin(sita3);
hp1=plot(x1,y1,'b-');
hp2=plot(x2,y2,'b-','linewidth',2);
hp3=plot(x3,y3,'g-','linewidth',2);
sita1=sita1+w1*pausetime;
sita2=sita2+w2*pausetime;
sita3=sita3+w3*pausetime;
pause(pausetime);
delete(hp1);
delete(hp2);
delete(hp3);
end
hold off
英语翻译function clk% clf;shg;h=figure('menubar','none',...'color','white',...'position',[200 200 320 360],...'name','CLOCK');e1=uicontrol('parent',h,...'style','edit',...'fontsize',12,...'position',[110 20 120 30]);b1=uicontrol('parent',h,...'st
function clk
% clf;shg;
%创建一个图形界面
h=figure('menubar','none',...%取消菜单栏
'color','white',...%设成白色
'position',[200 200 320 360],...%初始创建显示的位置
'name','CLOCK'); %窗口名字
%创建一个用户界面控制对象
e1=uicontrol('parent',h,...%指定父对象为界面窗口
'style','edit',...%该对象为可编辑文本框
'fontsize',12,...%字号
'position',[110 20 120 30]);
b1=uicontrol('parent',h,...
'style','text',...%该对象为静态文本
'string','12',...%文本内容为‘12’点
'fontsize',12,...
'position',[156 275 20 20]);
b2=uicontrol('parent',h,...
'style','text',...
'string','9',...%‘9’点
'fontsize',12,...
'position',[60 175 20 20]);
b3=uicontrol('parent',h,...
'style','text',...
'string','6',...‘6’点
'fontsize',12,...
'position',[156 75 20 20]);
b4=uicontrol('parent',h,...
'style','text',...
'string','3',...‘3’点
'fontsize',12,...
'position',[260 175 20 20]);
s1=[0:pi/1000:2*pi]; %圆周角,从0到2PI
hl=plot(cos(s1),sin(s1),'b-'); %用蓝色实线画一个圆
time=datestr(now); %获取当前日期字符串
set(e1,'string',time(1:11)); %把日期设置给可编辑文本框,并显示日期
sita1=pi/2-str2num(time(19:20))*pi/30; %当前秒针所在的角度
sita2=pi/2-str2num(time(16:17))*pi/30+sita1/60; %当前分针所在的角度
sita3=pi/2-str2num(time(13:14))*pi/6+sita2/12; %当前时针所在的角度
w1=-pi/30; %每变化一秒钟秒针扫过的角度
w2=-pi/1800; %每变化一秒钟分针扫过的角度
w3=-pi/108000; %每变化一秒时秒针扫过的角度
pausetime=1; %刷新时间设为1秒
axis off;axis equal %隐藏坐标系,并设为XY等尺度
hold on
plot(0,0,'or'); %在圆心上(钟的中心)画一个圆点
%设置刻度
%画分钟的刻度,60个红色短线
for n=pi*2:-pi/30:pi/30
a1=0.95*cos(n):0.05*cos(n)/2:cos(n);
b1=0.95*sin(n):0.05*sin(n)/2:sin(n);
plot(a1,b1,'r-');
end
%画时针的刻度,12个红色短线
for n=pi*2:-pi/6:pi/30
a1=0.9*cos(n):0.1*cos(n)/2:cos(n);
b1=0.9*sin(n):0.1*sin(n)/2:sin(n);
plot(a1,b1,'r-');
end
%时钟指针
while 1
%秒针当前坐标
x1=0:0.75*cos(sita1)/2:0.75*cos(sita1);y1=0:0.75*sin(sita1)/2:0.75*sin(sita1);
%分针当前坐标
x2=0:0.6*cos(sita2)/2:0.6*cos(sita2);y2=0:0.6*sin(sita2)/2:0.6*sin(sita2);
%时针当前坐标
x3=0:0.45*cos(sita3)/2:0.45*cos(sita3);y3=0:0.45*sin(sita3)/2:0.45*sin(sita3);
hp1=plot(x1,y1,'b-'); %画秒针
hp2=plot(x2,y2,'b-','linewidth',2); %画分针
hp3=plot(x3,y3,'g-','linewidth',2); %画时针
%更新针的角度
sita1=sita1+w1*pausetime;
sita2=sita2+w2*pausetime;
sita3=sita3+w3*pausetime;
pause(pausetime); %暂停1秒
%删除上一秒的针
delete(hp1);
delete(hp2);
delete(hp3);
end
hold off