fig = plt.figure()
fig.set_size_inches(12,2)
d=50
x1, x2 = -10, d
v1 = 5
a = 0
v2 = 9
dt = 0.1
a1 = 0
ax = plt.axes(xlim=(-10, 200), ylim=(-4, 20))
t1 = plt.text(-x1, 0., "train1", size=10,
bbox=dict(boxstyle="round",
ec=(1., 0.5, 0.5),
fc=(1., 0, 0),
)
)
t2 = plt.text(x2, 0., "train2", size=10,
bbox=dict(boxstyle="round",
ec=(0., 1, 0.5),
fc=(0.,1, 0),
)
)
plt.plot([0, 200],[0, 0], lw =2 ,c = 'k')
def init():
return [t1, t2]
def animate(i):
global x1, x2, v1, a
v1 += a * dt
x1 += v1 * dt
x2 += v2 *dt
t1.set_x(x1)
t2.set_x(x2)
return [t1,t2]