Exemple #1
0
 def test_randomColor(self):
     config = {}
     config["color_list_path"] = "Color_list.txt"
     color_list_path = config["color_list_path"]
     file = open(color_list_path)
     colorList = []
     count = 0
     for item in file.read().split(' '):
         colorList.append(item)
     
     for color in randomColor.randomColor(config,3):
         self.assertEqual(True, color in colorList)
     file.close()
Exemple #2
0
    def OnButton(self, evt):
        png = wx.Image(opj('testimage.png'),
                       wx.BITMAP_TYPE_PNG).ConvertToBitmap()
        pos = 10
        wx.StaticBitmap(self, -1, png, (10, pos),
                        (png.GetWidth(), png.GetHeight()))

        dstImage = wx.ImageFromBitmap(png)

        emptyImage = wx.EmptyImage(png.GetWidth(), png.GetHeight())
        defaultRed = 138
        defaultGreen = 102
        defaultBlue = 110
        defaultRed1 = 183
        defaultGreen2 = 171
        defaultBlue3 = 173
        rcr = rcolor.randomColor()
        randomRed, randomGreen, randomBlue = rcr.getRandomColor()
        randomRed1, randomGreen1, randomBlue1 = rcr.getRandomColor()
        indexColor = 0
        for x in xrange(png.GetWidth()):
            for y in xrange(png.GetHeight()):
                if defaultRed == dstImage.GetRed(
                        x, y) and defaultGreen == dstImage.GetGreen(
                            x, y) and defaultBlue == dstImage.GetBlue(x, y):
                    emptyImage.SetRGB(x, y, randomRed, randomGreen, randomBlue)
                elif defaultRed1 == dstImage.GetRed(
                        x, y) and defaultGreen2 == dstImage.GetGreen(
                            x, y) and defaultBlue3 == dstImage.GetBlue(x, y):
                    emptyImage.SetRGB(x, y, randomRed1, randomGreen1,
                                      randomBlue1)
                else:
                    emptyImage.SetRGB(x, y, dstImage.GetRed(x, y),
                                      dstImage.GetGreen(x, y),
                                      dstImage.GetBlue(x, y))
                indexColor = indexColor + 1

        pos = pos + png.GetHeight() + 10
        self.tempImage = emptyImage.ConvertToBitmap()
        wx.StaticBitmap(
            self, -1, self.tempImage, (10, pos),
            (self.tempImage.GetWidth(), self.tempImage.GetHeight()))
Exemple #3
0
    def processImage(self, png):
        emptyImage = wx.EmptyImage(png.GetWidth(), png.GetHeight())
        colorGenerate = randomColor.randomColor()
        randomColorLst = []
        for colorItem in self.colorLst:
            colorArray = colorGenerate.getRandomColor()
            randomColorLst.append(
                colda.colorData(colorArray[0], colorArray[1], colorArray[2]))

        for x in xrange(png.GetWidth()):
            for y in xrange(png.GetHeight()):
                tempColorData = colda.colorData(self.dstImage.GetRed(x, y),
                                                self.dstImage.GetGreen(x, y),
                                                self.dstImage.GetBlue(x, y))
                indexColor = 0
                findColor = False
                c1, c2, c3 = 0, 0, 0
                for dataColor in self.colorLst:
                    if dataColor.isSameColor(tempColorData) == True:
                        tempRandomColorData = randomColorLst[indexColor]
                        c1, c2, c3 = tempRandomColorData.getColor()
                        findColor = True
                        break
                    indexColor = indexColor + 1
                if findColor == True:
                    panelInstance = self.panelLst[indexColor]
                    if panelInstance.isChecked() == False:
                        emptyImage.SetRGB(x, y, c1, c2, c3)
                    else:
                        emptyImage.SetRGB(x, y, self.dstImage.GetRed(x, y),
                                          self.dstImage.GetGreen(x, y),
                                          self.dstImage.GetBlue(x, y))
                else:
                    emptyImage.SetRGB(x, y, self.dstImage.GetRed(x, y),
                                      self.dstImage.GetGreen(x, y),
                                      self.dstImage.GetBlue(x, y))
        pos = png.GetHeight() + 10
        self.tempImage = emptyImage.ConvertToBitmap()
        wx.StaticBitmap(
            self, -1, self.tempImage, (10, pos),
            (self.tempImage.GetWidth(), self.tempImage.GetHeight()))
        self.blue = blue

    def setColor(self, red, green, blue):
        self.red = red
        self.green = green
        self.blue = blue

    def getColor(self):
        return self.red, self.green, self.blue

    def isSameColor(self, colordata):
        if colordata.red == self.red and colordata.green == self.green and colordata.blue == self.blue:
            return True
        return False


rc = randomColor.randomColor()
rdata = colorData(rc.getRandomColor())
"""
c1 = colorData()
c1.setColor(1,1,1)
c2 = colorData()
c2.setColor(1,1,1)
"""
"""
sample_list = []
sample_list.append(c1)
sample_list.append(c2)
for data in sample_list: 
    print(data.getColor())
"""