- /
- 
        Fireworks at Night (Remixed with MATLAB GPT)
        on 15 Oct 2024
        
        
 
    - 17
- 380
- 0
- 0
- 1428
 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]); % Set figure background to black for night
k = 500;  % Number of points for smooth gradient
% Adding a starry background
numStars = 100; % Number of stars
starX = xMin + (xMax-xMin)*rand(1,numStars); % Random x positions for stars
starY = yMin + (yMax-yMin)*rand(1,numStars); % Random y positions for stars
scatter(starX, starY, rand(1, numStars) * 20, [1 1 1], 'filled'); % Plot stars with random sizes
% Drawing the moon
theta = linspace(0, 2*pi, 100); % Circle for moon
moonX = 4 + 1.5*cos(theta); % Moon's x position
moonY = 9 + 1.5*sin(theta); % Moon's y position
fill(moonX, moonY, [0.9 0.9 0.9], 'EdgeColor', 'none'); % Moon in light gray
%Each firework has n circular layers created with points. The sizes of
%these points and radii of these layers grow 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


 

 
             
             
