======
PyRect
======
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 pyrect``
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)``
``perimeter (read-only)``
Raw data
{
"_id": null,
"home_page": "https://github.com/asweigart/pyrect",
"name": "PyRect",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "pygame rect rectangular rectangle area",
"author": "Al Sweigart",
"author_email": "al@inventwithpython.com",
"download_url": "https://files.pythonhosted.org/packages/cb/04/2ba023d5f771b645f7be0c281cdacdcd939fe13d1deb331fc5ed1a6b3a98/PyRect-0.2.0.tar.gz",
"platform": null,
"description": "======\r\nPyRect\r\n======\r\nPyRect is a simple module with a Rect class for Pygame-like rectangular areas.\r\n\r\nThis 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.\r\n\r\nCurrently under development, though the basic features work.\r\n\r\nInstallation\r\n============\r\n\r\n ``pip install pyrect``\r\n\r\nQuickstart Guide\r\n================\r\n\r\nFirst, create a Rect object by providing the XY coordinates of its top-left corner, and then the width and height:\r\n\r\n >>> import pyrect\r\n >>> r = pyrect.Rect(0, 0, 10, 20)\r\n\r\nThere are several attributes that are automatically calculated (they have the same names as Pygame's Rect objects):\r\n\r\n >>> r.width, r.height, r.size\r\n (10, 20, (10, 20))\r\n >>> r. left\r\n 0\r\n >>> r.right\r\n 10\r\n >>> r.top\r\n 0\r\n >>> r.bottom\r\n 20\r\n >>> r.center\r\n (5, 10)\r\n >>> r.topleft\r\n (0, 0)\r\n >>> r.topright\r\n (10, 0)\r\n >>> r.midleft\r\n (0, 10)\r\n\r\nChanging these attributes re-calculates the others. The top-left corner is anchored for any growing or shrinking that takes place.\r\n\r\n >>> r.topleft\r\n (0, 0)\r\n >>> r.left = 100\r\n >>> r.topleft\r\n (100, 0)\r\n >>> r.topright\r\n (110, 0)\r\n >>> r.width = 30\r\n >>> r.topright\r\n (130, 0)\r\n\r\nRect objects are locked to integers, unless you set `enableFloat` to `True`:\r\n\r\n >>> r = pyrect.Rect(0, 0, 10, 20)\r\n >>> r.width = 10.5\r\n >>> r.width\r\n 10\r\n >>> r.enableFloat = True\r\n >>> r.width = 10.5\r\n >>> r.width\r\n 10.5\r\n >>> r2 = pyrect.Rect(0, 0, 10.5, 20.5, enableFloat=True)\r\n >>> r2.size\r\n (10.5, 20.5)\r\n\r\nRect Attributes\r\n===============\r\n\r\nRect objects have several attributes that can be read or modified. They are identical to Pygame's Rect objects:\r\n\r\n ``x, y``\r\n\r\n ``top, left, bottom, right``\r\n\r\n ``topleft, bottomleft, topright, bottomright``\r\n\r\n ``midtop, midleft, midbottom, midright``\r\n\r\n ``center, centerx, centery``\r\n\r\n ``size, width, height``\r\n\r\n ``w, h``\r\n\r\nThere are a couple other attributes as well:\r\n\r\n ``box (a tuple (left, top, width, height))``\r\n\r\n ``area (read-only)``\r\n\r\n ``perimeter (read-only)``\r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "PyRect is a simple module with a Rect class for Pygame-like rectangular areas.",
"version": "0.2.0",
"split_keywords": [
"pygame",
"rect",
"rectangular",
"rectangle",
"area"
],
"urls": [
{
"comment_text": "",
"digests": {
"md5": "8139f7036c54a0c770a14059d967f22e",
"sha256": "f65155f6df9b929b67caffbd57c0947c5ae5449d3b580d178074bffb47a09b78"
},
"downloads": -1,
"filename": "PyRect-0.2.0.tar.gz",
"has_sig": false,
"md5_digest": "8139f7036c54a0c770a14059d967f22e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 17219,
"upload_time": "2022-03-16T04:45:52",
"upload_time_iso_8601": "2022-03-16T04:45:52.360349Z",
"url": "https://files.pythonhosted.org/packages/cb/04/2ba023d5f771b645f7be0c281cdacdcd939fe13d1deb331fc5ed1a6b3a98/PyRect-0.2.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-03-16 04:45:52",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "asweigart",
"github_project": "pyrect",
"travis_ci": false,
"coveralls": true,
"github_actions": false,
"tox": true,
"lcname": "pyrect"
}