Skip to content

Commit

Permalink
Adding option to save animation (zhuminjie#58)
Browse files Browse the repository at this point in the history
- The animation returns to the initial frame instead of 0th frame once finished.
- Added function to save the animation as a movie (.mp4) file. Tested on Jupyter notebook, cmd and Spyder.
  • Loading branch information
u-anurag committed Jul 8, 2020
1 parent 7a487b8 commit 1ebf0cb
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions openseespy-pip/openseespy/postprocessing/Get_Rendering.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,11 +785,11 @@ def animate_deformedshape( Model = 'none', LoadCase = 'none', dt = 0, tStart = 0
have approximately the same number of time between each step or the
animation will appear to speed up or slow down.
tStart: float, optional
The start time for animation. It can be approximate value and the program
will find the closest matching time step.
The start time for animation. It can be approximate value and the program
will find the closest matching time step.
tEnd: float, optional
The end time for animation. It can be approximate value and the program
will find the closest matching time step.
The end time for animation. It can be approximate value and the program
will find the closest matching time step.
NodeFileName : Str
Name of the input node information file.
ElementFileName : Str
Expand All @@ -805,10 +805,8 @@ def animate_deformedshape( Model = 'none', LoadCase = 'none', dt = 0, tStart = 0
DESCRIPTION. The default is 1.
timeScale : TYPE, optional
DESCRIPTION. The default is 1.
Movie : str, optional (PLACEHOLDER)
Name of the movie file if the user wants to save the animation as .mp4 file.
This is a PLACEHOLDER for now until Matplotlib's compatibility with
ffmpeg writer is figured out.
Movie : str, optional
Name of the movie file if the user wants to save the animation as .mp4 file.
Returns
-------
Expand Down Expand Up @@ -1042,7 +1040,7 @@ def update_plot(ii):
CurrentFrame = int(np.floor(plotSlider.val))
CurrentFrame += 1
if CurrentFrame >= FrameEnd:
CurrentFrame = 0
CurrentFrame = FrameStart

# Update the slider
plotSlider.set_val(CurrentFrame)
Expand All @@ -1058,8 +1056,15 @@ def update_plot(ii):
fig.canvas.mpl_connect('button_press_event', on_click)

ani = animation.FuncAnimation(fig, update_plot, aniFrames, interval = FrameInterval, repeat=False)
plt.show()

if Movie != "none":
MovefileName = Movie + '.mp4'
ODBdir = Model+"_ODB" # ODB Dir name
Movfile = os.path.join(ODBdir, LoadCase, MovefileName)
print("Saving the animation movie as "+MovefileName+" in "+ODBdir+"->"+LoadCase+" folder")
ani.save(Movfile, writer='ffmpeg')

plt.show()
return ani


Expand Down

0 comments on commit 1ebf0cb

Please sign in to comment.