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
| # -*- coding: utf-8 -*-
from Tkinter import *
from math import tan, pi
def trace(f, a, b, step, scale, translate):
"""
Trace la représentation graphique
d'une fonction f de l'abscisse a à b.
"""
x0, y0 = translate
x = a
lines = []
while x <= b:
x1 = (x * scale) + x0
y1 = - (f(x) * scale) + y0
x2 = ((x - step) * scale) + x0
y2 = (- f(x - step) * scale) + y0
lines.append([x1, y1, x2, y2])
x += step
return lines
# GUI
Win = Tk()
Win.title('Plot')
width = 500
height = 500
Frame = Canvas(Win, width=width, height=height, bg='white')
Frame.pack()
x0 = width / 2.
y0 = height / 2.
# coordonnées du centre de la fenêtre
Frame.create_line(- width, y0, width, y0) # axe x
Frame.create_line(x0, - height, x0, height) # axe y
lines = trace(tan, 0, 2 * pi, .001, 20, (x0, y0)) # paramètres du tracé
for line in lines:
x1, y1, x2, y2 = line
Frame.create_line(x1, y1, x2, y2, fill='blue')
# trace y = tan x |
Partager