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
|
# -*- coding: utf-8 -*- #
#Test de la methode de Monte Carlo
from Tkinter import *
from math import *
from random import randrange
def ord(ordd):
ordd = Ordonnees - ordd
return ordd
def calc():
PtsD = 0
Entree = int(Ent.get())
for i in range(1,int(Ent.get())):
Xpoint = randrange (0,100)
Ypoint = randrange (0,100)
Can1.create_oval(Xpoint,ord(Ypoint),Xpoint,ord(Ypoint),width=3)
if sqrt(Ypoint**2 + Xpoint**2) <= 1:
PtsD = PtsD + 1
Rapport = PtsD - Entree
Lab.configure(text = "Rapport : " + str(Rapport)
Fen1 = Tk()
Ordonnees = 200
Abscisses = 200
Can1 = Canvas(Fen1, width=Abscisses, height=Ordonnees)
Can1.pack()
Boutton1 = Button(Fen1, text="Tracer et calculer", command=calc)
Can1.create_rectangle(0,ord(0),100,ord(100))
Can1.create_arc(-100,ord(-100),100,100,fill="red")
#Définit par les coordonnéées d'un point moins son rayon
#et ce point plus le rayon.
#Ici, cet arc commence a l'X = 0 et son rayon est 100
#Donc 0 - 100 = -100
#Il se termine donc à -100 + rayon
#Donc à 100
Ent = Entry(Fen1)
Lab = Label(Fen1, text = "Rapport :")
Lab.pack()
Ent.pack()
Boutton1.pack()
Fen1.mainloop() |
Partager