IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Tkinter Python Discussion :

programme spirographe, trochoides


Sujet :

Tkinter Python

  1. #1
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 3
    Points : 2
    Points
    2
    Par défaut programme spirographe, trochoides
    Bonjour,
    pour un projet je dois faire un programme qui effectue un tracé de trochoides (équivalent du spirographe). j'ai réussi à faire un programme très simple, mais je dois le réaliser avec des classes et je n'arrive pas à "relier" les classes entre elles. Etant débutante en python,je n'ai pas de grandes connaissances sur les classes et je recherche donc quelques conseils.
    Merci d'avance pour vos réponses.
    Fichiers attachés Fichiers attachés

  2. #2
    Candidat au Club
    Profil pro
    Inscrit en
    Avril 2010
    Messages
    3
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2010
    Messages : 3
    Points : 2
    Points
    2
    Par défaut
    je vais plutot mettre le code ici je pense que cela sera plus lisible

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    112
    113
    114
    115
    116
    117
    118
    119
    # --------------------------------------------------------------------------
    from Tkinter import *
    from tkFont import Font
    import math
    import tkColorChooser
    # ------------------------------------------------------------------------------
    class spiro():
      """Zone de dessin"""
      # ----------------------------------------------------------------------------
      def __init__(self, pos, **keys):
        #self.pos_x = root[11112].get()
        #self.pos_y = root[11122].get()
     
        command = keys['command']
        self.pos_x = spiro(command = choix_util().x)
        self.pos_y = spiro(command = choix_util().y)
     
      # ----------------------------------------------------------------------------
      def fonction(self, pos=None):
        R, r, O = root[113].get(), root[115].get(), root[117].get()
        coords=[]
        if pos is None:
          for t in range(500):
            coords.append((R+r)*math.cos(t)-O*math.cos(((R+r)/r)*t)+self.pos_x)
            coords.append((R+r)*math.sin(t)-O*math.sin(((R+r)/r)*t)+self.pos_y)
          outside_curve=root[11].create_line(coords,fill=color,tag='line',activedash=(2,2))
     
        else:
          for t in range(500):
            coords.append((R-r)*math.cos(t)+O*math.cos(((R-r)/r)*t)+self.pos_x)
            coords.append((R-r)*math.sin(t)-O*math.sin(((R-r)/r)*t)+self.pos_y)
            inside_curve=root[11].create_line(coords,fill=color,tag='line',activedash=(2,2))
     
    #-------------------------------------------------------------------------------
    class debut():
      """crée l'affichage du jeu"""   
      global root
      root = {0: Tk()}
      # ----------------------------------------------------------------------------
      root[1] = Frame(root[0])
      root[1].pack(side=TOP, fill=BOTH)
      root[11] = Frame(root[1])
      root[11].pack(side=LEFT, fill=BOTH)
      root[12] = Canvas(root[1], bg='white',width=500, height=500, relief=SOLID, border=3)
      root[12].pack(side=LEFT, fill=BOTH, expand=YES)
     
    # ------------------------------------------------------------------------------
    class choix_util():
     
      def __init__(self):
        self.x = root[11112].get()
        self.y = root[11122].get()
     
      root[111]= Frame(root[11])
      root[111].pack(side=TOP, fill=BOTH,pady=5)
     
      root[1111]=Frame(root[111])
      root[1111].pack(side=LEFT,fill=BOTH,pady=5)
      root[11111]=Label(root[1111],text='position de x')
      root[11111].pack(side=TOP, fill=BOTH,pady=5)
      root[11112] = Scale(root[1111], orient=HORIZONTAL, to=400)
      root[11112].pack(side=TOP, fill=BOTH, expand=YES)
     
      root[1112]=Frame(root[111])
      root[1112].pack(side=LEFT,fill=BOTH,pady=5)
      root[11121]=Label(root[1112],text='position de y')
      root[11121].pack(side=TOP, fill=BOTH,pady=5)
      root[11122] = Scale(root[1112], orient=HORIZONTAL, to=400)
      root[11122].pack(side=TOP, fill=BOTH, expand=YES)
      # ----------------------------------------------------------------------------
      root[112] = Label(root[11], text='rayon de cercle fixe (1-100)')
      root[112].pack(side=TOP, fill=BOTH,pady=5)
      root[113] = Scale(root[11], orient=HORIZONTAL,from_=1, to=100)
      root[113].pack(side=TOP, fill=BOTH, expand=YES)
      root[114] = Label(root[11], text='deplacement du rayon du cercle (1-100)')
      root[114].pack(side=TOP, fill=BOTH)
      root[115] = Scale(root[11], orient=HORIZONTAL, from_=1, to=100)
      root[115].pack(side=TOP, fill=BOTH, expand=YES)
      root[116] = Label(root[11], text='deplacement de compensation du cercle (1-100)')
      root[116].pack(side=TOP, fill=BOTH)
      root[117] = Scale(root[11], orient=HORIZONTAL, from_=1, to=100)
      root[117].pack(side=TOP, fill=BOTH, expand=YES)
     
    # ------------------------------------------------------------------------------
    class dessin():
     
      def cb_delete():
        """supprime tous les dessins dans la fenetre"""
        root[11].delete(root[11],'line')
     
      # ------------------------------------------------------------------------------
      def cb_color():
        """permet à l'utilisateur de choisir la couleur de la courbe"""
        val=tkColorChooser.askcolor()
        return val
     
      root[118] = Frame(root[11])
      root[118].pack(side=TOP,fill=BOTH,expand=YES)
      root[1181]=Button(root[118], text='deplacement intérieur',command = spiro(True))
      root[1181].pack(side=LEFT, fill=BOTH, expand=YES,pady=5,padx=5)
      root[1182] = Button(root[118], text='déplacement extérieur',command = spiro(False))
      root[1182].pack(side=LEFT, fill=BOTH, expand=YES,pady=5,padx=5)
    ##  root[119] = Label(root[11], text='Coefficient d agrandissement (5-10)')
    ##  root[119].pack(side=TOP, fill=BOTH)
    ##  root[130] = Scale(root[11], orient=HORIZONTAL, from_=5, to=10)
    ##  root[130].pack(side=TOP, fill=BOTH, expand=YES)
      root[119] = Button(root[11], text= 'effacer', command=cb_delete)
      root[119].pack(side=TOP, fill=BOTH,padx=5,pady=2)
     
    # ==============================================================================
    if __name__ == '__main__': # testcode de la classe spiro
      # ----------------------------------------------------------------------------
      root=debut()
      root.title('Trace de Trochoides')
      root.protocol('WM_DELETE_WINDOW', root.quit)
      root.minsize(root.winfo_width(), root.winfo_height())
      root.resizable(1,1)
      root.mainloop(); root.destroy()
    # ==============================================================================

Discussions similaires

  1. Programme de boot qui passe la main à Windows
    Par Bob dans le forum Assembleur
    Réponses: 7
    Dernier message: 25/11/2002, 03h08
  2. [Kylix] Probleme d'execution de programmes...
    Par yopziggy dans le forum EDI
    Réponses: 19
    Dernier message: 03/05/2002, 14h50
  3. communication entre programmes
    Par jérôme dans le forum C
    Réponses: 12
    Dernier message: 16/04/2002, 08h05
  4. Comment débuter en programmation ?
    Par Marc Lussac dans le forum Débuter
    Réponses: 0
    Dernier message: 08/04/2002, 11h29
  5. [Kylix] icone associée à un programme
    Par Anonymous dans le forum EDI
    Réponses: 1
    Dernier message: 22/03/2002, 09h43

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo