• Remix
  • Share
  • New Entry

  • Karl

  • /
  • Speeding along

on 3 Nov 2024
  • 32
  • 153
  • 0
  • 1
  • 1953
Cite your audio source here (if applicable):
drawframe(1);
Write your drawframe function below
function drawframe(f)
%DRAWFRAME Draw a frame for an animation of an athlete speeding along.
close
% Define wheel parameters.
nFramePerRotation = 48;
dphi = 2 * pi / nFramePerRotation;
x0 = 0.5;
y0 = 0.3;
r = 0.25;
wheelColor = [0.4940, 0.1840, 0.5560];
wheelLineWidth = 3;
nSpoke = 12;
thetas = linspace(0, 2 * pi, nSpoke + 1);
% Wheel rotation for current frame.
phi = -f * dphi;
% Define athlete paraemters.
athleteLineWidth = 10;
athleteColor = [0, 0, 1];
% Waist.
y1 = y0 + 0.6 * r;
x1 = x0 - 0.25 * r;
% Knee.
d1 = 1.5 * r;
x2 = x1 + d1;
y2 = y1;
% Foot.
theta1 = 1.35 * pi;
x3 = x2 + d1 * cos(theta1);
y3 = y2 + d1 * sin(theta1);
% Neck.
theta2 = 0.35 * pi;
x4 = x1 + d1 * cos(theta2);
y4 = y1 + d1 * sin(theta2);
% Head.
r2 = 0.35 * r;
x5 = x1 + (d1 + r2) * cos(theta2) - r2;
y5 = y1 + (d1 + r2) * sin(theta2) - r2;
% Shoulder.
d2 = 0.1 * r;
x6 = x1 + (d1 - d2) * cos(theta2);
y6 = y1 + (d1 - d2) * sin(theta2);
% Hand, for current wheel rotation.
nStep = 12;
theta3 = 0.75 * pi;
if 0 == mod(floor((f - 1) / nStep), 2)
% Forwards push.
phi2 = -mod(f - 1, nStep) * dphi;
else
% Backwards repositioning.
phi2 = -(nStep - mod(f - 1, nStep)) * dphi;
end
x7 = x0 + r * cos(theta3 + phi2);
y7 = y0 + r * sin(theta3 + phi2);
% Elbow, for current wheel rotation.
d3 = sqrt((x6 - x7)^2 + (y6 - y7)^2);
d4 = r;
theta4 = atan2(y6 - y7, x6 - x7) + acos(d3^2 / (2 * d3 * d4));
x8 = x7 + d4 * cos(theta4);
y8 = y7 + d4 * sin(theta4);
% Set up axes.
ax = axes(Position=[0, 0, 1, 1]);
ax.Color = [0.8, 0.9, 1];
axis([0, 1, 0, 1])
axis manual square
% Plot leg, body, head.
line([x4, x1, x2, x3], [y4, y1, y2, y3], ...
linewidth=athleteLineWidth, Color=athleteColor);
rectangle(Position=[x5, y5, 2*r2, 2*r2], ...
Curvature=[1, 1], FaceColor=athleteColor);
% Plot the wheel and its spokes.
viscircles([x0 y0], r, Linewidth=wheelLineWidth, Color=wheelColor);
for theta=thetas(1:nSpoke)
line([x0, x0 + r * cos(theta + phi)], ...
[y0, y0 + r * sin(theta + phi)],...
Linewidth=wheelLineWidth, Color=wheelColor);
end
% Plot arm.
line([x7, x8, x6], [y7, y8, y6], ...
linewidth=athleteLineWidth, Color=athleteColor);
end
Movie
Audio

This submission does not have audio.

Remix Tree