我目前正在研究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. Android活動動畫計時
- 2. 計算動畫時間Qt
- 3. 計時器與動畫
- 4. 正確計時CSS動畫
- 5. 倒計時應用動畫
- 6. jQuery的動畫計時
- 7. 計時器和動畫
- 8. 計時動畫gif顯示
- 9. CSS動畫計時問題
- 10. Python中的實時動畫
- 11. 流動動畫與計時(OpenGL)
- 12. XAML動畫運動倒計時
- 13. 動畫的TextView更改文本,並再次動畫(動畫倒計時)
- 14. 核心動畫 - 組中的動畫單獨計時
- 15. Python動畫圖
- 16. MatPlotLib中的計時/藝術家動畫
- 17. 使用幀計時器的Raphaël動畫
- 18. 重置倒計時動畫c#WPF
- 19. 針對非CSS的jQuery動畫計時
- 20. UIView動畫同時計數線程
- 21. IPad Safari CSS3動畫計時錯誤
- 22. 刷新UIScrollView /動畫,計時(Objective-C)
- 23. CSS動畫未正確計時
- 24. 爲倒計時腳本設置動畫
- 25. 使用時間線設計動畫
- 26. 角路由器動畫計時錯誤
- 27. 使用計時器的動畫?
- 28. 基於計時器的反應動畫
- 29. 使用jQuery進行計時動畫
- 30. 用python去動畫動畫gif
謝謝你,非常有幫助。我是Python的新手,但努力工作以更熟悉它。 – eriknelson 2010-04-18 03:21:57