Create an animation of a moving circle with a timer, and rewind the animation using rewindAnimation
.
First, create two symbolic variables, t
and x
. The variable t
defines the time parameter of the animation. Create a figure window for the animation.
Create the circle animation object using fanimator
. Use t
to set the center of the circle at (t,1)
and x
to parameterize the perimeter of the circle within the range [-pi pi]
. Set the range of the animation time parameter to [4 8]
. Set the x-axis and y-axis to be equal length.
Next, add a timer animation object. Use the text
function to create a piece of text to count the elapsed time. Use num2str
to convert the time parameter to a string.
Play the animation in figure fig
between 4 and 8 seconds by entering the playAnimation
command.
playAnimation(fig,'AnimationRange',[4 8])
You can rewind a previously played animation by using rewindAnimation
. rewindAnimation
restores the animation time parameter to its initial value at t = 4
and shows the starting animation frame.