Advertisement
here2share

# Tk_1D_Curvy_Waves.py

Oct 22nd, 2022
772
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.87 KB | None | 0 0
  1. # Tk_1D_Curvy_Waves.py
  2.  
  3. '''
  4. create curvy waves
  5. '''
  6.  
  7. from tkinter import *
  8. import PIL
  9. import math
  10. import random
  11.  
  12. ww = 1400
  13. hh = 600
  14.  
  15. root=Tk()
  16. root.geometry("%dx%d+-10+0"%(ww,hh))
  17. canvas = Canvas(root,width=ww,height=hh,bg='black')
  18. canvas.grid(row=0,column=0,sticky=N+S+E+W)
  19.  
  20. def oRGB(rgb):
  21.     r,g,b = rgb
  22.     return "#%02x%02x%02x" % (r,g,b)
  23.  
  24. def plot():
  25.     canvas.create_line((x, 0, x, y), fill=color)
  26.  
  27. rgb = 255,255,0 # yellow
  28. color = oRGB(rgb)
  29. y = hh/2
  30. amp = 10
  31. vel = 0.0 # velocity
  32. smoothness = 100.0
  33.  
  34. def init():
  35.     global x, y, vel
  36.     canvas.delete('all')
  37.     ttt = []
  38.     x = 0
  39.     while x < ww:
  40.         aim = max(amp*2,min(hh-amp*2,y+random.randint(-amp,amp)))
  41.         ttt += [aim]
  42.         for x2 in range(0,10):
  43.             vel += (aim-y)/smoothness
  44.             y += vel
  45.             plot()
  46.            
  47.             x += 1
  48.             if x > ww:
  49.                 break
  50.                
  51.     root.after(1000,init)
  52.  
  53. init()
  54. root.mainloop()
  55.  
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement