"); //-->
figure(1)%画背景图案
title('电梯简易模型')
axis([0 18 0 21]) %定义坐标系
axis off
set (gcf,'doublebuffer','on')
line([0;18],[0;0],'color','b','linewidth',10)
text(16,1.5,'F1'); %画楼房第一层
line([10;18],[3;3],'color','b','linewidth',5)
text(16,4.5,'F2') %画楼房第二层
line([10;18],[6;6],'color','b','linewidth',5)
text(16,7.5,'F3') %画楼房第三层
line([10;18],[9;9],'color','b','linewidth',5)
text(16,10.5,'F4') %画楼房第四层
line([10;18],[12;12],'color','b','linewidth',5)
text(16,13.5,'F5') %画楼房第五层
line([10;18],[15;15],'color','b','linewidth',5)
text(16,16.5,'F6') %画楼房第六层
line([10;18],[18;18],'color','b','linewidth',5)
text(16,19.5,'F7') %画楼房第七层
line([7;18],[21;21],'color','b','linewidth',5)%画楼房房顶直线
line([10;10],[0;21],'color','b','linewidth',6)%画楼房电梯左侧竖线
line([7;7],[0;21],'color','b','linewidth',6) %画楼房电梯右侧竖线
head1=line(5.8,1,'color','r','linestyle','.','erasemode','xor','markersize',50)%画红色小球,并设定其位置
head2=line(5,1,'color','g','linestyle','.','erasemode','xor','markersize',50)%画绿色小球,确定其位置
head3=line(12,13,'color','y','linestyle','.','erasemode','xor','markersize',50)%画黄色小球
head4=line(12,10,[1,0,0],'linestyle','.','erasemode','xor','markersize',50)%画粉红色小球
gan1=line([7;10],[3;3],'color','b','linewidth',7)%画电梯顶
gan2=line([7;10],[0;0],'color','b','linewidth',7)%画电梯底座
for i="0:600"%设置运动速度
x1=5+0.005*i%设置红色小球水平方向的运动轨迹
x2=5.8+0.005*i%设置绿色小球水平方向的运动轨迹
set(head2,'xdata',x1)
set(head1,'xdata',x2)
drawnow
end
for i="0:300"
b1=3+0.05*i%设置电梯顶的运动轨迹
b2=0.05*i%设置电梯底座的运动轨迹
y1=1+0.05*i%设置红色和绿色小球竖直方向的运动轨迹
set(head1,'ydata',y1)
set(head2,'ydata',y1)
set(gan1,'ydata',[b1;b1])
set(gan2,'ydata',[b2;b2])
drawnow
end
for i="0:550"
x1=8+0.005*i%设置红色小球的运动轨迹
set(head1,'xdata',x1)
drawnow
end
for i="0:60"
b1=18+0.05*i%设置电梯顶的运动轨迹
b2=15+0.05*i%设置电梯底座的运动轨迹
y1=16+0.05*i%设置绿色小球竖直方向的运动轨迹
set(head2,'ydata',y1)
set(gan1,'ydata',[b1;b1])
set(gan2,'ydata',[b2;b2])
drawnow
end
for i="0:550"
x2=8+0.005*i%设置绿色小球水平方向的运动轨迹
set(head2,'xdata',x2)
drawnow
end
for i="0:120"
b1=21-0.05*i%设置电梯顶的运动轨迹
b2=18-0.05*i%设置电梯底座的运动轨迹
set(gan1,'ydata',[b1;b1])
set(gan2,'ydata',[b2;b2])
drawnow
end
for i="0:640"
x3=12-0.005*i%设置黄色小球水平方向的运动轨迹
set(head3,'xdata',x3)
drawnow
end
for i="0:60"
b1=15-0.05*i%设置电梯顶的运动轨迹
b2=12-0.05*i%设置电梯底座的运动轨迹
y=13-0.05*i%设置黄色小球竖直方向的运动轨迹
set(head3,'ydata',y)
set(gan1,'ydata',[b1;b1])
set(gan2,'ydata',[b2;b2])
drawnow
end
for i="0:800"
x4=12-0.005*i%设置粉红色小球水平方向的运动轨迹
set(head4,'xdata',x4)
drawnow
end
for i="0:180"
y=10-0.05*i%设置黄色和分红色小球竖直方向的运动轨迹
b1=12-0.05*i%设置电梯顶的运动轨迹
b2=9-0.05*i%设置电梯底座的运动轨迹
set(head3,'ydata',y)
set(head4,'ydata',y)
set(gan1,'ydata',[b1;b1])
set(gan2,'ydata',[b2;b2])
drawnow
end
for i="0:480"
x3=8.8-0.005*i%设置黄色小球水平方向的运动轨迹
x4=8-0.005*i%设置分红色小球水平方向的运动轨迹
set(head3,'xdata',x3)
set(head4,'xdata',x4)
drawnow
end
*博客内容为网友个人发布,仅代表博主个人观点,如有侵权请联系工作人员删除。