• Remix
  • Share
  • New Entry

on 28 Nov 2023
  • 12
  • 9
  • 0
  • 0
  • 814
drawframe(1);
Write your drawframe function below
function drawframe(f)
numRows = 5;
numCols = 5;
hexagonVertices = @(center, radius) [center(1) + radius * cosd(0:60:360)', ...
center(2) + radius * sind(0:60:360)'];
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
radius = rand();
color = [row/numRows col/numCols f/48];
vertices = hexagonVertices([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 = hexagonVertices([lightX, lightY], lightRadius);
patch(lightVertices(:, 1), lightVertices(:, 2), lightColor, 'FaceAlpha', alphaValue);
end
end
end
axis equal;
axis off
end
Animation
Remix Tree