rev |
line source |
ksenia_yashina@20
|
1 import random |
ksenia_yashina@20
|
2 from math import * |
ksenia_yashina@20
|
3 import vector |
ksenia_yashina@20
|
4 |
ksenia_yashina@20
|
5 class Bacteria (object): |
ksenia_yashina@20
|
6 def __init__(self, position, velocity, lifetime, mutated): |
ksenia_yashina@20
|
7 self.position = position |
ksenia_yashina@20
|
8 self.velocity = velocity |
ksenia_yashina@20
|
9 self.lifetime = lifetime |
ksenia_yashina@20
|
10 self.mutated = mutated |
ksenia_yashina@20
|
11 |
ksenia_yashina@20
|
12 def __eq__(self,other): |
ksenia_yashina@20
|
13 if self.position==other.position and\ |
ksenia_yashina@20
|
14 self.velocity==other.velocity and\ |
ksenia_yashina@20
|
15 self.lifetime==other.lifetime and\ |
ksenia_yashina@20
|
16 self.mutated==other.mutated: |
ksenia_yashina@20
|
17 return True |
ksenia_yashina@20
|
18 return False |
ksenia_yashina@20
|
19 |
ksenia_yashina@20
|
20 def __ne__(self,other): |
ksenia_yashina@20
|
21 return not(self==other) |
ksenia_yashina@20
|
22 |
ksenia_yashina@20
|
23 def check_collision(self, bacteria, delta, bact_r,delta_t): |
ksenia_yashina@20
|
24 for bact in bacteria: |
ksenia_yashina@20
|
25 if 0 < abs(self.position - bact.position) < delta + 2*bact_r: |
ksenia_yashina@20
|
26 return bact |
ksenia_yashina@20
|
27 return False |
ksenia_yashina@20
|
28 |
ksenia_yashina@21
|
29 def check_dish_wall(self,position,radius,delta,bact_r): |
ksenia_yashina@21
|
30 if abs(position) > radius - (bact_r + delta): |
ksenia_yashina@21
|
31 return True |
ksenia_yashina@21
|
32 return False |
ksenia_yashina@21
|
33 |
ksenia_yashina@20
|
34 def move(self, bacteria, delta_t, radius, delta, bact_r): |
ksenia_yashina@21
|
35 if self.check_dish_wall(self.position,radius,delta,bact_r): |
ksenia_yashina@20
|
36 self.velocity = self.velocity.angleToCoord(-(pi/2 - |
ksenia_yashina@20
|
37 self.velocity.angle())) |
ksenia_yashina@20
|
38 self.position += self.velocity*delta_t |
ksenia_yashina@20
|
39 |
ksenia_yashina@20
|
40 def collision(self, other, bacteria, delta_t, radius, delta, bact_r): |
ksenia_yashina@20
|
41 self.velocity, other.velocity = other.velocity, self.velocity |
ksenia_yashina@20
|
42 self.move(bacteria, delta_t, radius, delta, bact_r) |
ksenia_yashina@20
|
43 other.move(bacteria, delta_t, radius, delta, bact_r) |
ksenia_yashina@20
|
44 |
ksenia_yashina@20
|
45 def reprod(self, type, env, p_max): |
ksenia_yashina@20
|
46 if type == 's': |
ksenia_yashina@20
|
47 prob = 1 - p_max*(env/100) |
ksenia_yashina@20
|
48 else: |
ksenia_yashina@20
|
49 prob = 0.001 |
ksenia_yashina@20
|
50 return random.random() < prob |
ksenia_yashina@20
|
51 |
ksenia_yashina@20
|
52 def asexual(self, bacteria, delta_t, radius, delta, bact_r, full_lifetime): |
ksenia_yashina@21
|
53 if self.find_place_a(bacteria, delta, bact_r)\ |
ksenia_yashina@21
|
54 and not(self.check_dish_wall(self.position,radius,delta,2*bact_r)): |
ksenia_yashina@20
|
55 pos1=self.position + vector.Vector(-(bact_r + 0.75*delta),0) |
ksenia_yashina@20
|
56 vel1=vector.Vector(1,0).angleToCoord(self.velocity.angle()) |
ksenia_yashina@20
|
57 bacteria.append(Bacteria(pos1, self.rnd_velocity(pi), |
ksenia_yashina@20
|
58 full_lifetime, self.if_mutated_a())) |
ksenia_yashina@20
|
59 pos2=self.position + vector.Vector((bact_r + 0.75*delta),0) |
ksenia_yashina@20
|
60 bacteria.append(Bacteria(pos2, self.rnd_velocity(0), |
ksenia_yashina@20
|
61 full_lifetime, self.if_mutated_a())) |
ksenia_yashina@20
|
62 bacteria.remove |