The bresenham module
A simple implementation of Bresenham’s line drawing algorithm.
See the Wikipedia entry for details on what that is.
Note that this is a simple implementation. It is written in Pure Python (without e.g. numpy), so it is relatively slow.
I found some beauty in combining the classic algorithm (whose ingenuity lies in using only integers – a constraint that isn’t really as relevant now) with a Python generator (a modern device that follows the spirit of “executable pseudocode”, abstracting away the output subroutine). I hope others can appreciate the code as well.
For serious use, look at these:
skimage.draw.line, which solves the same problem fast.
A Numpy-based recipe that generalizes the solution to <var>N</var> dimensions.
Installation
In a Python virtual environment, do:
python -m pip install bresenham
To install from a Git checkout (in editable mode):
python -m pip install -e.
To install without a virtual envitonment, add the --user option.
Usage
The bresenham(x0, y0, x1, y1) function returns a generator of the coordinates of the line from (x0, y0) to (x1, y1).
For example, the coordinates of a line from (-1, -4) to (3, 2), are:
>>> from bresenham import bresenham >>> list(bresenham(-1, -4, 3, 2)) [(-1, -4), (0, -3), (0, -2), (1, -1), (2, 0), (2, 1), (3, 2)]
Development
You’re welcome to join this project!
If you spot an issue, please report it at the Issues page on Github.
If you’d like to start changing the code or documentation, check out the code locally using:
git clone https://github.com/encukou/bresenham
If you’re new to this, please read the this guide about collaborating on Github-hosted projects like this one.
If that doesn’t make sense, please e-mail the author for clarification. I’d be happy to help you get started.
Metadata
Release files for bresenham 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bresenham-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for bresenham-0.2.1-py3-none-any.whl |
Release files / bresenham-0.2.1-py3-none-any.whl
| Download URL | bresenham-0.2.1-py3-none-any.whl |
|---|---|
| Size | 3.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c076b8bf730adb65cc5037d26639a5629dd63f6c1481d80b6856c99d47a1c6bf
|
|
BLAKE2b-256 checksum How to use checksums |
71dbb614ac2ef531a4ea5402342db8630f4842388fb86e4640c81b0e23b16d64
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.2 pkginfo/1.4.2 requests/2.20.0 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.2
|
Security for bresenham 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.