I’m trying to figure out animations in Plots.jl. I started off by porting a double pendulum simulation from the GR examples [https://github.com/jheinen/gr/blob/master/examples/double_pendulum.py], refactored a bit so it generates a list of positions in an array and then plots that. The main animation code is below; it’s a direct translation of the python code that calls GR.clearws(), sets a window and draws the pendulum via GR.polyline and GR.polymarker, and then calls GR.updatews(). This works fine to display an animation but I cannot figure out how to integrate it with the Plots animation mechanisms.
I’ve gone through the docs and examples, but they mostly talk about function plots, not making pictures with GR.polyline, and I’m missing the last step that connects the two.
using Plots; gr() # run_simulation code snipped function draw_polyline(vs) xs, ys = to_xy_lists(vs) GR.polyline(xs, ys) end function draw_polymarker(vs) xs, ys = to_xy_lists(vs) GR.polymarker(xs, ys) end function draw(block, window) GR.clearws() GR.setviewport(0, 1, 0, 1) GR.setwindow(window...) GR.setmarkertype(GR.MARKERTYPE_SOLID_CIRCLE) GR.fillarea([-0.2, 0.2, 0.2, -0.2], [0.75, 0.75, 0.8, 0.8]) block() GR.updatews() end function draw_pendulum(positions, n) l = l1 + l2 mass = [m1, m2] draw((-l, l, -l, l)) do ps = positions[n] draw_polyline(append!([pivot], ps)) GR.setmarkercolorind(86) for i = 1:2 GR.setmarkersize(3 * mass[i]) draw_polymarker([ps[i]]) end end end n_frames = 100 out = run_simulation(n_frames) for x in 1:n_frames draw_pendulum(out, x) sleep(0.1) end