Field of View

libtcod map attributes and field-of-view functions.

class int, height: int, order: Literal['C', 'F'] = 'C')[source]#

A map containing libtcod attributes.

Changed in version 4.1: transparent, walkable, and fov are now numpy boolean arrays.

Changed in version 4.3: Added order parameter.

  • width (int) – Width of the new Map.

  • height (int) – Height of the new Map.

  • order (str) – Which numpy memory order to use.


Read only width of this Map.




Read only height of this Map.




A boolean array of transparent cells.


A boolean array of walkable cells.


A boolean array of the cells lit by :any:’compute_fov’.


>>> import tcod
>>> m =, height=4)
>>> m.walkable
array([[False, False, False],
       [False, False, False],
       [False, False, False],
       [False, False, False]]...)

# Like the rest of the tcod modules, all arrays here are
# in row-major order and are addressed with [y,x]
>>> m.transparent[:] = True  # Sets all to True.
>>> m.transparent[1:3,0] = False  # Sets (1, 0) and (2, 0) to False.
>>> m.transparent
array([[ True,  True,  True],
       [False,  True,  True],
       [False,  True,  True],
       [ True,  True,  True]]...)

>>> m.compute_fov(0, 0)
>>> m.fov
array([[ True,  True,  True],
       [ True,  True,  True],
       [False,  True,  True],
       [False, False,  True]]...)
>>> m.fov[3,1]

Deprecated since version 11.13: You no longer need to use this class to hold data for field-of-view or pathfinding as those functions can now take NumPy arrays directly. See and tcod.path.

compute_fov(x: int, y: int, radius: int = 0, light_walls: bool = True, algorithm: int = 12) None[source]#

Compute a field-of-view on the current instance.

  • x (int) – Point of view, x-coordinate.

  • y (int) – Point of view, y-coordinate.

  • radius (int) –

    Maximum view distance from the point of view.

    A value of 0 will give an infinite distance.

  • light_walls (bool) – Light up walls, or only the floor.

  • algorithm (int) – Defaults to tcod.FOV_RESTRICTIVE

If you already have transparency in a NumPy array then you could use instead. ArrayLike, pov: tuple[int, int], radius: int = 0, light_walls: bool = True, algorithm: int = 12) NDArray[np.bool_][source]#

Return a boolean mask of the area covered by a field-of-view.

transparency is a 2 dimensional array where all non-zero values are considered transparent. The returned array will match the shape of this array.

pov is the point-of-view origin point. Areas are visible if they can be seen from this position. pov should be a 2D index matching the axes of the transparency array, and must be within the bounds of the transparency array.

radius is the maximum view distance from pov. If this is zero then the maximum distance is used.

If light_walls is True then visible obstacles will be returned, otherwise only transparent areas will be.

algorithm is the field-of-view algorithm to run. The default value is tcod.FOV_RESTRICTIVE. The options are:

  • tcod.FOV_BASIC: Simple ray-cast implementation.

  • tcod.FOV_DIAMOND

  • tcod.FOV_SHADOW: Recursive shadow caster.

  • tcod.FOV_PERMISSIVE(n): n starts at 0 (most restrictive) and goes up to 8 (most permissive.)



New in version 9.3.

Changed in version 11.0: The parameters x and y have been changed to pov.

Changed in version 11.17: Added tcod.FOV_SYMMETRIC_SHADOWCAST option.


>>> explored = np.zeros((3, 5), dtype=bool, order="F")
>>> transparency = np.ones((3, 5), dtype=bool, order="F")
>>> transparency[:2, 2] = False
>>> transparency  # Transparent area.
array([[ True,  True, False,  True,  True],
       [ True,  True, False,  True,  True],
       [ True,  True,  True,  True,  True]]...)
>>> visible =, (0, 0))
>>> visible  # Visible area.
array([[ True,  True,  True, False, False],
       [ True,  True,  True, False, False],
       [ True,  True,  True,  True, False]]...)
>>> explored |= visible  # Keep track of an explored area.

See also

numpy.where: For selecting between two arrays using a boolean array, like the one returned by this function. Select between arrays based on multiple conditions.