# Making frames for a rotating square
import numpy as np
import matplotlib.pyplot as plt
# Unrotated vertices
LL0 = [-1.0,-1.0]
LR0 = [1.0,-1.0]
UR0 = [1.0,1.0]
UL0 = [-1.0,1.0]
NumFrames = 200
plt.figure(facecolor='white')
for i in range(NumFrames):
theta = 2.0 * np.pi * float(i) / float(NumFrames)
# Rotate the vertices
LL = [LL0[0] * np.cos(theta) + LL0[1] * np.sin(theta), -LL0[0] * np.sin(theta) + LL0[1] * np.cos(theta)]
LR = [LR0[0] * np.cos(theta) + LR0[1] * np.sin(theta), -LR0[0] * np.sin(theta) + LR0[1] * np.cos(theta)]
UR = [UR0[0] * np.cos(theta) + UR0[1] * np.sin(theta), -UR0[0] * np.sin(theta) + UR0[1] * np.cos(theta)]
UL = [UL0[0] * np.cos(theta) + UL0[1] * np.sin(theta), -UL0[0] * np.sin(theta) + UL0[1] * np.cos(theta)]
# Plot them
ax = plt.axes(aspect=1)
ax.plot(LL,LR, lw=4, color='black')
ax.plot(LR,UR, lw=4, color='blue')
ax.plot(UR,UL, lw=4, color='red')
ax.plot(UL,LL, lw=4, color='green')
ax.set_xlim(-1.5, 1.5) # Sets the axis limits
ax.set_ylim(-1.5, 1.5) # Sets the axis limits
ax.axis('off') # Turns off the axes
filename = 'movie1/frame_%03d.png'%i
plt.savefig(filename) # Save the plot
plt.cla() # Clear the axes