|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
: k, f$ }) o1 l7 p一、简介
0 W; I4 m' V, |5 P4 `
, g6 C3 h/ f& J0 q$ g3 t! { b) e1 设计背景7 Z. g. U. B' l. t2 M
6 H4 {2 v$ `$ Y5 }3 F2 g( u
我们设计这款可调速风扇,来自于日常的生活和自身的兴趣。常州是一个典型的江南城市,相比常州的酷热无比大家都已经经历过,尤其是在学校的日子,更是酷热难耐。基于此我们想到了这款可调速风扇。; R/ ]8 M$ c* j6 y' W) q) v
( P. p# s' C1 i% ~( R5 b2 \
" ~* f1 D$ v2 C7 g7 m, G2 总体构想% l, h; _+ }" _ W6 v9 |
$ _& N. S, E. R- t8 {$ h, H先做一个风扇的框架,画出三个叶片,然后通过时间的变化,来改变风扇叶片的位置坐标,从而风扇叶片就有了动起来的效果,风扇就转起来了。再做一个滑动条来实现变速功能,这样就是一个变速风扇的大概模型了。最终再加上一个定时功能,这样就基本完成了。2 j8 r) f' _; e
2 E, i; n9 k+ B9 ^7 Q4 H, w2 p
8 z5 c5 ?! s2 G二、源代码
% o$ x' X. L9 s3 ]4 }
8 p1 l# u/ B2 e& x2 D Z- clear;
- clc;
- global speed;
- global k;
- global h01;
- global m01; %定义全局变量,这样能将窗口是设定的数据返回到循环中去
- t_1=clock; %返回一个六个元素的十进制数值型矢量,包含当前的日期和时间[year month day hour minute seconds];
- h0=t_1(4); %设定时间初始化
- m0=t_1(5);
- speed = 100;
- t = 0;
- Y_a = 4;Y_b = 4;Y_c = 4;
- y0 = figure;
- axis equal;axis off
- set(gcf,'name','变速风扇'); %命名图像名称:变速风扇
- set(gcf,'NumberTitle','off'); %不显示图像编号
- set(gcf,'MenuBar','none'); %不显示菜单栏
- set(gcf,'doublebuffer','on') %开启双缓存,可以画面消除闪烁现象
- beijing=axes('units','normalized'); %获得轴的句柄。
- uistack(beijing,'bottom') ; %重新设置对象的位置,位置有:'up', 'down', 'top' or 'bottom'
- II=imread('bg.jpg');%II=imread('shiyan0.bmp'); %注意路径问题,更改此处的文件名即可改变背景图片。
- image(II); %显示图片
- set (gca,'position',[0,0,1,1] ); %设置坐标轴距离画板(图形窗口figure)边距。[0,0,1,1] 分别为axes在figure中的左边界,下边界,宽度,高度,最小为0,最大为1(左边界,下边界为0,上边界,右边界为1),这样可以铺满窗口。
- set(beijing,'handlevisibility','off','visible','off');
- axis([-6 6 -10 6])
- title('可调速电风扇','fontsize',15); %%%设置绘图名称
- grid off; %%%关闭绘图格点
- k=1;
- %%%%%%%%%%%%%%%%设置按键%%%%%%%%%%%%%%%%%%%%
- %%%%%%%%%设置确认按键%%%%%%%%%%
- %%%plot里的position [a b c d]确定绘图区域的位置, [a b]为绘图区域左下点的坐标。c,d分别为绘图区域的宽和高。[350 10 50 20]
- uicontrol(gcf,'style','Pushbutton','string','确认','Position',[420,50,50,20],'backgroundcolor',[0.75 0.75 0.75],'Callback','h01=str2num(get(D1,''string''));m01=str2num(get(D2,''string''));');
- %%%%%%设置取消按键%%%%%%%
- uicontrol(gcf,'style','Pushbutton','string','取消','Position',[475,50,50,20],'backgroundcolor',[0.75 0.75 0.75],'Callback','h01=0;m01=01;');
- %%%%%%%%%%设置时间编辑框%%%%%%
- D1=uicontrol(gcf,'style','Edit','string','00','Position',[320,50,50,20],'backgroundcolor',[0.75 0.75 0.75]);
- D2=uicontrol(gcf,'style','Edit','string','00','Position',[360,50,50,20],'backgroundcolor',[0.75 0.75 0.75]);
- %设置:静态文本框
- uicontrol(gcf,'style','text','string',':','Position',[360,50,10,20],'backgroundcolor',[0.75 0.75 0.75]);
- %%%%%%设置开始按键%%%%%%%
- b0=uicontrol('parent',y0,'units','points','tag','b1','style','pushbutton','string','开始','backgroundcolor',[0.75 0.75 0.75],'position',[220 10 50 20],'callback','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']); %%%close:关闭程序,但不退出matlab环境,需要的话可以更改为quit、exit中任一个
- %%%%%%设置风速调节滑动条%%%%%%%
- % s11=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;','yunxing(k,speed)']);
- % gcbo 获得正执行"回调"的对象句柄
- s11=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;']);
- % speed = get(s11,'Value')
- % speed1 = get(s11,'Value')
- %%%%%%设置滑动条说明静态文本框%%%%%%%
- 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]);
- [x1,y1,z1]=sphere(30); %产生球体坐标
- x=5*x1;y=5*y1;z=5*z1;
- shading interp; %%shading 是用来处理色彩效果的,分以下三种:shading interp 在flat的基础上进行色彩的插值处理,使色彩平滑过渡; no shading 一般的默认模式 即shading faceted; no shading 一般的默认模式 即shading faceted;
- hold on;
- mesh(x,y,z),colormap(hot); %画风扇框架
- hold on;
- function yunxing(k,speed)
- k=1;
- h01=0;m01=01;
- t_1=clock;
- h0=t_1(4); %设定时间初始化
- m0=t_1(5);
- t = 0;
- Y_a = 4;Y_b = 4;Y_c = 4;
- [x1,y1,z1]=sphere(30); %产生球体坐标
- x=5*x1;y=5*y1;z=5*z1;
- shading interp; %%shading 是用来处理色彩效果的,分以下三种:shading interp 在flat的基础上进行色彩的插值处理,使色彩平滑过渡; no shading 一般的默认模式 即shading faceted; no shading 一般的默认模式 即shading faceted;
- hold on;
- mesh(x,y,z),colormap(hot); %画风扇框架
- hold on;
- hidden off; %%%mesh画的3维图中,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');
- 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); %linspace(X1, X2, N)就是在x1和x2之间均匀生成一个N点的行矢量;
- b = a;
- c = a;
- a(1,1) = ay;
- b(1,1) = by;
- c(1,1) = cy;
- while k
- if k==0
- pause(); %%%停止键响应, pause(),参数缺省的情况下表示:按任意键继续。
- elseif m0==m01&h0==h01
- pause(); %%%定时功能响应
- %k=0;
- end
- % speed1 = get(s11,'Value');%获取滑条的值作为速度
5 H2 ]2 w0 {9 Z 7 m4 ?& K% r: i ^
3 U2 j- K3 i$ X6 a6 b
* L* o/ d% {" m: m9 @& e三、运行结果
$ Z7 S/ K; N4 P4 Y S+ N1 Q+ D, W6 I# l5 F+ i
1 }( N% ?5 K7 ?5 [. e. c* @
F1 D3 _ E% p9 m8 J: }
|
|