• Remix
  • Share
  • New Entry

on 6 Nov 2023
  • 5
  • 149
  • 0
  • 3
  • 1041
function drawframe(f)
% Define the cat's body parts as shapes
% The frame number 'f' will determine the position of the tail
% Clear the figure
clf;
hold on;
% Body parameters
bodyWidth = 2;
bodyHeight = 1;
tailLength = 1.5;
% Calculate tail movement using sine function for smooth swing
tailAngle = sin(f * 2 * pi / 48) * 30; % 30 degrees swing from the center
% Draw the body
rectangle('Position', [-bodyWidth/2, -bodyHeight/2, bodyWidth, bodyHeight], 'Curvature', [1,1], 'EdgeColor', 'k', 'FaceColor', [0.8, 0.8, 0.8]);
% Draw the head
rectangle('Position', [-0.75, 0.5, 1.5, 1], 'Curvature', [1,1], 'EdgeColor', 'k', 'FaceColor', [0.8, 0.8, 0.8]);
% Draw the ears
triangle1x = [-0.75, -0.5, -1];
triangle1y = [1.5, 1.5, 2];
patch(triangle1x, triangle1y, [0.8, 0.8, 0.8], 'EdgeColor', 'k');
triangle2x = [0.75, 1, 0.5];
triangle2y = [1.5, 2, 1.5];
patch(triangle2x, triangle2y, [0.8, 0.8, 0.8], 'EdgeColor', 'k');
% Draw the eyes
rectangle('Position', [-0.5, 1, 0.2, 0.5], 'Curvature', [1,1], 'EdgeColor', 'k', 'FaceColor', 'w');
rectangle('Position', [0.3, 1, 0.2, 0.5], 'Curvature', [1,1], 'EdgeColor', 'k', 'FaceColor', 'w');
% Draw the tail with movement
% The tail is represented by a line that swings left and right
tailBaseX = bodyWidth/2;
tailBaseY = -bodyHeight/4; % Tail base is a quarter way up the body
tailEndX = tailBaseX + tailLength * cosd(tailAngle);
tailEndY = tailBaseY + tailLength * sind(tailAngle);
plot([tailBaseX, tailEndX], [tailBaseY, tailEndY], 'k', 'LineWidth', 2);
% Set the axis limits
axis([-3 3 -3 3]);
axis square;
axis off;
hold off;
end
Animation
Remix Tree