import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as patches
from matplotlib import animation

class Cart:
	def __init__(self, m):
		self.m = m

fig = plt.figure()
# plt.axis('equal')
# plt.gca().set_aspect('equal', adjustable='box')
plt.gca().set_aspect('equal')

# global drawing
cart = patches.Rectangle((0, 0), 0, 0, facecolor='xkcd:azure')

def init():
	ax = fig.add_subplot(111)
	ax.set_xlim(-10, 10)
	ax.set_ylim(-10, 10)

	# permanent drawing
	rail_x = np.linspace(-15, 15, 100)
	rail_y = np.zeros(100)
	ax.plot(rail_x, rail_y, 'xkcd:black', linewidth=2)

	# placeholder for temporary drawing
	ax.add_patch(cart)
	cart.set_width(1.0)
	cart.set_height(1.0)
	cart._angle = 0
	return cart,

def update(frame_number):
	
	cart.set_xy([5*np.sin(0.1*frame_number)-0.5, -0.5])
	# cart.set_xy([5, -0.5])
	return cart,

anim = animation.FuncAnimation(fig,
	update,
	init_func=init,
	frames = 10000,
	interval=50,
	blit=True)

plt.show()
