1、_MATLAB程序演示烟花燃放过程烟花(礼花)的朵朵绽放给夜空带来炫彩,瞬间绚丽至极,迸射出璀璨夺目的光彩。只是还来不及在脑海中印上花魂,她已昙花一现般,烟花(礼花)朵朵绽放,瞬间绚丽至极,迸射出璀璨夺目的光彩。只是还来不及在脑海中印上花魂,她已昙花一现般的消逝了。多少人痴迷于烟花的美,痴迷于她飘忽不定的幻影。利用MATLAB程序演示烟花的美,虽然她不如现实那样逼真,但一样会吸引人。附源程序:function firework% 烟花烟花满天飞% CopyRight:xiezhh(谢中华)% 2011.6.25OldHandle = findobj( Type, figure, Tag, Fi
2、reWork ) ;if ishandle(OldHandle) close(OldHandle) ;end% 图形窗口初始化fig = figure(units,normalized,position,0.1 0.1 0.8 0.8,. menubar,none,name,烟花满天飞(谢中华制作),. numbertitle,off,color,0 0 0,tag,FireWork);% 烟花炸开前的初始位置h0 = line(0,0,0,linestyle, none,. marker,.,. markersize,18,. MarkerEdgeColor,1 1 1,. MarkerFa
3、ceColor,1 1 1,. EraseMode , xor);% 设置坐标系显示属性axis equalaxis(-50 50 -50 50 0 100)axis offview(-42,22)% 设置参数rate = 1:-0.01:0; % 颜色衰减率v0 = 45; % 烟花头初始速度g = -9.8; % 重力加速度usedtime = -v0/g; % 烟花头爆炸前所经历时间zs = v0*usedtime+0.5*g*usedtime2; %烟花头爆炸前达到的最高高度theta = rand(250,1)*2*pi; % 各粒子速度的方位角phi = rand(250,1)*2
4、*pi-pi; % 各粒子速度的仰角age = 20; % 粒子生存期% 常用颜色矩阵colormat = 1.0 0.5 0.5 1.0 0.75 0.5 1.0 1.0 0.5 0.75 1.0 0.5 0.5 1.0 0.5 0.5 1.0 0.75 0.5 1.0 1.0 0.5 0.75 1.0 0.5 0.5 1.0 0.75 0.5 1.0 1.0 0.5 1.0 1.0 0.5 0.75;% 随机产生各粒子对应的颜色序号colorid = randsample(12,250,true);% 粒子对应的颜色矩阵colormat = colormat(colorid,:);% 粒子
5、颜色与背景色(夜色)的距离colordist = sqrt(sum(colormat.2,2);v1 = 20; % 粒子的初始速度k = 1; % 颜色衰减率初始序号timerA = timer(TimerFcn,TimerFcnA,. executionmode,fixedspacing,Period,0.001);start(timerA);h = getappdata(gcf,HandleParticle);timerB = timer(TimerFcn,TimerFcnB,. executionmode,fixedspacing,period,0.001);%-% 定时器回调函数(烟
6、花头)%-function TimerFcnA(timerA,event)ta = get(timerA,TasksExecuted)*0.1;if ta 0 & any(colordist=0.05) colormat = colormat*rate(k); colordist = sqrt(sum(colormat.2,2); for i = 1:250 xi = v1*cos(phi(i)*cos(theta(i)*tb; yi = v1*cos(phi(i)*sin(theta(i)*tb; zi = zs+v1*sin(phi(i)*tb+0.5*g*tb2; set(h(i),XData,xi,YData,yi,ZData,zi,. MarkerEdgeColor,colormat(i,:),. MarkerFaceColor,colormat(i,:) end drawnow age = age-0.1; k = k+1;else stop(timerB); delete(h)endend%-endWelcome ToDownload !欢迎您的下载,资料仅供参考!精品资料