Advertisement
here2share

# Tk_follow_slowdown.py

Nov 15th, 2022
912
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. # Tk_follow_slowdown.py
  2.  
  3. from tkinter import *
  4. from math import sin
  5. import random
  6.  
  7. ww = 400
  8. hh = 400
  9.  
  10. root=Tk()
  11. root.geometry("%dx%d+-10+0"%(ww,hh))
  12. canvas = Canvas(root,width=ww,height=hh,bg='yellow')
  13. canvas.grid(row=0,column=0,sticky=N+S+E+W)
  14. root.update()
  15.  
  16. def rgb2hex(r,g,b):
  17.     return '#%02X%02X%02X'%(r,g,b)
  18.  
  19. def circle(x, y, r=25):
  20.     canvas.create_oval((x-r, y-r, x+r, y+r), fill=color, tags=('dot'), width=0)
  21.    
  22. X = ww/2
  23. Y = hh/2
  24. xm = X
  25. ym = Y
  26.  
  27. delay = 1000
  28. r = 30
  29.  
  30. def mouse_move(event):
  31.     global xm, ym
  32.     xm, ym = event.x, event.y
  33.  
  34. root.bind('<Motion>', mouse_move)
  35.  
  36. i = 0
  37.  
  38. while 1:
  39.     canvas.delete('dot')
  40.     X += (xm-X)/delay
  41.     Y += (ym-Y)/delay
  42.     color = rgb2hex(0,121,184)
  43.     circle(X, Y, r+sin(i)*5)
  44.     color = 'white'
  45.     circle(X, Y, 15+sin(i-1)*7)
  46.     i += 0.01
  47.     root.update()
  48.  
  49. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement