A Python module of generators that generate x, y coordinates for various vector shapes such as lines, rectangles, etc. Named after Bresenham of line-algorithm fame.
Project description
# PyBresenham
A Python module of generators that generate x, y coordinates for various vector shapes such as lines, rectangles, etc. Named after Bresenham of line-algorithm fame.
For example:
```python
>>> import pybresenham
>>> pybresenham.line(0, 0, 3, 6)
<generator object line at 0x00000000030923B8>
>>> list(pybresenham.line(0, 0, 3, 6))
[(0, 0), (0, 1), (1, 2), (1, 3), (2, 4), (2, 5), (3, 6)]
```
PyBresenham is currently under development, and is seeking contributors!
Installation
============
pip install pybresenham
Example Usage
=============
Get the points of a line from (0, 0) to (5, 10):
>>> import pybresenham
>>> for x, y in pybresenham.line(0, 0, 5, 10):
... print('(%s, %s)' % (x, y))
...
(0, 0)
(0, 1)
(1, 2)
(1, 3)
(2, 4)
(2, 5)
(3, 6)
(3, 7)
(4, 8)
(4, 9)
(5, 10)
>>> list(pybresenham.line(0, 0, 5, 10))
[(0, 0), (0, 1), (1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7), (4, 8), (4, 9), (5, 10)]
Get the points of a multiline from (0, 0) to (2, 0) to (2, 2):
>>> import pybresenham
>>> list(pybresenham.lines([(0, 0), (2, 0), (2, 2)]))
[(0, 0), (1, 0), (2, 0), (2, 1), (2, 2)]
Get the points of a circle, centered on (0, 0), with radius 3:
>>> list(pybresenham.circle(0, 0, 3))
[(0, -3), (3, 0), (0, 3), (1, -3), (3, -1), (3, 1), (-1, 3), (-3, -1), (-3, 1), (-1, -3), (1, 3), (2, -2), (2, 2), (-2, 2), (-2, -2)]
Get a quick drawing of the above circle:
>>> import pybresenham
>>> pybresenham._drawPoints(pybresenham.circle(0, 0, 3), bg=' ')
OOO
O O
O O
O O
O O
O O
OOO
Get a quick drawing of a square and rectangle:
>>> import pybresenham
>>> list(pybresenham.square(0, 0, 4))
[(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (3, 2), (3, 3), (2, 3), (1, 3), (0, 3), (0, 2), (0, 1)]
>>> pybresenham._drawPoints(pybresenham.square(0, 0, 4), bg=' ')
OOOO
O O
O O
OOOO
>>> pybresenham._drawPoints(pybresenham.rectangle(0, 0, 15, 4), bg=' ')
OOOOOOOOOOOOOOO
O O
O O
OOOOOOOOOOOOOOO
>>> drawPoints(polygon(10, 10, 8, 5), bg=' ')
O
O O
O OO
O O
OO O
O O
O O
O O
O O
O O
O O
O O
O O
O O
OOOOOOOOO
>>> drawPoints(polygon(10, 10, 8, 5, rotationDegrees=20), bg=' ')
OO
O OOO
O OO
O OO
O O
O O
O O
O O
O O
O O
O O
O OO
O OO
O OOO
OO
Road Map
========
The following functions aren't yet implemented:
* ellipse()
* ellipseVertices()
* arc()
* arcVertices()
* star()
* starVertices()
* hexGrid()
* hexGridVertices()
* hexGridInterior()
* bezier()
* bezierVertices()
* roundedBox()
* roundedBoxVertices()
The `thickness`, `filled`, `endcap`, and `viewport` parameters are still unimplemented. (Except for square() and rectangle(), which do implement the `filled` parameter.)
A Python module of generators that generate x, y coordinates for various vector shapes such as lines, rectangles, etc. Named after Bresenham of line-algorithm fame.
For example:
```python
>>> import pybresenham
>>> pybresenham.line(0, 0, 3, 6)
<generator object line at 0x00000000030923B8>
>>> list(pybresenham.line(0, 0, 3, 6))
[(0, 0), (0, 1), (1, 2), (1, 3), (2, 4), (2, 5), (3, 6)]
```
PyBresenham is currently under development, and is seeking contributors!
Installation
============
pip install pybresenham
Example Usage
=============
Get the points of a line from (0, 0) to (5, 10):
>>> import pybresenham
>>> for x, y in pybresenham.line(0, 0, 5, 10):
... print('(%s, %s)' % (x, y))
...
(0, 0)
(0, 1)
(1, 2)
(1, 3)
(2, 4)
(2, 5)
(3, 6)
(3, 7)
(4, 8)
(4, 9)
(5, 10)
>>> list(pybresenham.line(0, 0, 5, 10))
[(0, 0), (0, 1), (1, 2), (1, 3), (2, 4), (2, 5), (3, 6), (3, 7), (4, 8), (4, 9), (5, 10)]
Get the points of a multiline from (0, 0) to (2, 0) to (2, 2):
>>> import pybresenham
>>> list(pybresenham.lines([(0, 0), (2, 0), (2, 2)]))
[(0, 0), (1, 0), (2, 0), (2, 1), (2, 2)]
Get the points of a circle, centered on (0, 0), with radius 3:
>>> list(pybresenham.circle(0, 0, 3))
[(0, -3), (3, 0), (0, 3), (1, -3), (3, -1), (3, 1), (-1, 3), (-3, -1), (-3, 1), (-1, -3), (1, 3), (2, -2), (2, 2), (-2, 2), (-2, -2)]
Get a quick drawing of the above circle:
>>> import pybresenham
>>> pybresenham._drawPoints(pybresenham.circle(0, 0, 3), bg=' ')
OOO
O O
O O
O O
O O
O O
OOO
Get a quick drawing of a square and rectangle:
>>> import pybresenham
>>> list(pybresenham.square(0, 0, 4))
[(0, 0), (1, 0), (2, 0), (3, 0), (3, 1), (3, 2), (3, 3), (2, 3), (1, 3), (0, 3), (0, 2), (0, 1)]
>>> pybresenham._drawPoints(pybresenham.square(0, 0, 4), bg=' ')
OOOO
O O
O O
OOOO
>>> pybresenham._drawPoints(pybresenham.rectangle(0, 0, 15, 4), bg=' ')
OOOOOOOOOOOOOOO
O O
O O
OOOOOOOOOOOOOOO
>>> drawPoints(polygon(10, 10, 8, 5), bg=' ')
O
O O
O OO
O O
OO O
O O
O O
O O
O O
O O
O O
O O
O O
O O
OOOOOOOOO
>>> drawPoints(polygon(10, 10, 8, 5, rotationDegrees=20), bg=' ')
OO
O OOO
O OO
O OO
O O
O O
O O
O O
O O
O O
O O
O OO
O OO
O OOO
OO
Road Map
========
The following functions aren't yet implemented:
* ellipse()
* ellipseVertices()
* arc()
* arcVertices()
* star()
* starVertices()
* hexGrid()
* hexGridVertices()
* hexGridInterior()
* bezier()
* bezierVertices()
* roundedBox()
* roundedBoxVertices()
The `thickness`, `filled`, `endcap`, and `viewport` parameters are still unimplemented. (Except for square() and rectangle(), which do implement the `filled` parameter.)
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
PyBresenham-0.0.5.tar.gz
(19.2 kB
view details)
File details
Details for the file PyBresenham-0.0.5.tar.gz
.
File metadata
- Download URL: PyBresenham-0.0.5.tar.gz
- Upload date:
- Size: 19.2 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | a2ddfd4dc87a6c77dddf60b595bdcb0f7f34bd9c5a1d0d5e36d69c7e74cdb3d0 |
|
MD5 | c017125ed33d25741959ad471963ab91 |
|
BLAKE2b-256 | 9060d910211729e2dbfb70fe6b5045fe23298ad51483cde2863c8c9a00b04bae |