begin process at 2010 09 04 19:17:09
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > TRACER UNE FONCTION

TRACER UNE FONCTION


 Information sur la source

Note :
7 / 10 - par 1 personne
7,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Divers Classé sous :fonction, Tracer, tracer fonction Niveau :Débutant Date de création :23/12/2007 Vu :3 158

Auteur : kouakou021988

Ecrire un message privé
Commentaire sur cette source (1)
Ajouter un commentaire et/ou une note

 Description

Juste une appli me permettant de tracer des fonction:
Exemple: cos(x)
Nota Bene:Entrer (x)**2 au lieu de x**2

Source

  • # -*- coding: iso8859-15 -*-
  • from Tkinter import*
  • from math import*
  • import tkMessageBox
  • ref=[]
  • dic={}
  • class Application(Frame):
  • """Mise en place de l'interface"""
  • def __init__(self):
  • Frame.__init__(self)
  • self.master.title("::.Ma fonction.::-By Kouakou021988")
  • self.configure(bg="grey40",bd=0,relief=FLAT)
  • self.master.resizable(width=False, height=False)
  • self.master.protocol("WM_DELETE_WINDOW", self.quitter)
  • self.pack(side=TOP)
  • self.coul=['red','blue','yellow','green']
  • self.coord=[]
  • self.courb=['none']
  • self.build()
  • def build(self):
  • """mise en place des bouton,..."""
  • Label(self,text="f(x): ",font='arial 10 italic',background='grey40',fg='white').pack(side=LEFT)
  • self.ent_fct=Entry(self,width=25,font='arial 10 bold',relief=FLAT,fg='black')
  • self.ent_fct.pack(side=LEFT,fill=BOTH,expand=1)
  • Button(self,text="Tracer",font='arial 8 bold',background='grey40',
  • foreground='white',command=self.traceur).pack(side=RIGHT)
  • self.can=Canvas(self.master,bg='black',height=400,width=600)
  • self.can.pack(side=LEFT,fill=BOTH,expand=1)
  • pas=25
  • self.can.create_line(10,200,600,200,arrow=LAST,fill='white') #axe x
  • for x in range(1,11):
  • stx=300+x*pas
  • self.can.create_line(stx,0,stx,400,fill='grey40') #196/204
  • self.can.create_text(stx,210,text=str(x),fill='white',font='arial 6')
  • for x in range(1,11):
  • stx=300-x*pas
  • self.can.create_line(stx,0,stx,400,fill='grey40')
  • self.can.create_text(stx,210,text='-'+str(x),fill='white',font='arial 6')
  • self.can.create_line(300,395,300,5,arrow=LAST,fill='white') #axe y
  • for y in range(1,8):
  • sty=200+y*pas
  • self.can.create_line(0,sty,600,sty,fill='grey40') #296/304
  • self.can.create_text(310,sty,text='-'+str(y),fill='white',font='arial 6')
  • for y in range(1,8):
  • sty=200-y*pas
  • self.can.create_line(0,sty,600,sty,fill='grey40')
  • self.can.create_text(310,sty,text=str(y),fill='white',font='arial 6')
  • self.can.create_text(305,210,text=str(0),fill='white',font='arial 6')
  • fram=Frame(self.master)
  • fram.pack(side=RIGHT)
  • self.lstbox=Listbox(fram,height=5,font='arial 8 bold',fg='black')
  • self.lstbox.pack(side=TOP)
  • self.lstbox.insert(END,'none')
  • Button(fram,text="Reset",font='arial 8',command=self.reset).pack(side=LEFT)
  • self.re=Button(fram,text="Effacer Tracé",font='arial 8',command=self.efface)
  • self.re.pack(side=LEFT)
  • self.re.config(state=DISABLED)
  • self.lstbox.bind("<Button-1>",self.option)
  • def option(self,event=None):
  • self.master.update()
  • y=event.y
  • y=self.lstbox.nearest(y)
  • y=self.lstbox.get(y)
  • if y!='none':
  • if ref:
  • for i in ref:
  • for x in i: self.can.itemconfig(x, width =1)
  • self.re.config(state=NORMAL)
  • self.y=y #nom de la fct dans le listbox
  • self.coord=dic[self.y]
  • ref.append(self.coord)
  • for i in self.coord:
  • self.can.itemconfig(i, width =3)
  • self.can.lift(i)
  • if y=='none':
  • if self.coord:
  • for i in self.coord:
  • self.can.itemconfig(i, width =1)
  • self.re.config(state=DISABLED)
  • def efface(self):
  • try:
  • for i in self.coord:
  • self.can.delete(i)
  • s=self.courb.index(self.y)
  • self.lstbox.delete(s)
  • self.courb.remove(self.y)
  • self.initialise(self.y)
  • fin=dic.pop(self.y)
  • self.re.config(state=DISABLED)
  • except: pass
  • def initialise(self,f):
  • c=f.split('-->')[1]
  • c=c[1:len(c)-1]
  • self.coul.append(c)
  • def traceur(self):
  • fct=self.ent_fct.get()
  • if fct:
  • try: c=self.coul.pop()
  • except: tkMessageBox.showerror("Ma fonction","Limite de fonction atteinte")
  • else:
  • self.ph="f(x)="+fct+"-->("+c+")"
  • self.courbe(fct,c)
  • self.lstbox.insert(END,self.ph)
  • self.courb.append(self.ph)
  • else: pass
  • def reset(self):
  • try:
  • l=dic.keys()
  • for i in l:
  • a=dic.pop(i)
  • for x in a: self.can.delete(x)
  • self.lstbox.delete(1,END)
  • except: pass
  • self.coul=['red','blue','yellow','green']
  • def courbe(self,fonction="(x)**2.",color="red"):
  • """Courbe de la fonction:'(x)**2.' par defaut"""
  • self.func=fonction
  • curve=[]
  • x=0
  • while x<12:
  • try:
  • if "exp" in self.func:
  • self.func=fonction.replace('exp','zzz')
  • self.func=self.func.replace('x',str(x))
  • self.func=self.func.replace('zzz','exp')
  • y=eval(self.func)
  • else: y=eval(self.func.replace('x',str(x)))
  • except: pass
  • else: curve.append((x*25+300,(-y)*25+200))
  • x+=0.01
  • try: a=self.can.create_line(curve,fill=color,smooth=1)
  • except: a=""
  • x=0
  • curve=[]
  • while x>-12.0:
  • try:
  • if "exp" in self.func:
  • self.func=fonction.replace('exp','zzz')
  • self.func=self.func.replace('x',str(x))
  • self.func=self.func.replace('zzz','exp')
  • y=eval(self.func)
  • else: y=eval(self.func.replace('x',str(x)))
  • except: pass
  • else: curve.append((x*25+300,(-y)*25+200))
  • x-=0.01
  • try: b=self.can.create_line(curve,fill=color,smooth=1)
  • except: b=""
  • dic[self.ph]=(a,b)
  • def test(self,v):
  • pass
  • def quitter(self):
  • self.can.delete(ALL)
  • self.master.destroy()
  • ###--------------------------------------------------------------##############
  • if __name__=='__main__':
  • app=Application()
  • app.mainloop()
