1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
| # révolutions de mercure et venus autour du soleil
# imports
from tkinter import Tk, Canvas
from math import sin, cos, pi
# fonctions
def revolution(nom, x1, y1, angle, pas, dec, coul, taille, memx1=245, memy1=154, incrangle=5):
'révolution astre'
memx1, memy1 = x1, y1
if angle < 360 : angle += incrangle
else : angle = 5
radian = angle * (2*pi) / 360
x1, y1 = x1 + pas * cos(radian), y1 + pas * sin(radian)
can.itemconfigure(nom, fill = coul)
can.coords(nom, x1, y1 + dec, x1 + taille, y1 + dec + taille)
fen.after(100, revolution, nom, x1, y1, angle, pas, dec, coul, taille, memx1, memy1, incrangle)
# programme principal
fen = Tk() # racine des widgets
# widgets
can=Canvas(fen, bg = 'black', height = 500, width = 500)
can.pack()
for i in range(3):
globals()['astre' + str(i)] = can.create_oval(205, 205, 295, 295, fill = 'yellow') # création des 3 astres
revolution(astre1, 245, 145, 5, 8, 0, 'grey', 30) # lance la révolution de mercure
revolution(astre2, 245, 145, 5, 16, -95 ,'orange', 40) # Lance la révolution de venus
# réceptionnaire d'événements
fen.mainloop() |