本文整理汇总了Python中cell.Cell.position方法的典型用法代码示例。如果您正苦于以下问题:Python Cell.position方法的具体用法?Python Cell.position怎么用?Python Cell.position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cell.Cell
的用法示例。
在下文中一共展示了Cell.position方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: next
# 需要导入模块: from cell import Cell [as 别名]
# 或者: from cell.Cell import position [as 别名]
def next(self, speed=1):
#print (len(self.cells))
#print self.themap.grid
# Cells older than AGE reproduce
for cell in self.cells:
#print ('next cell')
if cell.age >= self.AGE:
#print ('next mature cell')
if cell.health >= 50:
#print ("Mitosis time!")
# Add two tangent daughter cells
newCell = Cell(cell.position, cell.dna.mutate())
theta = uniform(0, 200 * math.pi)
newCell.position = (cell.position[0] + cell.radius * 2 * math.cos(theta / 100), \
cell.position[1] + cell.radius * 2 * math.sin(theta / 100))
self.cells.append(newCell)
# Second daughter, in same place as current
self.cells.append(Cell(cell.position, cell.dna.mutate()))
# Kill current cell
cell.health = 0
else:
cell.health = 0
else:
break
for z in self.cells:
z.age += speed
z.health *= self.themap.select(z.position[0],z.position[1])
if (z.health > 100):
z.health = 100
elif (z.health < 0):
z.health = 0
self.themap.consume(z.position[0],z.position[1])
# Toxin damage
for disc in self.discs:
for cell in self.cells:
if disc.type:
if cell.dna.wall_type != disc.type:
damage = 50 - self.distance_squared(cell.position, disc.position)**2/2560000
if damage > 0:
cell.health -= damage
if cell.health < 0:
cell.health = 0
else:
damage = 50 - self.distance_squared(cell.position, disc.position)**2/2560000
if damage > 0:
cell.health -= damage
if cell.health < 0:
cell.health = 0
#try:
# self.themap.pollute(z.position[0],z.position[1],z.dna.toxin_type,z.dna.toxin_strength)
# toxin = 0
#
# for toxin_strength in self.themap.select(z.position[0],z.position[1]):
# if (toxin > 1):
# if not (((z.dna.wall_type) == (toxin)) or ((z.dna.toxin_type) == (toxin))):
# z.health -= (toxin_strength - z.dna.wall_width)*5
# toxin = toxin + 1
#except IndexError:
# pass
# Remove dead cells
for y in range(len(self.cells)):
try:
if (self.cells[y].health <= 0):
self.cells.pop(y)
elif (self.cells[y].position[0] < 0):
self.cells.pop(y)
elif (self.cells[y].position[1] < 0):
self.cells.pop(y)
elif (self.cells[y].position[0] > self.dimensions[0]):
self.cells.pop(y)
elif (self.cells[y].position[1] > self.dimensions[1]):
self.cells.pop(y)
except IndexError:
pass
self.themap.regrow()
self.time += 1