本文整理汇总了Python中navigation.Navigation.turn方法的典型用法代码示例。如果您正苦于以下问题:Python Navigation.turn方法的具体用法?Python Navigation.turn怎么用?Python Navigation.turn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类navigation.Navigation
的用法示例。
在下文中一共展示了Navigation.turn方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Whale
# 需要导入模块: from navigation import Navigation [as 别名]
# 或者: from navigation.Navigation import turn [as 别名]
class Whale(MovableSeaObject):
# f = 12 Hz - @2-5 kHz for “whale songs”, SL up to 188 dB
# Swimming: 10 - 20 Hz, 60 to 80 DB
# Sing: 2Khz - 5 Khz, 120 to 190 DB (AI should handle this later)
def __init__(self, sea):
MovableSeaObject.__init__(self, sea, 15)
self.nav = Navigation(self)
self.sea = sea
self.nav.destination = None
self.bands_swim = Bands().add_random([10, 20], [60, 80])
self.bands_swim_sing = self.bands_swim.add_random([2000, 5000], [120, 150], times=3)
self.deep = random.randint(10, 20)
print ("Swim: " + str(self.bands_swim))
print ("Sing: " + str(self.bands_swim_sing))
self.singing = False
self.counter = (random.randint(5, 10) + random.gauss(6, 5)) / 60
# The blue whale is a marine mammal belonging to the suborder of
# baleen whales (called Mysticeti). At up to 32.9 metres (108 ft)
# in length and 172 metric tons (190 short tons) or more in weight,
# it is the largest animal ever to have existed.
#
# Blue whales can reach speeds of 50 kilometres per hour (31 mph)
# over short bursts, usually when interacting with other whales, but 20
# kilometres per hour (12 mph) is a more typical traveling speed. When feeding,
# they slow down to 5 kilometres per hour (3.1 mph).
def turn(self, time_elapsed):
MovableSeaObject.turn(self, time_elapsed)
self.nav.turn(time_elapsed)
self.counter -= time_elapsed
if self.counter <= 0:
if self.singing:
self.singing = False
self.counter = (random.randint(10, 5) + random.gauss(5, 5)) / 60
else:
self.singing = True
self.counter = (random.gauss(10, 3) + 5) / 60
if self.nav.destination is None:
self.nav.destination = Point(random.randint(0, 10), random.randint(0, 10))
self.nav.speed = (random.random() * 10) + 3
def get_deep(self):
return self.deep
def get_pos(self):
return self.pos
def get_bands(self):
if self.singing:
return self.bands_swim_sing
else:
return self.bands_swim
def __str__(self):
return "Whale {is_singing}, {pos}, swim:{swim}, sing:{sing}, counter:{counter}, dest:{dest}".format(
is_singing = self.singing,
pos=MovableSeaObject.__str__(self),
swim=str(self.bands_swim),
sing=str(self.bands_swim_sing),
counter=self.counter,
dest=self.nav.destination)