Coder Social home page Coder Social logo

bresenham's Introduction

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:

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.

bresenham's People

Contributors

dornheimer avatar encukou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

bresenham's Issues

Make algorithm work with float input?

Hi! Great work!

Maybe it is possible to make algorithm work with float input by changing line 32 from:
for x in range(dx + 1):
to
for x in range(int(dx + 1)):
in bresenham.py.

Vectorized implementation

Hi, I put together a vectorized implementation. Are you interested in adding it? If so, how would you like me to proceed?
The implementation is not an iterator: instead, it returns numpy arrays for Xs and Ys.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.