Skip to content

Commit

Permalink
Use for displacement animation
Browse files Browse the repository at this point in the history
  • Loading branch information
narahahn committed Dec 31, 2018
1 parent 32b7453 commit 4421b3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
22 changes: 10 additions & 12 deletions doc/examples/animation-pulsating-sphere-displacement.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
t = np.arange(L) / fs # time

# Uniform grid
xmin, xmax = -1, 1
xmin, xmax = -2, 1
ymin, ymax = -1, 1
grid = sfs.util.xyz_grid([xmin, xmax], [ymin, ymax], 0, spacing=0.02)

Expand All @@ -38,13 +38,10 @@
facecolor='RoyalBlue',
linestyle='None',
alpha=0.4))
line, = ax.plot([], [],
marker='o',
markersize=1.5,
markerfacecolor='gray',
markeredgecolor='None',
linestyle='None',
alpha=0.75)
scat = sfs.plot.particles(grid + displacement,
s=15,
c='gray',
marker='.')
text = ax.text(0.9 * xmax, 0.9 * ymin, '<t>',
fontsize=16,
horizontalalignment='right',
Expand All @@ -56,20 +53,21 @@
ax.axis('off')


def animate(i, line, patch, text):
def animate(i, scat, patch, text):
"""Update frame."""
phase_shift = np.exp(1j * omega * t[i])
X = grid + (displacement * phase_shift).apply(np.real)
line.set_data(X[0], X[1])
X = np.column_stack([X[0].flatten(), X[1].flatten()])
scat.set_offsets(X)
patch.set_radius(radius + amplitude * np.real(phase_shift))
text.set_text('{:0.2f} ms'.format(t[i] * 1000))
return line, patch, text
return scat, patch, text


ani = animation.FuncAnimation(fig,
animate,
frames=L,
fargs=(line, patch, text))
fargs=(scat, patch, text))
ani.save('pulsating_sphere_displacement.gif',
fps=10,
dpi=80,
Expand Down
3 changes: 2 additions & 1 deletion sfs/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,12 +338,13 @@ def particles(x, trim=None, ax=None, xlabel='x (m)', ylabel='y (m)',
if ax is None:
ax = plt.gca()

ax.scatter(XX, YY, edgecolor=edgecolor, **kwargs)
scat = ax.scatter(XX, YY, edgecolor=edgecolor, **kwargs)

if xlabel:
ax.set_xlabel(xlabel)
if ylabel:
ax.set_ylabel(ylabel)
return scat


def vectors(v, grid, cmap='blacktransparent', headlength=3, headaxislength=2.5,
Expand Down

0 comments on commit 4421b3c

Please sign in to comment.