from Tkinter import * from math import * import datetime import itertools #Fenêtre Mafenetre = Tk() Mafenetre.title('Mouvement des Planètes') def premieres(): global proche, eloigne proche = True eloigne = False Effacer() Soleil() Trajectoire_de_Mercure() Mercure(-13,56,0) Trajectoire_de_Venus() Venus(-64,87,0) Trajectoire_de_Terre() Terre(138,-58,0) Trajectoire_de_Mars() Mars(227,20,0) def suivantes(): global proche, eloigne proche = False eloigne = True Effacer() Soleil2() Trajectoire_de_Jupiter() Jupiter(32,-71,0) Trajectoire_de_Saturne() Saturne(92,105,0) Anneau_de_Saturne(92,105,0) Trajectoire_de_Uranus() Uranus (-283,-64,0) Trajectoire_de_Neptune() Neptune(-417,170,0) def saisie(): jour1=jour.get() i=int(jour1) Trajectoire_de_Mercure() Soleil() Trajectoire_de_Venus() Trajectoire_de_Terre() Trajectoire_de_Mars() terre(i) mercure(i) venus(i) mars(i) date(i) def saisie2(): jour1=jour.get() i=int(jour1) Soleil2() Trajectoire_de_Jupiter() Trajectoire_de_Saturne() Trajectoire_de_Uranus() Trajectoire_de_Neptune() jupiter(i) saturne(i) uranus(i) neptune(i) date(i) def saisie3(): global proche, eloigne Effacer() if proche == True: saisie() if eloigne == True: saisie2() def mercure(jour1): anglemercure=2*pi*((jour1)/87.66)+1.8 dxmercure=58*(cos(anglemercure)) dymercure=58*(sin(anglemercure)) Mercure(dxmercure,dymercure,anglemercure) def venus(jour1): anglevenus=2*pi*((jour1)/226.455)+2.2 dxvenus=108*(cos(anglevenus)) dyvenus=108*(sin(anglevenus)) Venus(dxvenus,dyvenus,anglevenus) def terre(jour1): angleterre=2*pi*((jour1)/365.25)-0.4 dxterre=150*(cos(angleterre)) dyterre=150*(sin(angleterre)) Terre(dxterre,dyterre,angleterre) def mars(jour1): anglemars=2*pi*((jour1)/687.67)+0.09 dxmars=228*(cos(anglemars)) dymars=228*(sin(anglemars)) Mars(dxmars,dymars,anglemars) def Soleil(): x = 600; y = 475; r = 27 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='#FFFF00', fill='#FFFF00') def Trajectoire_de_Mercure(): x = 600; y = 475; r = 58 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='white') def Mercure(dxmercure,dymercure,anglemercure): x = 600+dxmercure; y = 475-dymercure; r = 8 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='grey', fill='grey') def Trajectoire_de_Venus(): x = 600; y = 475; r = 108 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='white') def Venus(dxvenus,dyvenus,anglevenus): x = 600+dxvenus; y = 475-dyvenus; r = 12 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='#B18904', fill='#B18904') def Trajectoire_de_Terre(): x = 600; y = 475; r = 150 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='white') def Terre(dxterre,dyterre,angleterre): x = 600+dxterre; y = 475-dyterre; r = 14 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='#0080FF', fill='#0080FF') def Trajectoire_de_Mars(): x = 600; y = 475; r = 228 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='white') def Mars(dxmars,dymars,anglemars): x = 600+dxmars; y = 475-dymars; r = 10 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='#FE9A2E', fill='#FE9A2E') def jupiter(jour1): anglejupiter=2*pi*((jour1)/4331.865)-1.15 dxjupiter=78*(cos(anglejupiter)) dyjupiter=78*(sin(anglejupiter)) Jupiter(dxjupiter,dyjupiter,anglejupiter) def saturne(jour1): anglesaturne=2*pi*((jour1)/10774.875)+0.85 dxsaturne=140*(cos(anglesaturne)) dysaturne=140*(sin(anglesaturne)) Saturne(dxsaturne,dysaturne,anglesaturne) Anneau_de_Saturne(dxsaturne,dysaturne,anglesaturne) def uranus(jour1): angleuranus=2*pi*((jour1)/30681.0)+3.365 dxuranus=290*(cos(angleuranus)) dyuranus=290*(sin(angleuranus)) Uranus(dxuranus,dyuranus,angleuranus) def neptune(jour1): angleneptune=2*pi*((jour1)/60266.25)+2.755 dxneptune=450*(cos(angleneptune)) dyneptune=450*(sin(angleneptune)) Neptune(dxneptune,dyneptune,angleneptune) def Soleil2(): x = 600; y = 475; r = 24 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='#FFFF00', fill='#FFFF00') def Trajectoire_de_Jupiter(): x = 600; y = 475; r = 78 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='white') def Jupiter(dxjupiter,dyjupiter,anglejupiter): x = 600+dxjupiter; y = 475-dyjupiter; r = 20 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='#F3E2A9', fill='#F3E2A9') def Trajectoire_de_Saturne(): x = 600; y = 475; r = 140 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='white') def Saturne(dxsaturne,dysaturne,anglesaturne): x = 600+dxsaturne; y = 475-dysaturne; r = 16 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='#F7D358', fill='#F7D358') def Anneau_de_Saturne(dxsaturne,dysaturne,anglesaturne): x = 600+dxsaturne; y = 475-dysaturne; r = 24 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='#F7D358') def Trajectoire_de_Uranus(): x = 600; y = 475; r = 290 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='white') def Uranus (dxuranus,dyuranus,angleuranus): x = 600+dxuranus; y = 475-dyuranus; r = 14 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='#81BEF7', fill='#81BEF7') def Trajectoire_de_Neptune(): x = 600; y = 475; r = 450 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='white') def Neptune(dxneptune,dyneptune,angleneptune): x = 600+dxneptune; y = 475-dyneptune; r = 10 Canevas.create_oval(x-r, y-r, x+r, y+r, outline='#0080FF', fill='#0080FF') def Effacer(): """ Efface la zone graphique """ Canevas.delete(ALL) def Entree (event): touche = event.keysym if touche == 'Return': saisie3() def date(jour1): date = datetime.datetime(2013,1,1)+datetime.timedelta(days=jour1) date2 = date.strftime(' %d %B %Y ') widget2 = Label(text=date2, fg='white', bg='black') widget2.grid(row=0,column=0) # Image de Fond : fond = PhotoImage(file="fond.gif") # Zone Graphique : Largeur = 1200 Hauteur = 950 Canevas = Canvas(Mafenetre,width = Largeur, height =Hauteur, bg ='black') #item = Canevas.create_image(0,0,anchor=NW, image=fond) Canevas.grid(row=0, column=0,rowspan=20, columnspan=12) # Bouton Afficher Planètes Proches: BoutonGo = Button(Mafenetre, text ='Planètes proches', command = premieres) BoutonGo.grid(row=21, column=0,) # Bouton Afficher Planètes éloignés : BoutonGo = Button(Mafenetre, text ='Planètes éloignées', command = suivantes) BoutonGo.grid(row=21, column=1, sticky=W) # Label "Jour" Label1 = Label(Mafenetre, text = 'Jour : ') Label1.grid (row=21, column=3, sticky=E) # Zone de saisie jour = StringVar() ligne_texte = Entry(Mafenetre, textvariable=jour, width=25) ligne_texte.grid(row=21, column=4, sticky=W) ligne_texte.bind('',Entree) # Bouton Ok : BoutonOk = Button(Mafenetre, text ='OK', command = saisie3) BoutonOk.grid (row=21, column=5, pady=10, sticky=W) # Bouton Quitter : BoutonQuitter = Button(Mafenetre, text ='Quitter', command = Mafenetre.destroy) BoutonQuitter.grid(row=21, column=11,) Mafenetre.mainloop()