API

horton.grid.Grid(width, height[, value]) A Grid is a two-dimensional data-structure.
horton.grid.Torus(width, height[, value]) A Grid whose edges are connected.
class horton.grid.Grid(width, height, value=0)

A Grid is a two-dimensional data-structure.

It provides the Python Mapping interface whose keys are tuples representing co-ordinates in the Grid.

__add__(other)

Return a grid whose values are comprised by adding the values of two grids together.

__contains__(value)

Return True of value can be found in the grid.

__eq__(other)

Return True if equal to other.

Two grids are considered equal if every value in the grids are equal.

__getitem__(*args)

Return something from the grid.

The first argument of args is a tuple. If the elements of the tuple are integers then fetch the value at the coordinate. If the elements are slices then return a Grid from the region defined by them.

__iter__()

Return an iterator over the values.

__len__()

Return the total size.

__setitem__(*args)

Set an item in the grid to a value.

The first argument is an (x, y) tuple and the second is the value.

__sub__(other)

Return a grid whose values are comprised by subtracting the values from one by the other.

coordinates

Return the list of coordinates.

This value is cached internally after the initial call.

classmethod copy(other)

Return a new Grid as a copy of other.

dimensions

Return the dimensions tuple.

classmethod from_array(width, height, arr, copy=True)

Create a Grid from an array.

get(x, y, default=None)

Return a value at x, y.

Return a default value if the key cannot be found.

items()

Return a list of co-ordinate, value pairs.

iter_items()

Yield successive co-ordinate, value pairs.

static pprint(grid)

Pretty print a Grid object.

values

Return a copy of the grid values.

class horton.grid.Torus(width, height, value=0)

A Grid whose edges are connected.

__getitem__(*args)

Return an item from the grid.

The first argument is an (x, y) tuple.

__setitem__(*args)

Set an item in the grid to a value.

The first argument is an (x, y) tuple and the second is a value.