# -*- coding: iso8859-15 -*-

from Tkinter import*
from math import*
import tkMessageBox


ref=[]
dic={}
class Application(Frame):
        """Mise en place de l'interface"""
        def __init__(self):
                Frame.__init__(self)
                self.master.title("::.Ma fonction.::-By Kouakou021988")
                self.configure(bg="grey40",bd=0,relief=FLAT)
                self.master.resizable(width=False, height=False)
                self.master.protocol("WM_DELETE_WINDOW", self.quitter)
                self.pack(side=TOP)
                self.coul=['red','blue','yellow','green']
                self.coord=[]
                self.courb=['none']
                self.build()

        def build(self):
                """mise en place des bouton,..."""
                Label(self,text="f(x): ",font='arial 10 italic',background='grey40',fg='white').pack(side=LEFT)
                self.ent_fct=Entry(self,width=25,font='arial 10 bold',relief=FLAT,fg='black')
                self.ent_fct.pack(side=LEFT,fill=BOTH,expand=1)
                Button(self,text="Tracer",font='arial 8 bold',background='grey40',
                       foreground='white',command=self.traceur).pack(side=RIGHT)
                self.can=Canvas(self.master,bg='black',height=400,width=600)
                self.can.pack(side=LEFT,fill=BOTH,expand=1)
                pas=25
                self.can.create_line(10,200,600,200,arrow=LAST,fill='white')        #axe x
                for x in range(1,11):
                        stx=300+x*pas
                        self.can.create_line(stx,0,stx,400,fill='grey40')           #196/204
                        self.can.create_text(stx,210,text=str(x),fill='white',font='arial 6')
                for x in range(1,11):
                        stx=300-x*pas
                        self.can.create_line(stx,0,stx,400,fill='grey40')
                        self.can.create_text(stx,210,text='-'+str(x),fill='white',font='arial 6')
                self.can.create_line(300,395,300,5,arrow=LAST,fill='white')         #axe y
                for y in range(1,8):
                        sty=200+y*pas
                        self.can.create_line(0,sty,600,sty,fill='grey40')           #296/304
                        self.can.create_text(310,sty,text='-'+str(y),fill='white',font='arial 6')
                for y in range(1,8):
                        sty=200-y*pas
                        self.can.create_line(0,sty,600,sty,fill='grey40')
                        self.can.create_text(310,sty,text=str(y),fill='white',font='arial 6')
                self.can.create_text(305,210,text=str(0),fill='white',font='arial 6')
                fram=Frame(self.master)
                fram.pack(side=RIGHT)
                self.lstbox=Listbox(fram,height=5,font='arial 8 bold',fg='black')
                self.lstbox.pack(side=TOP)
                self.lstbox.insert(END,'none')
                Button(fram,text="Reset",font='arial 8',command=self.reset).pack(side=LEFT)
                self.re=Button(fram,text="Effacer Tracé",font='arial 8',command=self.efface)
                self.re.pack(side=LEFT)
                self.re.config(state=DISABLED)
                self.lstbox.bind("<Button-1>",self.option)

        def option(self,event=None):
                self.master.update()
                y=event.y
                y=self.lstbox.nearest(y)
                y=self.lstbox.get(y)
                if y!='none':
                        if ref:
                                for i in ref:
                                        for x in i: self.can.itemconfig(x, width =1)   
                        self.re.config(state=NORMAL)
                        self.y=y                                                            #nom de la fct dans le listbox
                        self.coord=dic[self.y]
                        ref.append(self.coord)
                        for i in self.coord:
                                self.can.itemconfig(i, width =3)
                                self.can.lift(i)
                if y=='none':
                        if self.coord:
                                for i in self.coord:
                                        self.can.itemconfig(i, width =1)
                                        self.re.config(state=DISABLED)
                                
        def efface(self):
                try:
                        for i in self.coord:
                                self.can.delete(i)
                        s=self.courb.index(self.y)
                        self.lstbox.delete(s)
                        self.courb.remove(self.y)
                        self.initialise(self.y)
                        fin=dic.pop(self.y)
                        self.re.config(state=DISABLED)
                except: pass

        def initialise(self,f):
                c=f.split('-->')[1]
                c=c[1:len(c)-1]
                self.coul.append(c)
                
        def traceur(self):
                fct=self.ent_fct.get()
                if fct:
                        try:    c=self.coul.pop()
                        except: tkMessageBox.showerror("Ma fonction","Limite de fonction atteinte")
                        else:
                                self.ph="f(x)="+fct+"-->("+c+")"
                                self.courbe(fct,c)
                                self.lstbox.insert(END,self.ph)
                                self.courb.append(self.ph)
                else:   pass
                
        def reset(self):
                try:
                        l=dic.keys()
                        for i in l:
                                a=dic.pop(i)
                                for x in a: self.can.delete(x)
                        self.lstbox.delete(1,END)
                except: pass
                self.coul=['red','blue','yellow','green']
                
        def courbe(self,fonction="(x)**2.",color="red"):
                """Courbe de la fonction:'(x)**2.' par defaut"""
                self.func=fonction
                curve=[]
                x=0
                while x<12:
                        try:
                                if "exp" in self.func:
                                        self.func=fonction.replace('exp','zzz')
                                        self.func=self.func.replace('x',str(x))
                                        self.func=self.func.replace('zzz','exp')
                                        y=eval(self.func)
                                else:   y=eval(self.func.replace('x',str(x)))
                        except: pass
                        else:   curve.append((x*25+300,(-y)*25+200))
                        x+=0.01
                try:    a=self.can.create_line(curve,fill=color,smooth=1)
                except: a=""
                x=0
                curve=[]
                while x>-12.0:
                        try:
                                if "exp" in self.func:
                                        self.func=fonction.replace('exp','zzz')
                                        self.func=self.func.replace('x',str(x))
                                        self.func=self.func.replace('zzz','exp')
                                        y=eval(self.func)
                                else:   y=eval(self.func.replace('x',str(x)))
                        except: pass
                        else:   curve.append((x*25+300,(-y)*25+200))
                        x-=0.01
                try:    b=self.can.create_line(curve,fill=color,smooth=1)
                except: b=""
                dic[self.ph]=(a,b)

        def test(self,v):
                pass
            
        def quitter(self):
                self.can.delete(ALL)
                self.master.destroy()



###--------------------------------------------------------------##############
if __name__=='__main__':
        app=Application()
        app.mainloop()

 Conclusion

Merci.


 Sources du même auteur

Source avec Zip MON REPERTOIRE
WX_REVEIL
REVEIL 2 EN PYTHON
JEU DE MOT
REVEIL EN PYTHON

 Sources de la même categorie

Source avec Zip SCRIPT PERMETTANT DE DÉCODER LA STRUCTURE SECONDAIRE D'UNE P... par Basilio
SUPPRESSION par Rano Its
Source avec Zip RECONNAISSANCE VOCALE par brennal
CONVERTISSEUR DE TEMPÉRATURE par skizo00o
Source avec Zip Source avec une capture I.A. (DÉBUTANT) par Rano Its

 Sources en rapport avec celle ci

CONVERTISSEUR DE TEMPÉRATURE par skizo00o
CALCULATRICE, INTRODUCTION AU LAMBDA par xeolin
Source avec Zip Source avec une capture GRAPHEUR DE FONCTIONS MATHÉMATIQUES par amaury74
Source avec Zip Source avec une capture UN TRACEUR DE FONCTION MATHÉMATIQUE par Gulius
Source avec Zip Source avec une capture TRACER UEN COURBE AVEC LA MÉTHODE D'EULER par LokR

