- /
-
Fireworks 🎆
on 15 Oct 2024
- 30
- 172
- 2
- 2
- 1309
Cite your audio source here (if applicable):
% Audio - https://youtu.be/Dxya5ucIroI?si=Xp152Pg-OuOnJMTf
drawframe(1);
Write your drawframe function below
function drawframe(f)
xMin = -6; xMax = 6;
yMin = -1; yMax = 11;
figure
axis([xMin xMax yMin yMax]); % Setting axis limits
axis off;
hold on;
set(gcf,'color',[0,0,0]);
k = 500; % Number of points for smooth gradient
% Creating the gradient black to navy background to represent night sky
gC = zeros(k, k, 3);
for i = 1:k
t = 1 - (i/k);
gC(i,:,1) = 0;
gC(i,:,2) = 0;
gC(i,:,3) = t * 0.5;
end
% Gradient BG as an image
image('XData', [xMin, xMax], 'YData', [yMin, yMax], 'CData', gC);
set(gca, 'YDir', 'normal');
%Each firework has n circular layers created with points. The sizes of
%these points and radii of these layers grows with frame no.
n=5;
% Fireworks Scene 1
if f<=45 && f>=1
for i=1:n % Index to handle layers
pS = i*f/2 ; %increasing point size with frame no and layers no
inc = 0.2*i ; %increment factor of radii of layers
circ([-4.5,7.5],f/50+inc,pS,9,[1 0 0; 0.8500 0.3250 0.0980]); %fw1
circ([1.5,5.5],f/60+inc,pS,7,[1 1 0;0 1 0]); %fw2
circ([4.2,8],f/40+inc,pS,11,[1 0 1; 0 1 1]); %fw3
circ([-3,4],f/50+inc,pS,13,rand(2,3)); %fw4
circ([0,9],f/50+inc,pS,13,rand(2,3)); %fw5
circ([4,3],f/50+inc,pS,13,rand(2,3)); %fw6
end
% Fireworks Scene 2
elseif f<=96 && f>=52
f = mod(f,52)+1;
for i=1:n
pS = i*f/2 ;
inc = 0.2*i ;
circ([-4.5,8],f/40+inc,pS,11,rand(2,3));
circ([-3.5,3.5],f/40+inc,pS,11,[1 1 0;0.8500 0.3250 0.0980]);
circ([-0.5,5.5],f/50+inc,pS,9,[1 0 0; 0 1 0]);
circ([2,9],f/40+inc,pS,13,[0.5 0 1; 0 1 1]);
circ([4,4],f/50+inc,pS,13,rand(2,3));
end
end
end
function circ(center, radius, pointSize, numPoints, clr)
glowSize = pointSize + 200;
th = linspace(0, 2*pi, numPoints);
x = center(1) + radius * cos(th);
y = center(2) + radius * sin(th);
colors = repmat(clr, ceil(numPoints/2), 1);
colors = colors(1:numPoints, :);
hold on;
scatter(x, y, pointSize, colors, 'filled'); %Create single circular layers of points
for glow = 1:3 %Glow effect
scatter(x, y, pointSize + glow*glowSize, colors, 'filled', 'MarkerFaceAlpha', 0.05);
end
end