Advertisement
here2share

# Tk_smooth_wave_fn.py

Mar 20th, 2023
743
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. # Tk_smooth_wave_fn.py
  2.  
  3. from tkinter import *
  4. import random
  5. import math
  6. import time
  7.  
  8. root = Tk()
  9. root.title("Smooth Wave Algorithm")
  10. ww = 1400
  11. hh = 300
  12. cy = hh//2-128
  13. root.geometry("%dx%d+-10+0"%(ww,hh))
  14. canvas = Canvas(root, width=ww, height=hh)
  15. canvas.pack()
  16.  
  17. waves = {}
  18. steps = 10
  19. for i in range(256):
  20.     for j in range(256):
  21.         values = []
  22.         j2 = min(i+50, min(i-50, j))
  23.         for step in range(1,steps+1):
  24.             value = i + (j-i) * step/steps * 0.5
  25.             values.append(value)
  26.         waves[(i,j)] = values
  27.  
  28. while True:
  29.     canvas.delete('all')
  30.     data =[random.randint(0,255) for _ in range(0, ww, steps)]
  31.     L= ww // steps -1
  32.    
  33.     x=0
  34.     y0=random.randint(0 ,255)
  35.     for j in range(L):
  36.         target=max(0,min(255,y0+random.randint(-20 ,20)))
  37.         for i in range(steps):
  38.             y=waves[int(y0),int(target)][i]
  39.             canvas.create_line(x,cy+y0,x+1,cy+y ,fill='green')
  40.             y0=y
  41.             x+=1
  42.    
  43.     canvas.update()
  44.     time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement