Advertisement
here2share

# Tk_wave_fn.py

Nov 5th, 2020 (edited)
2,089
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.84 KB | None | 0 0
  1. # Tk_wave_fn.py
  2.  
  3. from tkinter import *
  4. from PIL import Image, ImageTk
  5. import random
  6. import math
  7. import time
  8.  
  9. root = Tk()
  10. root.title("Wave Algorithm")
  11. wt = 1400
  12. ht = 100
  13. root.geometry("%dx%d+-10+0"%(wt,ht))
  14. canvas = Canvas(root, width=wt, height=ht)
  15. canvas.pack()
  16.  
  17. def fn_wave():
  18.     z = [zzz[(x//dist)*dist] for dist in [8,64,128,256]]
  19.     z = (y*70+sum(z))/74
  20.     return z
  21.  
  22. img = Image.new('RGB', (wt,ht))
  23. zz = {}
  24. XYo = []
  25. c = 0
  26. for y in range(ht):
  27.     for x in range(wt):
  28.         zz[x,y] = c
  29.         XYo.append((255,255,255))
  30.         c += 1
  31. 0
  32. yy = 50
  33. y = 0.0
  34. while 1:
  35.     xy = XYo[:]
  36.     zzz = [random.randint(-50,50) for z in range(wt)]
  37.     for x in range(wt):
  38.         y = fn_wave()
  39.         xy[zz[x,int(y+yy)]] = (0,0,255)
  40.     img.putdata(tuple(xy))
  41.     imgTk = ImageTk.PhotoImage(img)
  42.     canvas.create_image(0, 0, anchor=NW, image=imgTk)
  43.     canvas.update()
  44.     time.sleep(0.5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement