Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Tk_follow_slowdown.py
- from tkinter import *
- from math import sin
- import random
- ww = 400
- hh = 400
- root=Tk()
- root.geometry("%dx%d+-10+0"%(ww,hh))
- canvas = Canvas(root,width=ww,height=hh,bg='yellow')
- canvas.grid(row=0,column=0,sticky=N+S+E+W)
- root.update()
- def rgb2hex(r,g,b):
- return '#%02X%02X%02X'%(r,g,b)
- def circle(x, y, r=25):
- canvas.create_oval((x-r, y-r, x+r, y+r), fill=color, tags=('dot'), width=0)
- X = ww/2
- Y = hh/2
- xm = X
- ym = Y
- delay = 1000
- r = 30
- def mouse_move(event):
- global xm, ym
- xm, ym = event.x, event.y
- root.bind('<Motion>', mouse_move)
- i = 0
- while 1:
- canvas.delete('dot')
- X += (xm-X)/delay
- Y += (ym-Y)/delay
- color = rgb2hex(0,121,184)
- circle(X, Y, r+sin(i)*5)
- color = 'white'
- circle(X, Y, 15+sin(i-1)*7)
- i += 0.01
- root.update()
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement