Esempio 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)
Esempio n. 2
0
 def squareColor(self, indices):
     """
     :param documentme
     """
     (xIndex, yIndex) = indices
     maxValue = 10
     storedValue = util.clip(self.grid[xIndex][yIndex], -maxValue, maxValue)
     v = util.clip((maxValue - storedValue) / maxValue, 0, 1)
     s = util.clip((storedValue + maxValue) / maxValue, 0, 1)
     if self.robotCanOccupy(indices):
         hue = colors.greenHue
     else:
         hue = colors.redHue
     return colors.RGBToPyColor(colors.HSVtoRGB(hue, 0.2 + 0.8 * s, v))