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


Python turtle.ontimer方法代碼示例

本文整理匯總了Python中turtle.ontimer方法的典型用法代碼示例。如果您正苦於以下問題:Python turtle.ontimer方法的具體用法?Python turtle.ontimer怎麽用?Python turtle.ontimer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在turtle的用法示例。


在下文中一共展示了turtle.ontimer方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def __init__(self,N):
        # timer value in milliseconds
        self.deltaT=10
        # get window dimensions
        self.width = turtle.window_width()
        self.height=turtle.window_height()
        # creat the Spiro objects
        self.spiros=[]
        for i in range(N):
            # generate random params
            rparams=self.genRandomParams()
            # set spiro params
            spiro=Spiro(*rparams)
            self.spiros.append(spiro)
        # call timer
        turtle.ontimer(self.update,self.deltaT)



    # restart spiro drawing 
開發者ID:DeqianBai,項目名稱:Python-Project,代碼行數:22,代碼來源:spiro.py

示例2: update

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def update(self):
        # update all spiros
        nComplete=0
        for spiro in self.spiros:
            # update
            spiro.update()
            # count completed ones
            if spiro.drawingComplete:
                nComplete+=1
        # if all spiros are complete,restart
        if nComplete==len(self.spiros):
            self.restart()
        # call timer
        turtle.ontimer(self.update,self.deltaT)

    # toggle turtle on/off 
開發者ID:DeqianBai,項目名稱:Python-Project,代碼行數:18,代碼來源:spiro.py

示例3: startTick

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def startTick(second_hand, minute_hand, hour_hand, printer):
	today = datetime.datetime.today()
	second = today.second + today.microsecond * 1e-6
	minute = today.minute + second / 60.
	hour = (today.hour + minute / 60) % 12
	# 設置朝向
	second_hand.setheading(6 * second)
	minute_hand.setheading(6 * minute)
	hour_hand.setheading(12 * hour)
	turtle.tracer(False)
	printer.forward(65)
	printer.write(getWeekday(today), align='center', font=("Courier", 14, "bold"))
	printer.forward(120)
	printer.write('12', align='center', font=("Courier", 14, "bold"))
	printer.back(250)
	printer.write(getDate(today), align='center', font=("Courier", 14, "bold"))
	printer.back(145)
	printer.write('6', align='center', font=("Courier", 14, "bold"))
	printer.home()
	printer.right(92.5)
	printer.forward(200)
	printer.write('3', align='center', font=("Courier", 14, "bold"))
	printer.left(2.5)
	printer.back(400)
	printer.write('9', align='center', font=("Courier", 14, "bold"))
	printer.home()
	turtle.tracer(True)
	# 100ms調用一次
	turtle.ontimer(lambda: startTick(second_hand, minute_hand, hour_hand, printer), 100) 
開發者ID:CharlesPikachu,項目名稱:Tools,代碼行數:31,代碼來源:clock.py

示例4: play_sound

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def play_sound(self, sound_file, time = 0):
        # Windows
        if platform.system() == 'Windows':
            winsound.PlaySound(sound_file, winsound.SND_ASYNC)
        # Linux
        elif platform.system() == "Linux":
            os.system("aplay -q {}&".format(sound_file))
        # Mac
        else:
            os.system("afplay {}&".format(sound_file))

        if time > 0:
	        turtle.ontimer(lambda: self.play_sound(sound_file, time), t=int(time * 1000)) 
開發者ID:wynand1004,項目名稱:SPGL,代碼行數:15,代碼來源:spgl.py

示例5: after

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def after(self, function, milliseconds):
        turtle.ontimer(function, milliseconds) 
開發者ID:wynand1004,項目名稱:SPGL,代碼行數:4,代碼來源:spgl.py

示例6: main

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def main():
    if not exit:
            star.forward(50)
            star.right(144)
    turtle.ontimer(main,500) 
開發者ID:PacktPublishing,項目名稱:Learning-Python-by-building-games,代碼行數:7,代碼來源:ontimer-star.py

示例7: play_sound

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def play_sound(sound_file, time = 0):
    # Windows
    if platform.system() == 'Windows':
        winsound.PlaySound(sound_file, winsound.SND_ASYNC)
    # Linux
    elif platform.system() == "Linux":
        os.system("aplay -q {}&".format(sound_file))
    # Mac
    else:
        os.system("afplay {}&".format(sound_file))

    if time > 0:
        turtle.ontimer(lambda: play_sound(sound_file, time), t=int(time * 1000)) 
開發者ID:wynand1004,項目名稱:Projects,代碼行數:15,代碼來源:space_arena.py

示例8: timer

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def timer(game=game):
    os.system("clear")
    print("FPS: {}".format(game.frame))
    game.frame = 0
    turtle.ontimer(timer, 1000) 
開發者ID:wynand1004,項目名稱:Projects,代碼行數:7,代碼來源:space_arena.py

示例9: move

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def move():
    if running:
        t.forward(15)
        angle = random.randint(-9, 9) * 10 
        t.left(angle)
        t.ontimer(move, 25) # 25ms 
開發者ID:furas,項目名稱:python-examples,代碼行數:8,代碼來源:example-1.py

示例10: move_t1

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def move_t1():
    # first turtle moves a little
    t1.left(10)  
    t1.forward(10)
    
    # repeat it after 100ms
    turtle.ontimer(move_t1, 100) 
開發者ID:furas,項目名稱:python-examples,代碼行數:9,代碼來源:main-2.py

示例11: move_t2

# 需要導入模塊: import turtle [as 別名]
# 或者: from turtle import ontimer [as 別名]
def move_t2():
    # second turtle moves a little
    t2.right(10)  
    t2.forward(10)
    
    # repeat it after 100ms
    turtle.ontimer(move_t2, 100)

# --- main ---

# create two turtles 
開發者ID:furas,項目名稱:python-examples,代碼行數:13,代碼來源:main-2.py


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