-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParticle.py
More file actions
74 lines (60 loc) · 2.26 KB
/
Particle.py
File metadata and controls
74 lines (60 loc) · 2.26 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import math
import numpy as np
from params import WIDTH, HEIGHT, OBSTACLE_REJECTION
TYPE_PARTICLE = 0
TYPE_BOID = 1
TYPE_GOAL = 2
TYPE_OBSTACLE = 3
def distance(point1, point2):
"Distance between 2 points"
return math.sqrt(np.sum((point1 - point2) ** 2))
class Particle:
"General class to describe a Particle of the map"
rejection_radius = (0, 1)
confort_radius = (0, 0)
attraction_radius = (0, 0)
def __init__(self, identity, pos=np.zeros(2), speed=np.zeros(2), acc=np.zeros(2), size=6, color=np.zeros(3)):
self.identity = identity
self.type = TYPE_PARTICLE
self.pos = pos
self.speed = speed
self.acc = acc
self.size = size
self.color = color
self.vectors = np.zeros(4)
def update(self):
"Upate function required for all types of elements"
pass
def get_key(self):
"Unique identifier for element"
return str(self.type) + ' ' + str(self.identity)
def distance(self, element):
"Distance from self to element"
return distance(element.pos, self.pos)
#enabled this piece of code to make the map like a tore
if diff[0] > WIDTH / 2:
diff[0] = WIDTH - element.pos[0] - self.pos[0]
if diff[1] > HEIGHT / 2:
diff[1] = HEIGHT - element.pos[1] - self.pos[1]
def get_pos(self):
"Return position as int32"
return self.pos.astype('int32')
@staticmethod
def gen_key(elem_type, elem_id):
"Generate key of a certain type and id"
return str(elem_type) + ' ' + str(elem_id)
def reaction(self, herd):
"Compute the reaction of the particule to it's surrounding"
pass
class Goal(Particle):
"Symbolize the point some particle must go to"
def __init__(self, identity, pos=np.zeros(2), size=12, color=None):
Particle.__init__(self, identity, pos, size=size)
self.color = color or np.random.randint(255,size=3)
self.type = TYPE_GOAL
class Obstacle(Particle):
"Symbolize obstacle on the map"
rejection_radius = (0, OBSTACLE_REJECTION)
def __init__(self, identity, pos=np.zeros(2), size=10, color=np.array((0, 0, 0))):
Particle.__init__(self, identity, pos, size=size, color=color)
self.type = TYPE_OBSTACLE