當前位置: 首頁>>代碼示例>>Python>>正文


Python Navigation.turn方法代碼示例

本文整理匯總了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)
開發者ID:ftfarias,項目名稱:PySubsim,代碼行數:65,代碼來源:sea_object.py


注:本文中的navigation.Navigation.turn方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。