我目前正在研究python中的精靈工作表工具,它將組織導出到一個xml文檔中,但我遇到了一些嘗試動畫預覽的問題。我不太確定如何使用python來計算幀頻。例如,假設我擁有所有適當的幀數據和繪圖功能,我將如何編碼時間以每秒30幀(或任何其他任意速率)顯示。Python動畫計時
4
A
回答
8
做到這一點最簡單的方法是用Pygame:
import pygame
pygame.init()
clock = pygame.time.Clock()
# or whatever loop you're using for the animation
while True:
# draw animation
# pause so that the animation runs at 30 fps
clock.tick(30)
做第二個最簡單的方法是手動:
import time
FPS = 30
last_time = time.time()
# whatever the loop is...
while True:
# draw animation
# pause so that the animation runs at 30 fps
new_time = time.time()
# see how many milliseconds we have to sleep for
# then divide by 1000.0 since time.sleep() uses seconds
sleep_time = ((1000.0/FPS) - (new_time - last_time))/1000.0
if sleep_time > 0:
time.sleep(sleep_time)
last_time = new_time
0
還有就是threading
模塊中的Timer
類。這可能比使用time.sleep
用於某些目的更方便。
>>> from threading import Timer
>>> def hello(who):
... print 'hello %s' % who
...
>>> t = Timer(5.0, hello, args=('world',))
>>> t.start() # and five seconds later...
hello world
0
您可以使用select?它通常用於等待I/O完成,但看看簽名:
select.select(rlist, wlist, xlist[, timeout])
是這樣,你可以這樣做:
timeout = 30.0
while true:
if select.select([], [], [], timeout):
#timout reached
# maybe you should recalculate your timeout ?
相關問題
- 1. 計時動畫gif顯示
- 2. 倒計時應用動畫
- 3. 正確計時CSS動畫
- 4. 計算動畫時間Qt
- 5. Python中的實時動畫
- 6. 流動動畫與計時(OpenGL)
- 7. 核心動畫 - 組中的動畫單獨計時
- 8. Python動畫圖
- 9. IPad Safari CSS3動畫計時錯誤
- 10. MatPlotLib中的計時/藝術家動畫
- 11. 針對非CSS的jQuery動畫計時
- 12. 使用jQuery進行計時動畫
- 13. 爲倒計時腳本設置動畫
- 14. 重置倒計時動畫c#WPF
- 15. 刷新UIScrollView /動畫,計時(Objective-C)
- 16. 使用時間線設計動畫
- 17. 角路由器動畫計時錯誤
- 18. 用python去動畫動畫gif
- 19. IE11薩斯計算C動畫計時不工作
- 20. 用動畫計算數字
- 21. 累計動畫與CSS
- 22. 動畫actionBar材質設計
- 23. Android動畫 - 選擇動畫時
- 24. 在動畫視圖時動畫UIButton
- 25. Spyder Python動畫不工作
- 26. 在python中動畫Colormesh圖
- 27. Python tkinter畫布動態Create.Line
- 28. Python Kivy小部件動畫
- 29. Python中的2D動畫
- 30. Python動畫陰影matplotlib
謝謝你,非常有幫助。我是Python的新手,但努力工作以更熟悉它。 – eriknelson 2010-04-18 03:21:57