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)
回答(1 个)
KSSV
2019-3-11
Reverse M before writitng into video...
M = fliplr(M) ;
writeVideo(v,M);
close(v);
movie(M,1)
类别
在 帮助中心 和 File Exchange 中查找有关 Animation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!