import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as anim
from matplotlib.widgets import Slider, Button, RadioButtons

a=np.loadtxt("kepler.dat")

fig,p=plt.subplots(figsize=(8,8))
p.set_xlim(-50000, 10000)
p.set_ylim(-30000, 30000)
p.grid()
p.set_aspect("equal")
sat, = p.plot([], [], '.',color="red")

maa=plt.Circle((0,0),6378,color="green")
ohu=plt.Circle((0,0),6478,color="blue",fill=False)
p.add_artist(maa)
p.add_artist(ohu)

def animf(frame):
    sat.set_data(a[frame,1], a[frame,2])
    vel_txt.set_text('Kiirus = %10.3f km/s' % (a[frame,6]))
    dist_txt.set_text('Korgus = %10.3f km' % (a[frame,5]-6378.))
    kiirend_txt.set_text('Kiirendus = %10.3f m/s2' % (a[frame,7]*1000.))
    time_txt.set_text('Aeg = %8.3f min = %8.3f tund' % (a[frame,0]/60.,a[frame,0]/3600.))
    return sat,time_txt,dist_txt,vel_txt,kiirend_txt
    
vel_txt = p.text(0.02,0.90,'',transform=p.transAxes)
dist_txt = p.text(0.02,0.95,'',transform=p.transAxes)
kiirend_txt = p.text(0.02,0.85,'',transform=p.transAxes)
time_txt = p.text(0.02,0.80,'',transform=p.transAxes)

ani = anim.FuncAnimation(fig, animf, range(0,len(a[:,0]),10),interval=0,repeat=False,blit=True)
plt.show()