How to reverse an animation

How do we modify the program below to create a program where ball fly and then return to where they are?
clc,clf,clear
g=9.81; theta0=45*pi/180; v0=5;
t(1)=0;x=0;y=0;
plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8)
axis([0 3 0 0.8])
M(1)=getframe;
dt=1/128;
v=VideoWriter('cannon2.avi');
open(v);
for j = 2:1000
t(j)=t(j-1)+dt;
x=v0*cos(theta0)*t(j);
y=v0*sin(theta0)*t(j)-0.5*g*t(j)^2;
plot(x,y,'o','MarkerFaceColor','b','MarkerSize',8)
axis([0 3 0 0.8])
pause(0.1)
M(j)=getframe;
%%writeVideo(v,M(j));
if y<=0, break, end
end
writeVideo(v,M);
close(v);
pause
movie(M,1)

Answers (1)

Reverse M before writitng into video...
M = fliplr(M) ;
writeVideo(v,M);
close(v);
movie(M,1)

Categories

Tags

Asked:

on 11 Mar 2019

Answered:

on 11 Mar 2019

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!