Advertisement
here2share

# Tk_duo_wave.py

May 7th, 2020
1,913
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.16 KB | None | 0 0
  1. # Tk_duo_wave.py
  2.  
  3. from PIL import Image, ImageTk, ImageDraw
  4. from Tkinter import *
  5. import PIL
  6. import math
  7.  
  8. ww = 1000
  9. hh = 400
  10. waves = {}
  11. ppp = list('ab')
  12. for i in (97,120):
  13.     incr = (360.0/i)
  14.     xy = {}
  15.     p = ppp.pop()
  16.     waves[p] = []
  17.     z = 0
  18.     while z < 360:
  19.         s = math.cos(math.radians(z))*(hh/2-20)+(hh/2)
  20.         xy[len(xy)] = min(600,int(s))
  21.         z += incr
  22.     t = [xy[z] for z in range(len(xy))]
  23.     waves[p].extend(t)
  24. 0
  25. a,b = waves
  26. a2 = len(waves[a])
  27. b2 = len(waves[b])
  28.  
  29. c = 0
  30. root=Tk()
  31. canvas = Canvas(root,width=ww,height=hh,bg='black')
  32. canvas.grid(row=0,column=0,sticky=N+S+E+W)
  33.  
  34. def high():
  35.     aa = waves[a][c%a2]
  36.     bb = waves[b][c%b2]
  37.     return (aa+bb)/2
  38. 0
  39.  
  40. wide = []
  41. while c != ww+2:
  42.     wide.append(high())
  43.     c += 1
  44.  
  45. def plot():
  46.     color = oRGB(rgb)
  47.     x = xx+2
  48.     canvas.create_line((x, 0, x, yy), fill=color)
  49. 0
  50. def oRGB(rgb):
  51.     r,g,b = rgb
  52.     return "#%02x%02x%02x" % (r,g,b)
  53. 0
  54. while 1:
  55.     canvas.delete('all')
  56.     for xx in range(0,ww):
  57.         yy = wide[xx]
  58.         rgb = 255,255,0
  59.         plot()
  60.     canvas.update()
  61.     wide.append(high())
  62.     wide.pop(0)
  63.     c += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement