-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBall.py
More file actions
17 lines (14 loc) · 674 Bytes
/
Ball.py
File metadata and controls
17 lines (14 loc) · 674 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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)
# print(coordinates)
if(coordinates[2]>=(self.canvas.winfo_width()) or coordinates[0]<0):
self.xVelocity = -self.xVelocity
elif(coordinates[3]>=(self.canvas.winfo_height()) or coordinates[1]<0):
self.yVelocity = -self.yVelocity
self.canvas.move(self.image,self.xVelocity,self.yVelocity)