Exemplo n.º 1
0
 def drawSquare(self, pos, color='red'):
   import graphicsUtils
   def getColor(c):
     colors = {
       -1 : '#ff0000',
       0 : '#ffffff',
       1 : '#00ff00',
       2 : '#ffff00'
     }
     if c in colors: return colors[c]
     else: return c
   color = getColor(color)
   graphicsUtils.square((pos[0]*15 + 14, 15*(14-pos[1]) + 14), 7.5, color)
Exemplo n.º 2
0
    def shadeCost(self, layout, constraints, costVector, feasiblePoints, xmin,
                  ymin, xmax, ymax):
        baseColor = [1.0, 0.0, 0.0]

        costs = [self.pointCost(costVector, point) for point in feasiblePoints]
        minCost = min(costs)
        maxCost = max(costs)
        costSpan = maxCost - minCost

        allFeasiblePoints = self.getFeasibleLayoutPoints(
            layout, constraints, xmin, ymin, xmax, ymax)

        # The feasible points themselves may have been gridded to infeasible grid points,
        # but we want to make sure they are shaded too.
        #cornerPoints = [self.cartesianToLayout(xmin, ymin, xmax, ymax, point) for point in feasiblePoints]
        cornerPoints = self.getLayoutPointsWithSymbol(layout, ('o', 'P'))

        gridPointsToShade = cornerPoints + allFeasiblePoints

        for gridPoint in gridPointsToShade:
            point = self.layoutToCartesian(xmin, ymin, xmax, ymax, gridPoint)

            relativeCost = (self.pointCost(costVector, point) -
                            minCost) * 1.0 / costSpan

            # Whoops our grid points are flipped top-bottom from what to_screen expects
            screenPos = self.to_screen(
                (gridPoint[0], len(layout) - gridPoint[1] - 1))

            cellColor = [
                0.25 + 0.5 * relativeCost * channel for channel in baseColor
            ]

            graphicsUtils.square(screenPos,
                                 0.5 * self.gridSize,
                                 color=graphicsUtils.formatColor(*cellColor),
                                 filled=1,
                                 behind=2)

        graphicsUtils.refresh()
        graphicsUtils.sleep(1)
Exemplo n.º 3
0
 def drawDistributions(self, state):
     walls = state.layout.walls
     dist = []
     for x in range(walls.width):
         distx = []
         dist.append(distx)
         for y in range(walls.height):
             (screen_x, screen_y) = self.to_screen((x, y))
             block = gU.square((screen_x, screen_y),
                               0.5 * self.gridSize,
                               color=BACKGROUND_COLOR,
                               filled=1, behind=2)
             distx.append(block)
     self.distributionImages = dist
Exemplo n.º 4
0
 def drawExpandedCells(self, cells):
     """
     Draws an overlay of expanded grid positions for search agents
     """
     n = float(len(cells))
     baseColor = [1.0, 0.0, 0.0]
     self.clearExpandedCells()
     self.expandedCells = []
     for k, cell in enumerate(cells):
         screenPos = self.to_screen(cell)
         cellColor = gU.formatColor(*[(n - k) * c * .5 / n + .25
                                      for c in baseColor])
         block = gU.square(screenPos,
                           0.5 * self.gridSize,
                           color=cellColor,
                           filled=1, behind=2)
         self.expandedCells.append(block)
         if self.frameTime < 0:
             gU.refresh()
Exemplo n.º 5
0
 def drawSquare(pos, size, color):
     return graphicsUtils.square(pos, size, color)