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 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
   | from tkinter import *
import time
from math import cos, tan, pi
 
def cercle(x, y, r, coul='black'):
    "tracé d'un cercle de centre (x,y) et de rayon r"
    can.create_oval(x-r, y-r, x+r, y+r, outline=coul,fill='red')
def effacecercle (x,y,r,coul='white'):
    can.create_oval(x-r, y-r, x+r, y+r, outline='white',fill='white')
def figure_1():
    global X, Y,h,L, Xp,Yp, LaxeY, LaxeX,pY,pX,entr1 #X,Y coordonnées absolues dans can
 
    x = 50
    # Effacer d'abord tout dessin préexistant :
    #can.delete(ALL)????????????????????????????????????????????????
    #création des axes
    #tracé axe des abscisses
    can.create_line(70,Hcan-50,70+LaxeX,Hcan-50,width=1,fill='red')
    #tracé axe des ordonnées
    can.create_line(70,50,70,50+LaxeY,width=1,fill='red')
    #création des graduations
    #graduations abscisses
    can.create_line(70+pX,50+LaxeY,70+pX,50+LaxeY+10,width=1,fill='red')
    can.create_line(70+2*pX,50+LaxeY,70+2*pX,50+LaxeY+10,width=1,fill='red')
    can.create_line(70+3*pX,50+LaxeY,70+3*pX,50+LaxeY+10,width=1,fill='red')
    can.create_line(70+4*pX,50+LaxeY,70+4*pX,50+LaxeY+10,width=1,fill='red')
    can.create_line(70+5*pX,50+LaxeY,70+5*pX,50+LaxeY+13,width=1,fill='red')
    can.create_line(70+6*pX,50+LaxeY,70+6*pX,50+LaxeY+10,width=1,fill='red')
    can.create_line(70+7*pX,50+LaxeY,70+7*pX,50+LaxeY+10,width=1,fill='red')
    can.create_line(70+8*pX,50+LaxeY,70+8*pX,50+LaxeY+10,width=1,fill='red')
    can.create_line(70+9*pX,50+LaxeY,70+9*pX,50+LaxeY+10,width=1,fill='red')
    can.create_line(70+10*pX,50+LaxeY,70+10*pX,50+LaxeY+13,width=1,fill='red')
    # affichage type de coordonnées sur les axex
    #abscisses
    can.create_text(1250,770,text="L(m)")
    can.create_text(185,770,text="1")
    can.create_text(645,770,text="5")
    #ordonnées
    can.create_text(50,80,text="h(m)")
    can.create_text(50,650,text="1")
    can.create_text(50,250,text="5")
    #graduations ordonnées
    can.create_line(70,50+LaxeY-pY,70-10,50+LaxeY-pY,width=1,fill='red')
    can.create_line(70,50+LaxeY-2*pY,70-10,50+LaxeY-2*pY,width=1,fill='red')
    can.create_line(70,50+LaxeY-3*pY,70-10,50+LaxeY-3*pY,width=1,fill='red')
    can.create_line(70,50+LaxeY-4*pY,70-10,50+LaxeY-4*pY,width=1,fill='red')
    can.create_line(70,50+LaxeY-5*pY,70-13,50+LaxeY-5*pY,width=1,fill='red')
    can.create_line(70,50+LaxeY-6*pY,70-10,50+LaxeY-6*pY,width=1,fill='red')
 
 
 
 
 
    #??????????????????????????????????????
    #?????????????????????????????????????
 
 
    #??????????????????????????????????????????????
    #tracé de la courbe
    #can.create_oval(100-10, 100-10, 100+10, 100+10, outline='green',fill='red')
    rayon=10
    #angd=60
    while L< 10:
        Xp, Yp = X, Y
        ang=pi*int(angd.get())/180
        effacecercle(X, Y, rayon)
        h= -0.5*9.81*L*L/(v0*v0*cos(ang)*cos(ang))+L*tan(ang)
        X=70+LaxeX*L/10
        Y=-LaxeY*h/6+50+LaxeY # en instance
        can.create_line(Xp, Yp, X, Y, fill ='black')
 
        cercle(X, Y, rayon)
        can.update()
        time.sleep(0.3)
 
        L +=0.1
 
##### Programme principal : ############
# initialisation des coordonnées, des vitesses et du témoin d'animation :
#70px=décalage vers la droite de l'axe des ordonnées
L,flag ,Lcan, Hcan= 0,0,1400,800
X=70
Y = Hcan -50
v0=10
#Lcan=largeur du canevas Hcan= hauteur du canevas
LaxeX=Lcan-250 #largeur axes des abscisses
LaxeY=Hcan-100 #longueur axe des ordonnées
pX = LaxeX/10 #pas de graduation x pour 10 intervalles
pY = LaxeY/7 #pas de graduation y pour 10 intervalles
 
h=0
L=0
 
def on_quit():
    global L
    L = 10
    fen.quit()
 
fen = Tk()
fen.title('Balistique')
angd = StringVar()
angd.set('45')
can = Canvas(fen, width=Lcan, height=Hcan, bg='white')
can.pack()
Button(fen, text='Lancer', command=figure_1).pack(side=RIGHT, padx=10)
txt1=Label(fen, text='angle de tir en degré')
entr1=Entry(fen, textvariable=angd)
txt1.place(x=100, y=100)
entr1.place(x=150, y=150)
fen.protocol("WM_DELETE_WINDOW", on_quit)
fen.mainloop() | 
Partager