-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBall.py
More file actions
16 lines (13 loc) · 662 Bytes
/
Ball.py
File metadata and controls
16 lines (13 loc) · 662 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
class Ball:
def __init__(self, canvas, x, y, diameter, xvelocity, yvelocity, color):
self.canvas = canvas
self.image = canvas.create_oval(x, y, diameter, diameter, fill=color)
self.xvelocity = xvelocity
self.yvelocity = yvelocity
def move(self):
coordinates = self.canvas.coords(self.image)
if coordinates[2] >= (self.canvas.winfo_width()) or coordinates[0] < 0:
self.xvelocity = -self.xvelocity
if coordinates[3] >= (self.canvas.winfo_height()) or coordinates[1] < 0:
self.yvelocity = -self.yvelocity
self.canvas.move(self.image, self.xvelocity, self.yvelocity)