Commentaires et avis

Commentaire de aera group le 04/01/2008 10:42:06 7/10

Ta source n'est pas mal, mais .... il y en existe une autre bien plus "puissante" :
http://www.pythonfrance.com/codes/TRACEUR-FONCTION-MATHEMATIQUE_29942.aspx
Voila, je met quand même 7/10, parce que c'est tout de même pas mal !
Bon courrage pour la suite

 Ajouter un commentaire


Discussions en rapport avec ce code source dans le forum

wxWindow::RegisterHotKey [ par DoudouBidou ] Bonjour à tous(au passage Merci pour ce site, depuis le temps que je l'attends...)J'utilise wxPython pour réaliser mon interface graphique mais je n'a probleme avec os.path.getctime() [ par Bl0tCh ] Voilà, Donc cette fonction est censée me donner la date de creation du fichier (en secondes) mais le probleme c ke elle me donne la premiere date de c liste des process en cours [ par rodrigos ] Bonjour, Je suis sous windows et je cherche &#224; obtenir la liste des process en cours sur le pc. La seule foncyion que j'ai rouv&#233; est la fonc Zope: Contenu d'une liste en fonction d'une autre [ par keumlebarbare ] AU SECOURS!!!! Je suis tout ce qu'il y a de plus d&#233;butant en Zope, et je crois que si je continue &#224; gal&#233;rer comme ca, je me (re)met a Ou trouver la liste des fonction disponible... [ par CotCouture ] Bonjour j'aimerais savoir ou je peux trouver la liste des fonction disponible dans les logiciel office? Cot Couture fonction inconnue [ par xeolin ] je voulai creer cette discussion pour que l'on fasse un jeu : le but est : mettre des fonction que personne utilise ! ca parais bidon mais ca peut existe -t-il un équivalent de la fonction "call" sous Python? [ par Veust ] Bonjour, je suis en train d'ecrire un code sous python qui d'une part doit rentrer des donner dans une liste(jusque là facile) et d'autre part créer u Appel d'une fonction [ par Thomeux ] Bonjour,Je débute en python.J'essais de structurer mon Programme de la manière suivante         :Un fichier bibliothèque fonction,          :Un Fichi utiliser correctement les fonction, débutant niveaux 0+ dx [ par gwenc_hlan ] voilà, en gros, ça fait une semaine que je fait du python et en totu un peu plus de dix jours que je programme. engros : je débute.bon, voilà, je suis définir une fonction dans une fonction ? [ par gwenc_hlan ] bonjour, voilà, je cherche à faire un petit programme à interface graphiques. cependant, j'aimerais savoir s'il est possible de définir une fonction


Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Septembre 2010
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
27282930   

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 1,326 sec (4)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales