Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from math import *
- from tkinter import *
- def f(x):
- if x >= 0 and x < 0.1:
- x = 0.1
- if x <= 0 and x >= -0.1:
- x = -0.1
- return(2*x+2)
- root=Tk()
- root.geometry("1200x1200")
- W = 1000
- H = 1000
- canvas=Canvas(root, width=W, height=H,bg="grey")
- canvas.create_line(W/2, 0, W/2, H, width=0.5)
- canvas.create_line(0, H/2, W, H/2, width=0.5)
- minx = -10
- maxx = 10
- funcy = [0] * W
- for i in range(W):
- x = minx + (maxx - minx) / W * i
- funcy[i] = f(x)
- maxy = max(funcy)
- for i in range(W - 1):
- y1 = funcy[i] / maxy * H / 10
- y2 = funcy[i + 1] / maxy * H / 10
- if abs(y1 - y2) < 150:
- #canvas.create_line(i,H/2 - y1,i + 1, H/2 - y2,fill="red", width=1)
- canvas.create_oval(i,H/2-y1,i+5,H/2-y2)
- canvas.pack()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement