Advertisement
here2share

# Tk_1D_Walk.py

Sep 9th, 2022
937
1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 1 0
  1. # Tk_1D_Walk.py
  2.  
  3. from PIL import Image, ImageTk, ImageDraw
  4. from tkinter import *
  5. import PIL
  6. import math
  7. import random
  8.  
  9. ww = 1400
  10. hh = 600
  11.  
  12. yy = hh/2
  13. root=Tk()
  14. root.title("Tk_1D_Walk")
  15. root.geometry("%dx%d+0+0"%(ww,hh))
  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():
  24.     color = oRGB(rgb)
  25.     x = xx+2
  26.     canvas.create_line((x, 0, x, yy), fill=color)
  27. 0
  28. while 1:
  29.     canvas.delete('all')
  30.     for xx in range(0,ww):
  31.         rgb = 255,255,0 # yellow
  32.         yy = max(20,min(hh-20,yy+random.choice([-2,-1,0,1,2])))
  33.         plot()
  34.     canvas.update()
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement