-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblob.py
34 lines (23 loc) · 1.1 KB
/
blob.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import random
class Blob:
def __init__(self,color,x_boundary, y_buondary,size_range=(4,8),movement_range=(-1,2)):
self.size = random.randrange(size_range[0],size_range[1])
self.color = color
self.x_boundary = x_boundary
self.y_buondary = y_buondary
self.x = random.randrange(0, self.x_boundary )
self.y = random.randrange(0, self.y_buondary)
self.movement_range = movement_range
def __repr__(self):
return 'Blob({},{},({},{}))'.format(self.color,
self.size,self.x,self.y)
def move(self):
self.move_x = random.randrange(self.movement_range[0],self.movement_range[1])
self.move_y = random.randrange(self.movement_range[0],self.movement_range[1])
self.x += self.move_x
self.y += self.move_y
def check_bounds(self):
if self.x <0: self.x = 0
elif self.x > self.x_boundary : self.x = self.x_boundary
if self.y<0: self.y= 0
elif self.y > self.y_buondary: self.y = self.y_buondary