Skip to main content

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

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fpstimer-0.0.1.tar.gz (2.9 kB view details)

Uploaded Source

File details

Details for the file fpstimer-0.0.1.tar.gz.

File metadata

  • Download URL: fpstimer-0.0.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for fpstimer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 fba3bcebfda796d2eb4251ea88e2b45b1f3909e05afa79812778d0d98c3acfca
MD5 2369a5e1145f2793a30897d737ae92a7
BLAKE2b-256 bf213661d769a596ca345a38f03e55e1b655bd647329a95efc7588bb1a1cddf1

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page