Module gridMap :: Class GridMap
[frames] | no frames]

Class GridMap

Instance Methods
 
__init__(self, xMin, xMax, yMin, yMax, gridSquareSize, windowWidth=400)
Basic initializer that determines the number of cells, and calls the makeStartingGrid method that any subclass must provide, to get the initial values.
 
makeWindow(self, windowWidth=400, title='Grid Map')
Create a window of the right dimensions representing the grid map.
 
xToIndex(self, x)
Returns: x grid index it maps into
 
yToIndex(self, y)
Returns: y grid index it maps into
 
indexToX(self, ix)
Returns: the real x coordinate of the center of that grid cell
 
indexToY(self, iy)
Returns: the real y coordinate of the center of that grid cell
 
pointToIndices(self, point)
Returns: pair of (x, y) grid indices it maps into
 
indicesToPoint(self, (ix, iy))
Returns: c{Point} in real world coordinates of center of cell
 
boxDim(self)
Returns: size of a grid cell in the drawing window in pixels
 
drawWorld(self)
Clears the whole window and redraws the grid
 
drawNewSquare(self, indices, color=None)
 
drawSquare(self, indices, color=None)
Recolors the existing square
 
drawPath(self, path)
Draws list of cells; first one is purple, last is yellow, rest are blue
 
undrawPath(self, path)
Draws list of cells using the underlying grid color scheme, effectively 'undrawing' a path.
 
squareColor(self, indices)
Default color scheme: squares that the robot can occupy are white and others are black.
Instance Variables
  xMin
X coordinate of left edge
  xMax
X coordinate of right edge
  yMin
Y coordinate of bottom edge
  yMax
Y coordinate of top edge
  xN
number of cells in x dimension
  yN
number of cells in y dimension
  xStep
size of a side of a cell in the x dimension
  yStep
size of a side of a cell in the y dimension
  grid
values stored in the grid cells
  graphicsGrid
graphics objects
Method Details

__init__(self, xMin, xMax, yMin, yMax, gridSquareSize, windowWidth=400)
(Constructor)

 

Basic initializer that determines the number of cells, and calls the makeStartingGrid method that any subclass must provide, to get the initial values. Makes a window and draws the initial world state in it.

Parameters:
  • xMin - least real x coordinate
  • xMax - greatest real x coordinate
  • yMin - least real y coordinate
  • yMax - greatest real y coordinate
  • gridSquareSize - size, in world coordinates, of a grid square
  • windowWidth - size, in pixels, to make the window for drawing this map

makeWindow(self, windowWidth=400, title='Grid Map')

 

Create a window of the right dimensions representing the grid map. Store in self.window.

xToIndex(self, x)

 
Parameters:
  • x - real world x coordinate
Returns:
x grid index it maps into

yToIndex(self, y)

 
Parameters:
  • y - real world y coordinate
Returns:
y grid index it maps into

indexToX(self, ix)

 
Parameters:
  • ix - grid index in the x dimension
Returns:
the real x coordinate of the center of that grid cell

indexToY(self, iy)

 
Parameters:
  • iy - grid index in the y dimension
Returns:
the real y coordinate of the center of that grid cell

pointToIndices(self, point)

 
Parameters:
  • point - real world point coordinates (instance of Point)
Returns:
pair of (x, y) grid indices it maps into

indicesToPoint(self, (ix, iy))

 
Parameters:
  • ix - x index of grid cell
  • iy - y index of grid cell
Returns:
c{Point} in real world coordinates of center of cell

boxDim(self)

 
Returns:
size of a grid cell in the drawing window in pixels

drawNewSquare(self, indices, color=None)

 
Parameters:
  • indices - (ix, iy) indices of grid cell
  • color - Python color to draw the square; if None uses the self.squareColor method to determine a color. Draws a box at the specified point, on top of whatever is there

drawSquare(self, indices, color=None)

 

Recolors the existing square

Parameters:
  • indices - (ix, iy) indices of grid cell
  • color - Python color to draw the square; if None uses the self.squareColor method to determine a color.

drawPath(self, path)

 

Draws list of cells; first one is purple, last is yellow, rest are blue

Parameters:
  • path - list of pairs of (ix, iy) grid indices

undrawPath(self, path)

 

Draws list of cells using the underlying grid color scheme, effectively 'undrawing' a path.

Parameters:
  • path - list of pairs of (ix, iy) grid indices