Advertisement
Guest User

Untitled

a guest
Nov 13th, 2019
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. from math import *
  2. from tkinter import *
  3. def f(x):
  4. if x >= 0 and x < 0.1:
  5. x = 0.1
  6. if x <= 0 and x >= -0.1:
  7. x = -0.1
  8. return(2*x+2)
  9.  
  10. root=Tk()
  11. root.geometry("1200x1200")
  12. W = 1000
  13. H = 1000
  14. canvas=Canvas(root, width=W, height=H,bg="grey")
  15. canvas.create_line(W/2, 0, W/2, H, width=0.5)
  16. canvas.create_line(0, H/2, W, H/2, width=0.5)
  17. minx = -10
  18. maxx = 10
  19.  
  20. funcy = [0] * W
  21.  
  22. for i in range(W):
  23. x = minx + (maxx - minx) / W * i
  24. funcy[i] = f(x)
  25.  
  26. maxy = max(funcy)
  27.  
  28. for i in range(W - 1):
  29. y1 = funcy[i] / maxy * H / 10
  30. y2 = funcy[i + 1] / maxy * H / 10
  31. if abs(y1 - y2) < 150:
  32. #canvas.create_line(i,H/2 - y1,i + 1, H/2 - y2,fill="red", width=1)
  33. canvas.create_oval(i,H/2-y1,i+5,H/2-y2)
  34. canvas.pack()
  35. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement