聊城做网站做的不错的,网页链接打不开,旅游网站对比模板下载,wap网站做视频直播控制fps的时钟Clock类#xff0c;本程序用来在循环中控制fps。如何在海龟画图中控制fps#xff1f;这是一个比较重要的问题#xff0c;否则程序可能有时候快有时候慢。import timeimport colorsysfrom turtle import *from random impo…控制fps的时钟Clock类本程序用来在循环中控制fps。如何在海龟画图中控制fps这是一个比较重要的问题否则程序可能有时候快有时候慢。import timeimport colorsysfrom 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,fps0):end_time time.perf_counter()passdef getfps(self):得到fpst time.perf_counter() - self._old_start_timereturn round(1/t,2)# 类定义好了以下是测试Clock类的代码def makecolors(n128):产生颜色表这种颜色表中的颜色更鲜艳cs []passreturn cscolorlist makecolors()screen Screen()screen.tracer(0,0)screen.setup(480,360)screen.title(控制fps的时钟类)fps 10 # 设定fpsindex 0 # 颜色表索引clock Clock() # 建立时钟对象while 1:screen.bgcolor(colorlist[index])index index 1index index % len(colorlist)t clock.tick(fps)screen.title(fps str(clock.getfps()) :逝去的时间 str(t))如需要查看完整源代码,请扫码付款:VIP免费查看当前隐藏内容需要支付60元已有0人支付立即购买