Advertisement
Guest User

Untitled

a guest
Apr 8th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. import canvas
  2. import time
  3. from random import randint
  4.  
  5. circles = []
  6. for i in range(5):
  7.     new_dict = {"x" : randint(20,330),
  8.     "y" : randint(20,330),
  9.     "dx" : randint (5,-5),
  10.     "dy" : randint(5,-5)}
  11.     circles.append(new_dict)
  12.     while True:
  13.         canvas.clear()
  14.         for g in circles:
  15.             new_dict["x"] = new_dict["x"] + new_dict["dx"]
  16.             new_dict["y"] = new_dict["y"] + new_dict["dy"]
  17.             if new_dict["x"] > 330 or new_dict["x"] < 20:
  18.                 new_dict["dx"] = -new_dict["dx"]
  19.             elif new_dict["y"] > 330 or new_dict["y"] < 20:
  20.              new_dict["dy"] = -new_dict["dy"]
  21.         else:
  22.             pass
  23.         canvas.circle(new_dict["x"], new_dict["y"], 20)
  24.         canvas.draw()
  25.         time.sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement