• Remix
  • Share
  • New Entry

on 6 Nov 2023
  • 8
  • 32
  • 0
  • 2
  • 633
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Set up parameters
totalframes = 48;
width = 600;
height = 600;
% Create figure and set its size
figure('Position', [100, 100, width, height]);
% Set the background to black and hold the plot
set(gca, 'color', 'k', 'YTick', [], 'XTick', []);
axis([0 width 0 height]);
hold on;
% Loop to draw multiple rectangles
for i = 0:1/16:1-(1/16)
barheight = inOutSin(tri(timeLoop(totalframes, i * 60, f))) * 100;
barWidth = 32;
posX = 36 + i * 640;
posY = (300);
% Draw rectangle with no border
rectangle('Position', [posX, posY, barWidth, barheight], 'EdgeColor', 'none', 'FaceColor', 'w');
end
% Hold off the plot
hold off;
end
function pos = timeLoop(totalframes, offset, frameCount)
% This helper function calculates the position of the rectangle
pos = mod(frameCount + offset, totalframes) / totalframes;
end
function y = tri(t)
% Triangle wave function
if t < 0.5
y = t * 2;
else
y = 2 - (t * 2);
end
end
function y = inOutSin(t)
% Ease-in-out sine wave function
y = 0.5 - cos(pi * t) / 2;
end
Animation
Remix Tree