Skip to main content

fpstimer

A clock timer that provides sleep()-like features for maintaining a certain "frames per second" (FPS) framerate in Python 2 and 3.

Sometimes you'll want to slow down your computer so it doesn't run too fast for the user. For example, if you want to run a video game at 60 frames per second (FPS), but the game can render the graphics for the screen in less than 1/60 second, you'll need the program to pause for however much time is remaining in that 1/60 second. This varible amount of time can be calculated by FPS Timer.

Install

pip install fpstimer

Usage

The frame rate is set by passing the integer FPS to the FPSTimer() constructor. The FPSTimer object has an sleep() method that pauses for a variable amount of time needed to maintain that framerate.

For example, calling FPSTimer(10) creates a timer for 10 fps. Each "frame" should last for 1/10 of a second. Running your program without an FPS timer could cause your program to run too fast for the user, especially as CPUs get faster. After running the code for a single frame, calling sleep() will pause the program for however much is needed for the remaining 1/10 second for that frame. This pause is calculated from the last time that sleep() was called for the previous frame.

>>> import fpstimer
>>> timer = fpstimer.FPSTimer(60) # Make a timer that is set for 60 fps.
>>> for i in range(100): # Each iteration of this loop will last (at least) 1/60 of a second.
...     # Do calculations/work for a single "frame" here.
...     timer.sleep() # Pause just enough to have a 1/60 second wait since last fpstSleep() call.

Release files for fpstimer 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fpstimer 0.0.1
File Size Uploaded
fpstimer-0.0.1.tar.gz 2.9 kB Details

Release files / fpstimer-0.0.1.tar.gz

Download URL fpstimer-0.0.1.tar.gz
Size 2.9 kB
Tags Source
SHA-256 checksum
How to use checksums
fba3bcebfda796d2eb4251ea88e2b45b1f3909e05afa79812778d0d98c3acfca
BLAKE2b-256 checksum
How to use checksums
bf213661d769a596ca345a38f03e55e1b655bd647329a95efc7588bb1a1cddf1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.11.0 pkginfo/1.4.2 requests/2.21.0 setuptools/40.2.0 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.1

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page