def init_cells(direction_map): cells = [] nx, ny = direction_map.shape for i in xrange(nx): cells.append([]) for j in xrange(ny): theCell = Cell() theCell.x = i theCell.y = j cells[-1].append(Cell()) for i in xrange(nx): for j in xrange(ny): i_next, j_next = direction_and_value.to_indices(i, j, direction_map[i,j]) if i_next < 0 or j_next < 0 or i_next == nx or j_next == ny: nextCell = None else: nextCell = cells[i_next][j_next] cells[i][j].set_next(nextCell) return cells