This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Johanwikdahl last edited by ccc
def animate(step, p, U): p_r = np.sqrt(p[0, :]**2 + p[1, :]**2) u_p = U + (K / (2*np.pi)) * p[0, :] / p_r**2 v_p = (K / (2*np.pi)) * p[1, :] / p_r**2 U = np.asarray([u_p, v_p]) # To avoid very large velocities for particles close to the center U[:, p_r < r_threshold] = 0.0 # Update positions based on linear advection p += U * delta_t points.set_data(p[0, :], p[1, :]) anim = animation.FuncAnimation(fig2, animate, frames=num_timesteps,interval=10000/FPS, fargs=(p, U)) plt.close(anim._fig) HTML(anim.to_html5_video()) #HTML(anim.to_jshtml())
How can I make this animation run in Pythonista?
JonB last edited by ccc
Pythonista uses a pretty old version of matplotlib.
Although this version 1.3.1 does has an animations module, it does not have the HTML video writer or Pillow writer.
Skimming the source code, I believe
animation.pyis entirely python code, so could in theory be backported to pythonista, which would allow use of the html writer or pillow writer.
(I'll experiment a little this week)
JonB last edited by JonB
Okay, as it turns out it was not hard at all to backport the latest matplotlib.animation module so it works in pythonista. Obviously, things which rely on ffmpeg are not going to work, but to_jshtml does work, since it works by saving a sequence of temporary files, then encoding those files and embedding into html, with some js code to decode and play. The results is an html string that can be passed to ui.webview.load_html().
You get this by first importing the package below in your code. Then ani.save would be replaced with to_jshtml and load_html.