📄 tiaosu.m
字号:
clear
speed = 100;
t = 0;
Y_a = 4;Y_b = 4;Y_c = 4;
y0 = figure;
axis equal;axis off
axis([-6 6 -10 6])
title('可调速电风扇','fontsize',15);
grid off;
[x1,y1,z1]=sphere(30);
x=5*x1;y=5*y1;z=5*z1;
shading interp;
hold on;
mesh(x,y,z),colormap(hot);
hold on;
hidden off;
hold on;
fill([-3,-1,1,3],[-8.5,-5,-5,-8.5],[0.5,0.5,0.5]);
text(-0.6,-6,'... ','color','k');
text(-1.2,-7,'@@@','color','k');
text(-1.8,-8,'###','color','k');
hold on
ax = Y_a * cos(2 * pi * t);ay = Y_a * sin(2 * pi * t);
bx = Y_b * cos(2 * pi * t - 2 * pi/3);by = Y_b * sin(2 * pi * t - 2 * pi/3);
cx = Y_c * cos(2 * pi * t + 2 * pi/3);cy = Y_c * sin(2 * pi * t + 2 * pi/3);
y_line_a = line([0 ax],[0 ay],'EraseMode','xor','Color','r','linestyle','-','linewidth',20);
y_line_b = line([0 bx],[0 by],'EraseMode','xor','Color','b','linestyle','-','linewidth',20);
y_line_c = line([0 cx],[0 cy],'EraseMode','xor','Color','g','linestyle','-','linewidth',20);
a(2,:) = linspace(2,6,2 * speed);
b = a;
c = a;
a(1,1) = ay;
b(1,1) = by;
c(1,1) = cy;
k=1;
b1=uicontrol('parent',y0,'units','points','tag','b2','style','pushbutton','string','停止','backgroundcolor',[0.75 0.75 0.75], 'position',[280 10 50 20],...
'callback','k=0;');
b2=uicontrol('parent',y0,'units','points','tag','b3','style','pushbutton','string','关闭','backgroundcolor',[0.75 0.75 0.75],'position',[350 10 50 20],...
'callback',['k=1;,','close']);
s1=uicontrol('parent',y0,'units','points','tag','s1','style','slider','value',1*speed, 'max',100,...
'min',30,'backgroundcolor',[0.75 0.75 0.75],'position',[30 10 190 20],'callback',[...
'm=get(gcbo,''value'');,',...
'speed=m/1;']);
t1=uicontrol('parent',y0,...
'units','points',...
'tag','t1',...
'style','text',...
'fontsize',15,...
'string','风速 请点击滑动条空白处',...
'backgroundcolor',[0.75 0.75 0.75],...
'position',[30 30 190 20]);
while 1
if k==0
break
end
t = t + 1/speed;
ax = Y_a * cos(2 * pi * t);ay = Y_a * sin(2 * pi * t);
bx = Y_b * cos(2 * pi * t - 2 * pi/3);by = Y_b * sin(2 * pi * t - 2 * pi/3);
cx = Y_c * cos(2 * pi * t + 2 * pi/3);cy = Y_c * sin(2 * pi * t + 2 * pi/3);
drawnow;
set(y_line_a,'XData',[0 ax],'YData',[0 ay]);
set(y_line_b,'XData',[0 bx],'YData',[0 by]);
set(y_line_c,'XData',[0 cx],'YData',[0 cy]);
for i = 1 : 2 * speed - 1;
a(1,2 * speed + 1 - i) = a(1,2 * speed - i);
b(1,2 * speed + 1 - i) = b(1,2 * speed - i);
c(1,2 * speed + 1 - i) = c(1,2 * speed - i);
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -