Forcer l'affichage avant la fin des calculs

jeanmartre Messages postés 9 Date d'inscription samedi 18 novembre 2017 Statut Membre Dernière intervention 23 février 2018 - Modifié le 8 janv. 2018 à 18:48
Whismeril Messages postés 19025 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 19 avril 2024 - 8 janv. 2018 à 20:32
Bonjour, bonsoir,
j'ai une problème (c'est pourquoi je suis ici !!)
j'ai créé un petit programme qui permet de tracer des courbes mathématiques.
pour cela, j'ai découpé la courbe en plein de petites droites de quelques pixels de longueur...
le problème, c'est que l'ordi calcul d'abord la position de TOUTES les droites et les affiche ensuite. La courbe apparaît donc d'un seul coup. Est-il possible d'afficher les droites au fur et à mesure que l'ordinateur calcule leur position ?
Les calculs sont d'ailleurs trop nombreux et je n'arrive pas à les réduire. Les autres remarques pour améliorer mon code sont bien-entendu les bienvenues... :)

from tkinter import * ; from math import * ; import tkinter as tk

a,b=1350,650 ; l=50 ; m=l+20 ; h1,h2,h3,h4=20,12,45,37

fen=Tk()
contour = Canvas(fen, width=a, height=60) ; traceur = Canvas(fen, width=a, height=b, bg='ivory') ; contour.pack() ; traceur.pack(side = BOTTOM)

contour.create_text(l, h1, text="x min :", fill='green') ; contour.create_text(l+178,h1, text="x max :", fill='green') ; contour.create_text(l,h3, text="y min :", fill='green') ; contour.create_text(l+178,h3, text="y max :", fill='green') ; contour.create_text(l+502,h1, text="f(x)=")
xmin, xmax, ymin, ymax, entree = Entry(fen), Entry(fen), Entry(fen), Entry(fen), Entry(fen)
xmin.place(x=m, y=h2) ; xmax.place(x=m+180, y=h2) ; ymin.place(x=m, y=h4) ; ymax.place(x=m+180, y=h4) ; entree.place(x=m+496, y=h2)

def deplaceraxes(axes):
   x1=float(xmin.get()) ; x2=float(xmax.get()) ; y1=float(ymin.get()) ; y2=float(ymax.get())
   a1 = (y2*b)/(y2-y1) ; a2 = a-(x2*a)/(x2-x1)
   a21 = a2-a2/x1 ; a22 = a2+a2/x1 ; a11 = a1-a1/y2 ; a12 = a1+a1/y2
   traceur.delete(ALL)
   traceur.create_line(0, a1, a-20, a1, arrow='last') ; traceur.create_line(a2, b, a2, 20, arrow='last')
   traceur.create_line(a21, a1-3, a21, a1+3) ; traceur.create_line(a22, a1-3, a22, a1+3) ; traceur.create_line(a2-3, a12, a2+3, a12) ; traceur.create_line(a2-3, a11, a2+3, a11)
   traceur.create_text(a22, a1-10, text="-1") ; traceur.create_text(a21, a1-10, text="1") ; traceur.create_text(a2-10, a12, text="-1") ; traceur.create_text(a2-7, a11, text="1")

def tracer(f):
   x1=float(xmin.get()) ; x2=float(xmax.get()) ; y1=float(ymin.get()) ; y2=float(ymax.get())
   a1 = (y2*b)/(y2-y1) ; a2 = a-(x2*a)/(x2-x1)
   x = x1 ; z=15 ; i = entree.get()
   for z in range (12, 1000000, 1):
     traceur.delete(z)
   while x<x2:
     x=x+0.00001
     n=eval(i)
     traceur.create_line(a2-x*(a2/x1),a1-n*(a1/y2),a2-x*(a2/x1)+0.07,a1-n*(a1/y2))

bout1 =  Button(contour, text='Quitter', command = fen.destroy) ; bout1.place(x=a-100,y=5)

entree.bind('<Return>', tracer) ; xmax.bind('<Return>', deplaceraxes) ; ymin.bind('<Return>', deplaceraxes) ; ymax.bind('<Return>', deplaceraxes) ; xmin.bind('<Return>', deplaceraxes)

fen.mainloop()

je code en python 3.6
merci d'avance

1 réponse

Whismeril Messages postés 19025 Date d'inscription mardi 11 mars 2003 Statut Contributeur Dernière intervention 19 avril 2024 656
8 janv. 2018 à 20:32
Bonsoir
je ne suis pas codeur Python, mais je sais qu'un des ses points forts est le tracé de courbes.
Alors pourquoi réinventer l'eau chaude?
http://www.courspython.com/introduction-courbes.html
0
Rejoignez-nous