matlab
function fireworks()
% 设置烟花的种类和颜色
types = {'circle', 'star', 'heart', 'triangle','square', 'diamond', 'pentagon', 'hexagon', 'spiral', 'burst'};
colors = {'r', 'g', 'b', 'c', 'm', 'y'};
% 创建一个图形窗口
figure;
axis off;
axis equal;
hold on;
% 循环放置烟花
for i = 1:10
% 随机选择一种烟花和颜色
type =types{randi(numel(types))};
color =colors{randi(numel(colors))};
% 随机生成烟花的位置
x = rand() * 10;
y = rand() * 10;
% 绘制烟花
drawFirework(type, color, x, y);
% 等待一段时间,以便观察烟花效果
pause(1);
end
end
function drawFirework(type, color, x, y)
% 根据烟花的类型绘制不同形状
switch type
case 'circle'
t = linspace(0, 2*pi,100);
r = linspace(0, 1,100);
plot(x + r.*cos(t), y+ r.*sin(t), color);
case 'star'
t = linspace(0, 2*pi,10);
r = linspace(0, 1,10);
x_star = x +r.*cos(t);
y_star = y +r.*sin(t);
plot(x_star, y_star,color);
% 其他烟花形状的绘制方法类似,可以根据需要添加
end
end