Exemplo n.º 1
0
    def on_rgb_press(self,r,g,b):
        """
        Callback to rgb button
        """
        self.rgb = introcs.RGB(r, g, b)
        self.hsv = a2.rgb_to_hsv(self.rgb)
        assert (self.hsv == None or type(self.hsv) == introcs.HSV), \
                'rgb_to_hsv does not return a HSV object'

        self.cmyk = a2.rgb_to_cmyk(self.rgb)
        assert (self.cmyk == None or type(self.cmyk) == introcs.CMYK), \
                'rgb_to_cmyk does not return a CMYK object'
        self.update()
Exemplo n.º 2
0
def test_rgb_to_cmyk():
    """
    Test translation function rgb_to_cmyk
    """
    rgb = introcs.RGB(255, 255, 255)
    cmyk = a2.rgb_to_cmyk(rgb)
    introcs.assert_equals('0.000', a2.str5(cmyk.cyan))
    introcs.assert_equals('0.000', a2.str5(cmyk.magenta))
    introcs.assert_equals('0.000', a2.str5(cmyk.yellow))
    introcs.assert_equals('0.000', a2.str5(cmyk.black))

    rgb = introcs.RGB(0, 0, 0)
    cmyk = a2.rgb_to_cmyk(rgb)
    introcs.assert_equals('0.000', a2.str5(cmyk.cyan))
    introcs.assert_equals('0.000', a2.str5(cmyk.magenta))
    introcs.assert_equals('0.000', a2.str5(cmyk.yellow))
    introcs.assert_equals('100.0', a2.str5(cmyk.black))

    rgb = introcs.RGB(217, 43, 164)
    cmyk = a2.rgb_to_cmyk(rgb)
    introcs.assert_equals('0.000', a2.str5(cmyk.cyan))
    introcs.assert_equals('80.18', a2.str5(cmyk.magenta))
    introcs.assert_equals('24.42', a2.str5(cmyk.yellow))
    introcs.assert_equals('14.90', a2.str5(cmyk.black))

    rgb = introcs.RGB(0, 165, 39)
    cmyk = a2.rgb_to_cmyk(rgb)
    introcs.assert_equals('100.0', a2.str5(cmyk.cyan))
    introcs.assert_equals('0.000', a2.str5(cmyk.magenta))
    introcs.assert_equals('76.36', a2.str5(cmyk.yellow))
    introcs.assert_equals('35.29', a2.str5(cmyk.black))

    rgb = introcs.RGB(23, 66, 188)
    cmyk = a2.rgb_to_cmyk(rgb)
    introcs.assert_equals('87.77', a2.str5(cmyk.cyan))
    introcs.assert_equals('64.89', a2.str5(cmyk.magenta))
    introcs.assert_equals('0.000', a2.str5(cmyk.yellow))
    introcs.assert_equals('26.27', a2.str5(cmyk.black))
Exemplo n.º 3
0
    def on_hsv_press(self,h,s,v):
        """
        Callback to hsv button
        """
        self.hsv = introcs.HSV(h, s, v)
        temp = a2.hsv_to_rgb(self.hsv)
        assert (temp == None or type(temp) == introcs.RGB), \
                'hsv_to_rgb does not return a RGB object'

        self.rgb = self.rgb if temp is None else temp
        self.cmyk = a2.rgb_to_cmyk(self.rgb);
        assert (self.cmyk == None or type(self.cmyk) == introcs.CMYK), \
                'rgb_to_cmyk does not return a CMYK object'
        self.update()
Exemplo n.º 4
0
 def register(self):
     """
     Initializes color values and forces refresh
     """
     active = True
     self.rgb = introcs.RGB(0, 255, 0)
     self.cmyk = a2.rgb_to_cmyk(self.rgb)
     assert (self.cmyk == None or type(self.cmyk) == introcs.CMYK), \
             'rgb_to_cmyk does not return a CMYK object'
     self.hsv = a2.rgb_to_hsv(self.rgb)
     assert (self.hsv == None or type(self.hsv) == introcs.HSV), \
             'rgb_to_hsv does not return a HSV object'
     self.top.register()
     self.update()
Exemplo n.º 5
0
def test_rgb_to_cmyk():
    """
    Test translation function rgb_to_cmyk
    """
    rgb = introcs.RGB(255, 255, 255)
    cmyk = a2.rgb_to_cmyk(rgb)
    introcs.assert_equals('0.000', a2.str5(cmyk.cyan))
    introcs.assert_equals('0.000', a2.str5(cmyk.magenta))
    introcs.assert_equals('0.000', a2.str5(cmyk.yellow))
    introcs.assert_equals('0.000', a2.str5(cmyk.black))

    rgb = introcs.RGB(0, 0, 0)
    cmyk = a2.rgb_to_cmyk(rgb)
    introcs.assert_equals('0.000', a2.str5(cmyk.cyan))
    introcs.assert_equals('0.000', a2.str5(cmyk.magenta))
    introcs.assert_equals('0.000', a2.str5(cmyk.yellow))
    introcs.assert_equals('100.0', a2.str5(cmyk.black))

    rgb = introcs.RGB(217, 43, 164)
    cmyk = a2.rgb_to_cmyk(rgb)
    introcs.assert_equals('0.000', a2.str5(cmyk.cyan))
    introcs.assert_equals('80.18', a2.str5(cmyk.magenta))
    introcs.assert_equals('24.42', a2.str5(cmyk.yellow))
    introcs.assert_equals('14.90', a2.str5(cmyk.black))
