Advertisement
here2share

# Tk_wave_qref.py

Oct 29th, 2021
1,373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.31 KB | None | 0 0
  1. # Tk_wave_qref.py
  2.  
  3. from Tkinter import *
  4. import math
  5. import time
  6.  
  7. tx =  time.time
  8. ww = 1400
  9. hh = 510
  10.  
  11. root = Tk()
  12. root.title("Simple Wave Plotting")
  13. root.geometry("%dx%d+-6+-2"%(ww,hh))
  14. cv = Canvas(width=ww, height=hh, bg='white')
  15. cv.pack()
  16.  
  17. def draw():
  18.     xy = [(x,y) for x,y in enumerate(Ys)]
  19.     cv.create_line(xy, fill='red')
  20.     cv.update()
  21.  
  22. x = 0
  23. Ys = [-99999,-99999,-99999]
  24. ydict = {}
  25.  
  26. for radius in range(3,hh/4,2):
  27.     for r in range(radius,radius*4,4):
  28.         t = ydict
  29.         tYs = Ys[:]
  30.         for angle in range(0,radius*4):
  31.                 at = hh-r-2
  32.                 theta = math.pi*angle/radius/2
  33.                 y = int(math.cos(theta)*r+at)
  34.                 if y < 1:
  35.                     t = ydict
  36.                     tYs = Ys[:]
  37.                     break
  38.                 tYs.append(y)
  39.                 try:
  40.                     t[(tYs[-3],tYs[-2])].add(tYs[-1])
  41.                     t[(hh-tYs[-3],hh-tYs[-2])].add(hh-tYs[-1])
  42.                 except:
  43.                     t[(tYs[-3],tYs[-2])] = set([tYs[-1]])
  44.                     t[(hh-tYs[-3],hh-tYs[-2])] = set([hh-tYs[-1]])
  45.                 x += 1
  46.         ydict = t
  47.         Ys = tYs[:]
  48.  
  49.         cv.delete('all')
  50.         Ys = Ys[-ww:]
  51.         draw()
  52.  
  53. ydict = dict([(k, tuple(ydict[k])) for k in ydict])
  54. print ydict
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement