Advertisement
here2share

# Tk_1D_Curvy_Waves.py

Sep 9th, 2022 (edited)
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.01 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. red = oRGB((255,0,0))
  30. y = hh/2
  31. steps = 20
  32. vel = 0.0 # velocity
  33.  
  34. def targets(ttt): # display last
  35.     for x1,aim in enumerate(ttt):
  36.         x1 = x1 * steps
  37.         canvas.create_line((x1+steps*0.5, aim, x1+steps*1.5, aim), fill=red)
  38.  
  39. def init():
  40.     global x, y, vel
  41.     canvas.delete('all')
  42.     ttt = []
  43.     for x1 in range(0,ww,steps):
  44.         aim = max(20,min(hh-20,y+random.randint(-20,20)))
  45.         ttt += [aim]
  46.         for x2 in range(0,steps):
  47.             x = x1+x2
  48.             vel += (aim-y)/120.0
  49.             y += vel
  50.             plot(x)
  51.     # targets(ttt)
  52.     root.after(1000,init)
  53.  
  54. init()
  55. root.mainloop()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement