Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/petri_dish/file/9fa0119fa63c/Bacteria.py
Дата изменения: Unknown
Дата индексирования: Sun Feb 3 14:12:31 2013
Кодировка:
petri_dish: 9fa0119fa63c Bacteria.py

petri_dish

view Bacteria.py @ 18:9fa0119fa63c

Added reasonable binding for mousewheel to Scroll widget
author Daniil Alexeyevsky <me.dendik@gmail.com>
date Wed, 15 Dec 2010 16:21:26 +0300
parents 4163852eb85b
children
line source
1 from random import *
2 from math import *
4 class Bacteria (object):
5 def __init__ (self, position, velocity, lifetime, mutated):
6 self.position=position
7 self.velocity=velocity
8 self.lifetime=lifetime
9 self.mutated=mutated
11 def check_collision (self, bacteria, delta, bact_r):
12 for bact in bacteria:
13 if 0<abs(self.position-bact.position)<delta+2*bact_r:
14 return bact
15 return false
17 def move (self, delta_t, radius, delta, bact_r):
18 if abs(self.position)<radius-(bact_r+delta):
19 self.velocity=self.velocity.angleToCoord(-(pi/2-self.velocity.angle()))
20 self.position=self.position*delta_t
22 def collision (self, other, delta_t, radius, delta, bact_r):
23 self.velocity, other.velocity = other.velocity, self.velocity
24 self.move (delta_t, radius, delta, bact_r)
26 def reprod (type, env, p_max):
27 if type=='s':
28 p=1-p_max*(env/100)
29 else:
30 p=p_max*(env/100)
31 return randrange(0, int(1/p))==0
33 def asexual (self, bacteria, delta_t, radius, delta, bact_r, full_lifetime):
34 if self.find_place_a(bacteria, delta, bact_r):
35 bacteria.append(Bacteria(self.position+Vector(-(bact_r+0.75*delta),0),
36 self.rnd_velocity(), full_lifetime, self.if_mutated()))
38 def sexual (self, other, bacteria, delta_t, radius, delta, bact_r, full_lifetime):
39 pass
41 def find_place_a (self, bacteria, delta, bact_r): #searches for place for children
42 for bact in bacteria:
43 if 0<abs(bact.position-self.position)<(bact_r*3+delta*2):
44 return false
45 return true
48 def find_place_s (self, other, bacteria, delta, bact_r):
49 for bact in bacteria:
50 if bact_r<abs(bact.position-(self.position+other.position)*(1/2))<((sqrt(2)+1)*bact_r*2+delta*2):
51 return false
52 return true
55 def rnd_velocity(self):
56 pass
58 def if_mutated_a(self):
59 pass
61 def if_mutated__s(self,other):
62 pass