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
| from Tkinter import *
from math import *
T = Tk() # set up master widget
T.title('sinus 0.0')
W = 300 # width
H = 300 # height
F = Canvas(T, width=W, height=H, bg='light yellow')
F.pack()
def scale(val) : return round(val * H/3, 2)
def pixel(F, x, y, c) : # widget, abs, ord, color
F.create_rectangle(x, y, x, y, fill=c, outline=c)
X = W / 6
Y = H / 2
F.create_line(X/2,Y, W-X, Y)
F.create_line(X, X, X, H - 20)
F.create_text(X/2 + 10, Y - 10, text='0')
for angle in xrange(0, int(radians(360) * 100), 5) :
x = angle / 100.
y = Y + scale(sin(x))
x *= 20
x += X
pixel(F, x, y, 'red')
T.mainloop() |
Partager