Exemplo n.º 6
0
    def on_rgb_slide(self,r,g,b):
        """
        Callback to rgb sliders
        """
        if not self.active:
            return
        red = int(round(r / 100.0))
        green = int(round(g / 100.0))
        blue = int(round(b / 100.0))
        self.rgb = introcs.RGB(red, green, blue)
        self.hsv = a2.rgb_to_hsv(self.rgb)
        assert (self.hsv == None or type(self.hsv) == introcs.HSV), \
                'rgb_to_hsv does not return a HSV object'

        self.cmyk = a2.rgb_to_cmyk(self.rgb)
        assert (self.cmyk == None or type(self.cmyk) == introcs.CMYK), \
                'rgb_to_cmyk does not return a CMYK object'
        self.update()
Exemplo n.º 7
0
    def on_hsv_slide(self,h,s,v):
        """
        Callback to hsv sliders
        """
        if not self.active:
            return
        hue = h / 100.0
        sat = s / 100.0
        val = v / 100.0
        self.hsv = introcs.HSV(hue, sat, val)
        temp = a2.hsv_to_rgb(self.hsv)
        assert (temp == None or type(temp) == introcs.RGB), \
                'hsv_to_rgb does not return a RGB object'

        self.rgb = self.rgb if temp is None else temp
        self.cmyk = a2.rgb_to_cmyk(self.rgb);
        assert (self.cmyk == None or type(self.cmyk) == introcs.CMYK), \
                'rgb_to_cmyk does not return a CMYK object'
        self.update()
Exemplo n.º 8
0
    def update(self, rgb, cmyk, hsv):
        """
        Refreshes the color and text display in the color panels
        """
        compRGB = a2.complement_rgb(rgb)
        if (compRGB is None):
            compRGB = rgb

        rgb_str  = rgb_to_str(rgb)
        cmyk_str = '' if cmyk is None else str5_cmyk(cmyk)
        hsv_str  = '' if hsv is None else str5_hsv(hsv)

        self.main.text = ("ORIGINAL COLOR\n\n"+
                          "Color\nRGB:    " + rgb_str +
                          "\nCMYK: " + cmyk_str +
                          "\nHSV:    " + hsv_str + "\n \n" +
                          "R,G,B sliders in: 0..255\n" +
                          "C,M,Y,K sliders: 0 to 100%\n" +
                          "H slider: 0 <= H < 360 degrees\n" +
                          "S,V sliders: 0 <= S,V <= 1")
        self.main.background = rgb.glColor()
        self.main.foreground = compRGB.glColor()

        if self.menu.text in self.menu.data:
            matrix = self.menu.data[self.menu.text]
        else:
            matrix = self.menu.data['Normal']
        cbrgb = a2.apply_matrix(matrix,rgb)

        rgb_str  = rgb_to_str(cbrgb)
        try:
            cmyk_str = str5_cmyk(a2.rgb_to_cmyk(cbrgb))
            if cmyk_str is None:
                cmyk_str = ''
        except:
            cmyk_str = ''
        try:
            hsv_str = str5_hsv(a2.rgb_to_hsv(cbrgb))
            if hsv_str is None:
                hsv_str = ''
        except:
            hsv_str = ''

        self.comp.text = ("TRANSFORMED COLOR\n\n"+
                          "Color\nRGB:    " + rgb_str +
                          "\nCMYK: " + cmyk_str +
                          "\nHSV:    " + hsv_str + "\n \n" +
                          "R,G,B sliders in: 0..255\n" +
                          "C,M,Y,K sliders: 0 to 100%\n" +
                          "H slider: 0 <= H < 360 degrees\n" +
                          "S,V sliders: 0 <= S,V <= 1" )
        self.comp.background = cbrgb.glColor()
        self.comp.foreground = a2.apply_matrix(matrix,compRGB).glColor()

        # set the sliders
        self.rSlider.value = rgb.red*100
        self.gSlider.value = rgb.green*100
        self.bSlider.value = rgb.blue*100
        self.cSlider.value = 0 if cmyk is None else cmyk.cyan*100
        self.mSlider.value = 0 if cmyk is None else cmyk.magenta*100
        self.ySlider.value = 0 if cmyk is None else cmyk.yellow*100
        self.kSlider.value = 0 if cmyk is None else cmyk.black*100
        self.hSlider.value = 0 if hsv is None else hsv.hue*100
        self.sSlider.value = 0 if hsv is None else hsv.saturation*100
        self.vSlider.value = 0 if hsv is None else hsv.value*100