omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    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.


    To_html5video

    Pythonista
    2
    3
    738
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Johanwikdahl
      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 1 Reply Last reply Reply Quote 0
      • JonB
        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.py is 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)

        1 Reply Last reply Reply Quote 0
        • JonB
          JonB @Johanwikdahl 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.

          See README
          https://github.com/jsbain/pythonista_matplotlib_backports

          1 Reply Last reply Reply Quote 0
          • First post
            Last post
          Powered by NodeBB Forums | Contributors