前言:2024已经到来,祝所有的小盆友们新年快乐!!!!!
一.设置黑色背景图框
首先,设置所需的图框并对图框进行标注尺寸
如图所示 :
二.作出星星图
通过axes()函数作出坐标区并画出星星图样
如图所示:
三.作出月亮图
同理作出坐标区并绘制月亮
如图所示:
四.绘制烟花
这里我们一共绘制了七个烟花,其中包括对于烟花的坐标区间,烟花的升空和爆炸设计,以及对于烟花的尺寸标注颜色定义等。
五.一些烟花的静止图
这里还不知道咋导出gif图所以就只有一些静止图(希望可以复制运行一下还是蛮好看嘞),以下是一些截屏的静止图。
如图:
六.整个的烟花源码
figure %设置黑色背景图框
set(gcf,'Color',[0 0 0],'Position',[400 200 700 600]) %对图框的大小及背景颜色进行标注
%利用axes()函数创建坐标区
ax1=axes('Position',[0.01 0.6 0.95 0.4]);
%画出星星图
hold on
for i=1:100
plot(rand(1),rand(1),'p',...
'MarkerFaceColor',[1 1 1],'MarkerEdgeColor',[1 1 1],'MarkerSize',randi(4,1)) %白色星星
end
axis off
%创建月亮的坐标区
ax2=axes('Position',[0.8 0.8 0.3 0.3]);
%画出月亮
[r,theta]=meshgrid(0:0.01:1,linspace(0,2*pi,100));
[X,Y]=pol2cart(theta,r); %极坐标转化为直角坐标系
Z=X.^2+Y.^2;
pcolor(X,Y,Z)
axis equal
shading interp
colormap gray %灰色渲染
axis off
%创建烟花坐标区
%绘制烟花一号
ax3=axes('Position',[0.05 0.05 0.9 0.9]); %这里默认0.05,0.05为该图的中点坐标位置
c=[0.8 0.97 0.5]; % 颜色接近火焰
for i=1:100
plot(0,i,'.','LineWidth',2,'MarkerFaceColor',c-[0 0 i/100/2.2],...
'MarkerEdgeColor',[min(rand(1)*3,1),rand(1),rand(1)],'MarkerSize',6)
axis([-100 100 0 200])
axis equal
axis off
drawnow
end
%烟花升空炸裂
theta=sort(rand(1,60))*2*pi;
t=(0:0.01:2)'; % 时间
v0=15; % 初始速度
xx=v0*cos(theta).*t;
yy=(v0*sin(theta)+5).*t-1/2*10*t.^2+100;
h = animatedline('Marker','.','LineStyle','none','MarkerSize',0.1);
for i=1:length(xx)
addpoints(h,xx(i,:),yy(i,:));
set(h,'Color',[rand(1),rand(1),rand(1)])
axis([-100 100 0 200])
axis off
drawnow
end
%烟花二号
ax4=axes('Position',[0.35 0.15 0.9 0.9]);
c=[0.8 0.97 0.5]; % 颜色接近火焰
for i=1:100
plot(0,i,'.','LineWidth',2,'MarkerFaceColor',c-[0 0 i/100/2.2],...
'MarkerEdgeColor',[min(rand(1)*3,1),rand(1),rand(1)],'MarkerSize',6)
axis([-100 100 0 200])
axis equal
axis off
drawnow
end
theta=sort(rand(1,60))*2*pi;
t=(0:0.01:2)'; % 时间
v0=15; % 初始速度
xx=v0*cos(theta).*t;
yy=(v0*sin(theta)+5).*t-1/2*10*t.^2+100;
h = animatedline('Marker','.','LineStyle','none','MarkerSize',0.1);
for i=1:length(xx)
addpoints(h,xx(i,:),yy(i,:));
set(h,'Color',[rand(1),rand(1),rand(1)])
axis([-100 100 0 200])
axis off
drawnow
end
%烟花三号
ax5=axes('Position',[0.25 0.05 0.9 0.9]);
c=[0.8 0.97 0.5]; % 颜色接近火焰
for i=1:100
plot(0,i,'.','LineWidth',2,'MarkerFaceColor',c-[0 0 i/100/2.2],...
'MarkerEdgeColor',[min(rand(1)*3,1),rand(1),rand(1)],'MarkerSize',6)
axis([-100 100 0 200])
axis equal
axis off
drawnow
end
theta=sort(rand(1,60))*2*pi;
t=(0:0.01:2)'; % 时间
v0=15; % 初始速度
xx=v0*cos(theta).*t;
yy=(v0*sin(theta)+5).*t-1/2*10*t.^2+100;
h = animatedline('Marker','.','LineStyle','none','MarkerSize',0.1);
for i=1:length(xx)
addpoints(h,xx(i,:),yy(i,:));
set(h,'Color',[rand(1),rand(1),rand(1)])
axis([-100 100 0 200])
axis off
drawnow
end
%烟花四号
ax6=axes('Position',[0.15 0.40 0.9 0.9]);
c=[0.8 0.97 0.5]; % 颜色接近火焰
for i=1:100
plot(0,i,'.','LineWidth',2,'MarkerFaceColor',c-[0 0 i/100/2.2],...
'MarkerEdgeColor',[min(rand(1)*3,1),rand(1),rand(1)],'MarkerSize',6)
axis([-100 100 0 200])
axis equal
axis off
drawnow
end
theta=sort(rand(1,60))*2*pi;
t=(0:0.01:2)'; % 时间
v0=15; % 初始速度
xx=v0*cos(theta).*t;
yy=(v0*sin(theta)+5).*t-1/2*10*t.^2+100;
h = animatedline('Marker','.','LineStyle','none','MarkerSize',0.1);
for i=1:length(xx)
addpoints(h,xx(i,:),yy(i,:));
set(h,'Color',[rand(1),rand(1),rand(1)])
axis([-100 100 0 200])
axis off
drawnow
end
%烟花五号
ax7=axes('Position',[-0.20 0.15 0.9 0.9]);
c=[0.8 0.97 0.5]; % 颜色接近火焰
for i=1:100
plot(0,i,'.','LineWidth',2,'MarkerFaceColor',c-[0 0 i/100/2.2],...
'MarkerEdgeColor',[min(rand(1)*3,1),rand(1),rand(1)],'MarkerSize',6)
axis([-100 100 0 200])
axis equal
axis off
drawnow
end
theta=sort(rand(1,60))*2*pi;
t=(0:0.01:2)'; % 时间
v0=15; % 初始速度
xx=v0*cos(theta).*t;
yy=(v0*sin(theta)+5).*t-1/2*10*t.^2+100;
h = animatedline('Marker','.','LineStyle','none','MarkerSize',0.1);
for i=1:length(xx)
addpoints(h,xx(i,:),yy(i,:));
set(h,'Color',[rand(1),rand(1),rand(1)])
axis([-100 100 0 200])
axis off
drawnow
end
%烟花六号
ax8=axes('Position',[-0.30 0.00 0.9 0.9]);
c=[0.8 0.97 0.5]; % 颜色接近火焰
for i=1:100
plot(0,i,'.','LineWidth',2,'MarkerFaceColor',c-[0 0 i/100/2.2],...
'MarkerEdgeColor',[min(rand(1)*3,1),rand(1),rand(1)],'MarkerSize',6)
axis([-100 100 0 200])
axis equal
axis off
drawnow
end
theta=sort(rand(1,60))*2*pi;
t=(0:0.01:2)'; % 时间
v0=15; % 初始速度
xx=v0*cos(theta).*t;
yy=(v0*sin(theta)+5).*t-1/2*10*t.^2+100;
h = animatedline('Marker','.','LineStyle','none','MarkerSize',0.1);
for i=1:length(xx)
addpoints(h,xx(i,:),yy(i,:));
set(h,'Color',[rand(1),rand(1),rand(1)])
axis([-100 100 0 200])
axis off
drawnow
end
%烟花七号
ax9=axes('Position',[-0.10 0.35 0.9 0.9]);
c=[0.8 0.97 0.5]; % 颜色接近火焰
for i=1:100
plot(0,i,'.','LineWidth',2,'MarkerFaceColor',c-[0 0 i/100/2.2],...
'MarkerEdgeColor',[min(rand(1)*3,1),rand(1),rand(1)],'MarkerSize',6)
axis([-100 100 0 200])
axis equal
axis off
drawnow
end
theta=sort(rand(1,60))*2*pi;
t=(0:0.01:2)'; % 时间
v0=15; % 初始速度
xx=v0*cos(theta).*t;
yy=(v0*sin(theta)+5).*t-1/2*10*t.^2+100;
h = animatedline('Marker','.','LineStyle','none','MarkerSize',0.1);
for i=1:length(xx)
addpoints(h,xx(i,:),yy(i,:));
set(h,'Color',[rand(1),rand(1),rand(1)])
axis([-100 100 0 200])
axis off
drawnow
end
最后祝大家2024新年快乐!!!!!!