Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import canvas
- import time
- from random import randint
- circles = []
- for i in range(5):
- new_dict = {"x" : randint(20,330),
- "y" : randint(20,330),
- "dx" : randint (5,-5),
- "dy" : randint(5,-5)}
- circles.append(new_dict)
- while True:
- canvas.clear()
- for g in circles:
- new_dict["x"] = new_dict["x"] + new_dict["dx"]
- new_dict["y"] = new_dict["y"] + new_dict["dy"]
- if new_dict["x"] > 330 or new_dict["x"] < 20:
- new_dict["dx"] = -new_dict["dx"]
- elif new_dict["y"] > 330 or new_dict["y"] < 20:
- new_dict["dy"] = -new_dict["dy"]
- else:
- pass
- canvas.circle(new_dict["x"], new_dict["y"], 20)
- canvas.draw()
- time.sleep(0.01)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement