
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.animation import ArtistAnimation
#%pylab qt

time = np.linspace(0, 10, 500)
deltaT=10.0/500

y=[]
y0=10.0 #m initial height
velocity=0 #initial vekocity
acceleration=-9.8 #m/s**2inital acceleration
restitution=0.9 #Loss of velocity at each ground hit


yold=0
localTime=0
counter=0

ynew=yold
for t in time:
    localTime=deltaT*counter
    ynew=y0+velocity*localTime+0.5*acceleration*localTime**2    
    y.append(ynew)
    if ynew<=0:
        velocity= restitution*(yold-ynew)/deltaT
        y0=0
        localTime=0
        counter=0
    yold=ynew  
    counter+=1
    
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.set_ylim(0,10)

artists = []
for i in range(len(time)):
    im = ax.imshow(np.random.randn(1, 1), extent=(0, 10, -10, 10))
    circle = Circle([time[i], y[i]],
        radius=0.25, color='yellow', fill=True)
    ax.add_patch(circle)
    artists.append([im, circle])
    
anim = ArtistAnimation(fig, artists, interval=10,repeat=False)