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()
# ============================================================================== |