In [1]:
%pylab inline
In [2]:
from JSAnimation import IPython_display
from matplotlib import animation
import JSAnimation_frametools as J
In [3]:
plotdir = '_plots' # to store png files for each figure
J.make_plotdir(plotdir, clobber=True) # ok to clobber if it already exists
In [23]:
def plot_square(t):
x = array([-1,1,1,-1,-1])
y = array([-1,-1,1,1,-1])
xr = cos(t)*x + sin(t)*y
yr = -sin(t)*x + cos(t)*y
fill(xr,yr,'b')
axis('scaled')
axis([-2,2,-2,2])
num_frames = 10
for n in range(num_frames):
t = (float(n)/num_frames) * pi/2.
plot_square(t)
# Save this frame:
J.save_frame(n, plotdir,verbose=True)
show()
In [24]:
anim = J.make_anim(plotdir)
anim
Out[24]:
In [25]:
J.make_html(anim, file_name="Square.html", title="Rotating square")
In [ ]: