Advertisement
nicx321

math graph

Aug 2nd, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. #!/usr/bin/python
  2. from tkinter import *
  3. from math import *
  4.  
  5. resy=480
  6. resx=int((resy/9)*16)
  7.  
  8. window = Tk()
  9. canvas = Canvas(window, width=resx, height=resy, bg="#000000")
  10. canvas.pack()
  11. img = PhotoImage(width=resx, height=resy)
  12. item = canvas.create_image((int((resx/2)), int((resy/2))), image=img, state="normal")
  13.  
  14. txt = "cos(radians(x))*100"
  15. def strt():
  16.     global resx
  17.     global img
  18.     global canvas
  19.    
  20.     x=resx
  21.     while x>=0:
  22.         img.put("#9A1409", (x,int((resy/2))))
  23.         x=x-1
  24.  
  25.     x=resx
  26.     while x>=0:
  27.         img.put("#9A1409", (int((resx/2)),x))
  28.         x=x-1
  29.  
  30. w1 = Scale(window, from_=-int(resx/2), to=int(resx/2),orient=HORIZONTAL,resolution=0.5, length=resx+25)
  31. w1.pack()
  32.  
  33. var=StringVar()
  34. var.set(txt)
  35. R=Label(window, textvariable=var, height=1, width=50)
  36. R.pack()
  37.  
  38. def callback():
  39.     global txt
  40.     global x
  41.     global canvas
  42.     global item
  43.     global img
  44.     global item
  45.    
  46.     canvas.delete(item)
  47.     img = PhotoImage(width=resx, height=resy)
  48.     item = canvas.create_image((int((resx/2)), int((resy/2))), image=img, state="normal")
  49.  
  50.     strt()
  51.     x=-int((resx/2))
  52.     txt = e.get()
  53.  
  54. x=-int((resx/2))
  55.  
  56. def text(txt):
  57.     global var
  58.     x = w1.get()
  59.     exec("var.set("+txt+")")
  60.  
  61. def update():
  62.     global x
  63.     global var
  64.     global txt
  65.     global img
  66.    
  67.     if x>=-int((resx/2)) and x<=int((resx/2)):
  68.         y=eval(str(txt))
  69.         z=int(y)
  70.         if y < int((resy/2)) and y > -int((resy/2)):
  71.             img.put("#00ff00", (int(x)+int((resx/2)),int((resy/2))-(z)))
  72.  
  73.     if x<int(resx/2):
  74.         x=x+0.1
  75.        
  76.     text(txt)
  77.  
  78.     window.after(1,update)
  79.  
  80. e = Entry(window)
  81. e.pack()
  82.  
  83. b = Button(window, text = "OK", width = 10, command = callback)
  84. b.pack()
  85. strt()
  86. window.after(1,update)
  87. window.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement