• Remix
  • Share
  • New Entry

on 29 Nov 2023
  • 10
  • 5
  • 0
  • 0
  • 982
drawframe(1);
Write your drawframe function below
function drawframe(f)
numRows = 5;
numCols = 5;
% Define a function to generate the vertices of a star
starVertices = @(center, radius) [center(1) + radius * cosd(0:72:360)', ...
center(2) + radius * sind(0:72:360)'];
% Define the minimum and maximum size of the stars
minSize = 0.5; % minimum size of a star
maxSize = 2.0; % maximum size of a star
for row = 1:numRows
for col = 1:numCols
centerX = col * 1.5;
centerY = row * sqrt(3);
if mod(row, 2) == 0
centerX = centerX + 0.75;
end
% Generate a random size for the star between minSize and maxSize
radius = minSize + rand() * (maxSize - minSize);
color = rand(1, 3);
vertices = starVertices([centerX, centerY], radius);
patch(vertices(:, 1), vertices(:, 2), color, 'EdgeColor', 'k');
numLights = 5;
lightRadius = radius * 0.3;
for i = 1:numLights
lightColor = [1, 1, 1];
alphaValue = rand() * 0.5*f/50;
theta = rand() * 2 * pi;
lightX = centerX + radius * cos(theta);
lightY = centerY + radius * sin(theta);
lightVertices = starVertices([lightX, lightY], lightRadius);
patch(lightVertices(:, 1), lightVertices(:, 2), lightColor, 'FaceAlpha', alphaValue);
end
end
end
axis off; % Turn off the axis
axis equal;
if f <= 50
minSize = 0.5 + (f/50) * 1.5; % minimum size of a star
maxSize = 2.0 + (f/50) * 1.5; % maximum size of a star
else
minSize = 2.0 - ((f-50)/50) * 1.5; % minimum size of a star
maxSize = 3.5 - ((f-50)/50) * 1.5; % maximum size of a star
end
end
Animation
Remix Tree