Advertisement
here2share

# Tk_1D_Step_Waves.py

Sep 9th, 2022
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.66 KB | None | 0 0
  1. # Tk_1D_Step_Waves.py
  2.  
  3. '''
  4. create step 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. canvas = Canvas(root,width=ww,height=hh,bg='black')
  17. canvas.grid(row=0,column=0,sticky=N+S+E+W)
  18. 0
  19. def oRGB(rgb):
  20.     r,g,b = rgb
  21.     return "#%02x%02x%02x" % (r,g,b)
  22.  
  23. def plot(x):
  24.     canvas.create_line((x, 0, x, y), fill=color)
  25. 0
  26. def init():
  27.     global y
  28.     canvas.delete('all')
  29.     for x1 in range(0,ww,10):
  30.         target = max(20,min(hh-20,y+random.randint(-10,10)))
  31.         for x2 in range(0,10):
  32.             y = target
  33.             plot(x1+x2+2)
  34.     canvas.update()
  35.  
  36. rgb = 255,255,0 # yellow
  37. color = oRGB(rgb)
  38.  
  39. y = hh/2
  40.  
  41. init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement