Advertisement
yukcheong

Animation

Feb 18th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | None | 0 0
  1. import Tkinter
  2. import time
  3. from random import *
  4.  
  5. aimyon = Tkinter.Tk()
  6. rock = Tkinter.Canvas(aimyon ,width = 500, height = 500)
  7. rock.pack()
  8.  
  9. x = 0
  10. y = 0
  11.  
  12. bobo = rock.create_oval(225, 225, 275, 275 , fill='pink')
  13.  
  14. xspeed = randint(1 ,5)
  15. yspeed = randint(1, 5)
  16.  
  17. while True:
  18.     rock.move(bobo, xspeed, yspeed)
  19.     rock.update()
  20.     time.sleep(0.01)
  21.     if rock.coords(bobo)[0] < 1 :
  22.         xspeed = randint(1, 5)
  23.     if rock.coords(bobo)[2] > 499 :
  24.         xspeed = -randint(1, 5)
  25.     if rock.coords(bobo)[1] < 1 :
  26.         yspeed = randint(1, 5)
  27.     if  rock.coords(bobo)[3] > 499 :
  28.         yspeed = -randint(1, 5)
  29.  
  30. aimyon.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement