Pixelscan
A Python library that provides functions to scan pixels on a grid in a variety of spatial patterns.
Install / Use
/learn @dpmcmlxxvi/PixelscanREADME
========= pixelscan
.. image:: https://travis-ci.org/dpmcmlxxvi/pixelscan.svg?branch=master :target: https://travis-ci.org/dpmcmlxxvi/pixelscan :alt: Code Status
.. image:: https://coveralls.io/repos/dpmcmlxxvi/pixelscan/badge.svg?branch=master&service=github :target: https://coveralls.io/github/dpmcmlxxvi/pixelscan?branch=master :alt: Code Coverage
.. image:: https://badge.fury.io/py/pixelscan.svg :target: https://pypi.python.org/pypi/pixelscan :alt: Code Package
The pixelscan library provides functions to scan pixels on a grid in a variety of spatial patterns. The library consists of scan generators and coordinate transformations. Scan generators are Python generators that return pixel coordinates in a particular spatial pattern. Coordinate transformations are iterators that apply spatial transformations to the coordinates created by the scan generators. Transformation can be chained to yield very generic transformations.
Documentation
See the library API documentation here <http://dpmcmlxxvi.github.io/pixelscan>_.
Usage
The typical calling syntax is
.. code-block:: python
for x, y in transformation(generator(...), ...): foo(x,y)
For example, the following scans pixels in a clockwise circular pattern from the origin up to a radius of one
.. code-block:: python
for x, y in snap(circlescan(0, 0, 0, 1)): print(x, y)
and will generate the following points
.. code-block:: python
(0,0), (0,1), (1,1), (1,0), (1,-1), (0,-1), (-1,-1), (-1,0), (-1,1)
To skip every other pixel a skip transformation can be applied
.. code-block:: python
for x, y in snap(skip(circlescan(0, 0, 0, 1), step=2)): print(x, y)
which will generate the following points
.. code-block:: python
(0,0), (1,1), (1,-1), (-1,-1), (-1,1)
Scan Generators
The following are the currently available generators
+------------------------------------+-----------------------------------------------------------+ | Name | Description | +====================================+===========================================================+ |circlescan |Generates pixels in a clockwise circular pattern | +------------------------------------+-----------------------------------------------------------+ | .. image:: examples/circlescan.png |.. code-block:: python | | | | | | x0, y0, r1, r2 = 0, 0, 0, 2 | | | for x, y in snap(circlescan(x0, y0, r1, r2)): | | | print(x, y) | | | | | |where | | | | | |.. code-block:: rest | | | | | | x0 = Circle x center | | | y0 = Circle y center | | | r1 = Initial radius | | | r2 = Final radius | | | | | |produces the following points: | | | | | |.. code-block:: python | | | | | | ( 0, 0) ( 0, 1) ( 1, 1) ( 1, 0) ( 1,-1) ( 0,-1) | | | (-1,-1) (-1, 0) (-1, 1) ( 0, 2) ( 1, 2) ( 2, 1) | | | ( 2, 0) ( 2,-1) ( 1,-2) ( 0,-2) (-1,-2) (-2,-1) | | | (-2, 0) (-2, 1) (-1, 2) | +------------------------------------+-----------------------------------------------------------+ |gridscan |Generates pixels in rectangular grid pattern | +------------------------------------+-----------------------------------------------------------+ | .. image:: examples/gridscan.png |.. code-block:: python | | | | | | xi, yi, xf, yf = 0, 0, 2, 2 | | | for x, y in gridscan(xi, yi, xf, yf, stepx=1, stepy=1): | | | print(x, y) | | | | | |where | | | | | |.. code-block:: rest | | | | | | xi = Initial x-coordinate | | | yi = Initial y-coordinate | | | xf = Final x-coordinate | | | yf = Final y-coordinate | | | stepx = Step size in x-coordinate | | | stepy = Step size in y-coordinate | | | | | |produces the following points: | | | | | |.. code-block:: python | | | | | | (0,0) (1,0) (2,0) (0,1) (1,1) (2,1) (0,2) (1,2) (2,2) | +------------------------------------+-----------------------------------------------------------+ |hilbertscan |Generates pixels in a Hilbert curve pattern | +------------------------------------+-----------------------------------------------------------+ | .. image:: examples/hilbertscan.png|.. code-block:: python | | | | | | size, distance = 4, 16 | | | for x, y in hilbertscan(size, distance): | | | print(x, y) | | | | | |where | | | | | |.. code-block:: rest | | | | | | size = Size of enclosing square | | | distance = Distance along curve | | | | | |produces the following points: | | | | | |.. code-block:: python | | | | | | (0,0), (0,1), (1,1), (1,0), (2,0), (3,0), (3,1), (2,1) | | | (2,2), (3,2), (3,3), (2,3), (1,3), (1,2), (0,2), (0,3) | +------------------------------------+-----------------------------------------------------------+ |ringscan - chebyshev |Generates pixels in a ring pattern (squares) | +------------------------------------+-----------------------------------------------------------+ | .. image:: examples/chebyshev.png |.. code-block:: python | | | | | | x0, y0, r1, r2 = 0, 0, 0, 2
