- /
-
Bouncing off four walls
on 9 Nov 2023
- 5
- 24
- 0
- 0
- 541
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Function for animation of ball bouncing around four walls.
% Remix of: Bouncing.
% Define number of frames in whole, half and quarter animation unit.
% Animation unit will repeat for frame numbers
% greater than number of frames in unit.
unit = 48;
half = 0.5*unit;
quarter = 0.25*unit;
% Determine frame number within unit.
step = mod(f, unit);
% Determine ball coordinates for current frame.
x = abs(step-half)/half;
y = (-1)^(step>half)*(abs(mod(f,half)-quarter)/quarter-1);
% Plot current frame.
plot(x,y, ...
Marker=".", ...
MarkerSize=100)
axis([0 1 -1 1])
end