Skip to main content

PyRect is a simple module with a Rect class for Pygame-like rectangular areas.

Project description

PyRect is a simple module with a Rect class for Pygame-like rectangular areas.

This module is like a stand-alone version of Pygame’s Rect class. It is similar to the Rect module by Simon Wittber, but compatible with both Python 2 and 3.

Currently under development, though the basic features work.

Installation

pip install rect

Quickstart Guide

First, create a Rect object by providing the XY coordinates of its top-left corner, and then the width and height:

>>> import pyrect
>>> r = pyrect.Rect(0, 0, 10, 20)

There are several attributes that are automatically calculated (they have the same names as Pygame’s Rect objects):

>>> r.width, r.height, r.size
(10, 20, (10, 20))
>>> r. left
0
>>> r.right
10
>>> r.top
0
>>> r.bottom
20
>>> r.center
(5, 10)
>>> r.topleft
(0, 0)
>>> r.topright
(10, 0)
>>> r.midleft
(0, 10)

Changing these attributes re-calculates the others. The top-left corner is anchored for any growing or shrinking that takes place.

>>> r.topleft
(0, 0)
>>> r.left = 100
>>> r.topleft
(100, 0)
>>> r.topright
(110, 0)
>>> r.width = 30
>>> r.topright
(130, 0)

Rect objects are locked to integers, unless you set enableFloat to True:

>>> r = pyrect.Rect(0, 0, 10, 20)
>>> r.width = 10.5
>>> r.width
10
>>> r.enableFloat = True
>>> r.width = 10.5
>>> r.width
10.5
>>> r2 = pyrect.Rect(0, 0, 10.5, 20.5, enableFloat=True)
>>> r2.size
(10.5, 20.5)

Rect Attributes

Rect objects have several attributes that can be read or modified. They are identical to Pygame’s Rect objects:

x, y

top, left, bottom, right

topleft, bottomleft, topright, bottomright

midtop, midleft, midbottom, midright

center, centerx, centery

size, width, height

w, h

There are a couple other attributes as well:

box (a tuple (left, top, width, height))

area (read-only)

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

PyRect-0.0.3.tar.gz (13.3 kB view details)

Uploaded Source

File details

Details for the file PyRect-0.0.3.tar.gz.

File metadata

  • Download URL: PyRect-0.0.3.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.23.4 CPython/3.7.0

File hashes

Hashes for PyRect-0.0.3.tar.gz
Algorithm Hash digest
SHA256 55064fb8c013f26dacd60cba9af70868bae9f3c4175f028e668f5521cf5c3b26
MD5 6997d9431640fc3008d74815f832081b
BLAKE2b-256 b41cc6d5fcfab460bc8006ac90e26c7b4f500b491d0a0c8f0dbcdbb5f651c59e

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