python2clock_控制fps的时钟Clock类源码
"""
控制fps的時(shí)鐘Clock類,
本程序用來(lái)在循環(huán)中控制fps。
如何在海龜畫圖中控制fps?這是一個(gè)比較重要的問(wèn)題,否則程序可能有時(shí)候快有時(shí)候慢。
"""
import time
import colorsys
from turtle import *
from random import *
class Clock:
def __init__(self):
self._old_start_time = time.perf_counter()
self._start_time = time.perf_counter()
def tick(self,fps=0):
end_time = time.perf_counter()
pass
def getfps(self):
"""得到fps"""
t = time.perf_counter() - self._old_start_time
return round(1/t,2)
# 類定義好了,以下是測(cè)試Clock類的代碼:
def makecolors(n=128):
"""產(chǎn)生顏色表,這種顏色表中的顏色更鮮艷"""
cs = []
pass
return cs
colorlist = makecolors()
screen = Screen()
screen.tracer(0,0)
screen.setup(480,360)
screen.title("控制fps的時(shí)鐘類")
fps = 10 # 設(shè)定fps
index = 0 # 顏色表索引
clock = Clock() # 建立時(shí)鐘對(duì)象
while 1:
screen.bgcolor(colorlist[index])
index = index + 1
index = index % len(colorlist)
t = clock.tick(fps)
screen.title("fps=" + str(clock.getfps())+ ":逝去的時(shí)間:" + str(t))
如需要查看完整源代碼,請(qǐng)掃碼付款:
VIP免費(fèi)查看
當(dāng)前隱藏內(nèi)容需要支付
60元
已有0人支付
立即購(gòu)買
總結(jié)
以上是生活随笔為你收集整理的python2clock_控制fps的时钟Clock类源码的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: python随机数生成的方法_pytho
- 下一篇: python关键字驱动框架搭建_pyth