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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| # -*- coding:utf-8 -*-
from time import *
from Tkinter import *
from math import sin, cos
#Programme traçant une trajectoire double sinusoidale
#---- Initialisation des variables
Xo,Yo,Rbille,Rroulette = 200,200,5,80
t0=time()
#---- Affichage de la position au temps t
timer = None
def play ():
global timer
if timer:
return
t=time()
X=Xo-(90-((5)*(t-t0)))*sin(150*(t-t0))
Y=Yo-(90-((5)*(t-t0)))*cos(-150*(t-t0))
can1.coords('bille',X-Rbille,Y-Rbille,X+Rbille,Y+Rbille)
timer = fen1.after(100,play)
def stop():
global timer
if timer:
fen1.after_cancel(timer)
timer = None
#-Programme principal
#--- Ouverture de la fenêtre principale
fen1 = Tk()
#---- Définition d'un canevas appelé can1
can1 = Canvas(fen1,bg='dark green',height=400,width=400)
can1.pack(side=RIGHT)
Button(fen1, text='lancer', command=play).pack()
Button(fen1, text='stop', command=stop).pack()
can1.create_oval(120,120,280,280,width=10 ,fill="RosyBrown4")
can1.create_oval(195,195,205,205,width=0,fill='white', tag='bille')
fen1.mainloop() |
Partager