Ejemplo n.º 1
0
    def plotSlime(self):
        maxT = len(self.slimeData)
        if maxT == 0:
            print 'No slime to plot'
            return

        slimeX = [p[0] for p in self.slimeData]
        slimeY = [p[1] for p in self.slimeData]

        (xLower, xUpper, yLower,
         yUpper) = self.getEquallyScaledBounds(slimeX, slimeY)
        xRange = xUpper - xLower
        yRange = yUpper - yLower

        if util.within(xRange, 0, 0.001):
            return

        if self.slimeWindow:
            self.slimeWindow.destroy()
        self.slimeWindow = dw.DrawingWindow(\
            self.windowSize, self.windowSize, xLower, xUpper, yLower, yUpper,
            'slime')
        # Draw dimensions
        self.slimeWindow.drawText(xLower + 0.1 * xRange,
                                  yLower + 0.05 * yRange,
                                  util.prettyString(xLower),
                                  color="black")
        self.slimeWindow.drawText(xUpper - 0.1 * xRange,
                                  yLower + 0.05 * yRange,
                                  util.prettyString(xUpper),
                                  color="black")
        self.slimeWindow.drawText(xLower + 0.05 * xRange,
                                  yLower + 0.1 * yRange,
                                  util.prettyString(yLower),
                                  color="black")
        self.slimeWindow.drawText(xLower + 0.05 * xRange,
                                  yUpper - 0.1 * yRange,
                                  util.prettyString(yUpper),
                                  color="black")
        # Draw axes
        xMin = min(slimeX)
        xMax = max(slimeX)
        yMin = min(slimeY)
        yMax = max(slimeY)

        self.slimeWindow.drawLineSeg(xMin, yMin, xUpper - 0.1 * xRange, yMin,
                                     'gray')
        self.slimeWindow.drawLineSeg(xMin, yMin, xMin, yUpper - 0.1 * yRange,
                                     'gray')

        # Draw slime
        for i in range(maxT):
            self.slimeWindow.drawRobot(
                slimeX[i], slimeY[i], slimeX[i], slimeY[i],
                colors.RGBToPyColor(colors.HSVtoRGB(i * 360.0 / maxT, 1.0,
                                                    1.0)), 2)
Ejemplo n.º 2
0
def plot_soar_world_dw(path_to_world,
                       plot_win=None,
                       linestyle='k',
                       title=None,
                       windowSize=600):
    body = ast.parse(open(path_to_world).read()).body
    walls = []
    offset = (0, 0)
    dim = (0, 0)
    for elt in body:
        if isinstance(elt, ast.Expr) and isinstance(elt.value, ast.Call):
            #everything we care about falls here (i think)
            if isinstance(elt.value.func, ast.Name):
                args = tuple(pythonic_from_ast(i) for i in elt.value.args)
                if elt.value.func.id == 'initial_robot_loc':
                    offset = args
                elif elt.value.func.id == 'wall':
                    walls.append(args)
                elif elt.value.func.id == 'dimensions':
                    dim = args

    # Robot's location needs to be (0, 0)
    # In the world definition, y decreases from the top
    xmin = -offset[0]
    xmax = xmin + dim[0]
    ymin = -offset[1]
    ymax = ymin + dim[1]

    print('x, y', (xmin, xmax), (ymin, ymax))
    print('window size', windowSize, int(windowSize * float(dim[1]) / dim[0]))
    print('dim', dim)

    if plot_win is None:
        if title is None:
            title = "Soar World Plot: {}, -- {}".\
                    format(os.path.basename(path_to_world),
                           datetime.now().strftime("%b %d, '%y; %I:%M:%S %p"))
        eps = 0.1 * dim[0]
        plot_win = dw.DrawingWindow(windowSize,
                                    int(windowSize * float(dim[1]) / dim[0]),
                                    xmin - eps,
                                    xmax + eps,
                                    ymin - eps,
                                    ymax + eps,
                                    title=title)

    plot_win.drawLineSeg(xmin, ymin, xmin, ymax)
    plot_win.drawLineSeg(xmin, ymax, xmax, ymax)
    plot_win.drawLineSeg(xmax, ymax, xmax, ymin)
    plot_win.drawLineSeg(xmax, ymin, xmin, ymin)
    #now add in walls
    for wall in walls:
        plot_win.draw_path([xmin + i[0] for i in wall],
                           [ymin + i[1] for i in wall],
                           color='black')
    return (plot_win, util.Point(offset[0], offset[1]))
Ejemplo n.º 3
0
 def makeWindow(self, windowWidth = defaultWindowWidth, title = 'Grid Map'):
     """
     Create a window of the right dimensions representing the grid map.
     Store in C{self.window}.
     """
     dx = self.xMax - self.xMin
     dy = self.yMax - self.yMin
     maxWorldDim = float(max(dx, dy))
     margin = 0.01*maxWorldDim
     margin = 0.0*maxWorldDim
     self.window = dw.DrawingWindow(int(windowWidth*dx/maxWorldDim),
                             int(windowWidth*dy/maxWorldDim),
                             self.xMin - margin, self.xMax + margin,
                             self.yMin - margin, self.yMax + margin, 
                             title)
     windows.windowList.append(self.window)