def get(self):
        """Return selected color with format (RGB, HSV, HEX)."""
        x = self.coords('cross_v')[0]
        y = self.coords('cross_h')[1]
        xp = min(x, self.bg.width() - 1)
        yp = min(y, self.bg.height() - 1)
        height = self.bg.height()
        width = self.bg.width()
        radius = min(height, width) / 2.0
        centre = height / 2, width / 2

        rx = x - centre[0]
        ry = y - centre[1]

        v = self.get_hue()
        x2 = rx * rx
        y2 = ry * ry

        s = int((math.sqrt(x2 + y2) / radius) * 100)
        #s = ((x - centre[0])**2.0 + (y - centre[1])**2.0)**0.5 / radius
        if s > 100:
            s = 100

        h = int(180 * ((math.atan2(ry, rx) / math.pi) + 1.0))

        h = self._correct_hue_for_disp(h)

        r, g, b = hsv_to_rgb(h, s, v)

        hexa = rgb_to_hexa(r, g, b)

        return (r, g, b), (h, s, v), hexa
    def get(self):
        """Return selected color with format (RGB, HSV, HEX)."""
        x = self.coords('cross_v')[0]
        y = self.coords('cross_h')[1]
        xp = min(x, self.bg.width() - 1)
        yp = min(y, self.bg.height() - 1)

        h = self.get_hue()
        s = round2((1 - float(y) / self.winfo_height()) * 100)
        v = round2(100 * float(x) / self.winfo_width())

        r, g, b = hsv_to_rgb(h, s, v)
        hexa = rgb_to_hexa(r, g, b)
        return (r, g, b), (h, s, v), hexa
 def _update_color_hsv(self, event=None):
     """Update display after a change in the HSV spinboxes."""
     if event is None or event.widget.old_value != event.widget.get():
         h = self.hue.get()
         s = self.saturation.get()
         v = self.value.get()
         sel_color = hsv_to_rgb(h, s, v)
         self.red.set(sel_color[0])
         self.green.set(sel_color[1])
         self.blue.set(sel_color[2])
         hexa = rgb_to_hexa(*sel_color)
         self.hexa.delete(0, "end")
         self.hexa.insert(0, hexa)
         self.square.set_hsv((h, s, v))
         self.bar.set(h)
         self._update_preview()
    def _fill(self):
        """Create the gradient."""
        r, g, b = hue2col(self._hue)
        width = self.winfo_width()
        height = self.winfo_height()
        h = float(height - 1)
        w = float(width - 1)

        if height:
            data = []
            brightness = int(self._hue)  #int(self._hue/255*100)

            radius = min(height, width) / 2.0
            centre = height / 2, width / 2
            crf = COLORCOR_MAX / self.cr
            cgf = COLORCOR_MAX / self.cg
            cbf = COLORCOR_MAX / self.cb
            for y in range(height):
                line = []
                ry = y - centre[1]
                y2 = ry * ry
                for x in range(width):
                    rx = x - centre[0]
                    x2 = rx * rx

                    s = int((math.sqrt(x2 + y2) / radius) * 100)
                    #                   s = ((x2 + (y - centre[1])**2.0)**0.5 / radius
                    if s <= 100:
                        h = int(((math.atan2(ry, rx) / math.pi) + 1.0) * 180)

                        h = self._correct_hue_for_disp(h)

                        rxy, gxy, bxy = hsv_to_rgb(h, s, 100)
                        rxy = int(rxy * crf)
                        gxy = int(gxy * cgf)
                        bxy = int(bxy * cbf)
                        if rxy > 255: rxy = 255
                        if gxy > 255: gxy = 255
                        if bxy > 255: bxy = 255
                        color = rgb_to_hexa(rxy, gxy, bxy)
                    else:
                        color = rgb_to_hexa(255, 255, 255)
                    line.append(color)

                data.append("{" + " ".join(line) + "}")
            self.bg.put(" ".join(data))
 def keycolor_to_dispcolor(self, keycolor):
     r,g,b = hexa_to_rgb(keycolor)
     args = (r,g,b)
     h,s,v = rgb_to_hsv(*args)
     r2,g2,b2 = self._correct_rgb_disp(*args)
     #---  palette colors will be displayed with brightness = 100
     args2 = (r2,g2,b2)
     h2,s2,v2 = rgb_to_hsv(*args2)
     r3,g3,b3 = hsv_to_rgb(h2,s2,100)
     args3 = (r3,g3,b3)
     disp_color = rgb_to_hexa(*args3)
     if PERCENT_BRIGHTNESS:                                           # 03.12.19:
         brightness = str(v) + " %"
     else:
         brightness = ""
         v3 = v/10
         for j in range(10):
             if j<v3:
                 brightness = brightness + ">"
     return disp_color, brightness
Example #6
0
    def get(self):
        """Return selected color with format (RGB, HSV, HEX)."""
        x = self.coords('cross_v')[0]
        y = self.coords('cross_h')[1]
        xp = min(x, self.bg.width() - 1)
        yp = min(y, self.bg.height() - 1)
        try:
            r, g, b = self.bg.get(round2(xp), round2(yp))
        except ValueError:
            r, g, b = self.bg.get(round2(xp), round2(yp)).split()
            r, g, b = int(r), int(g), int(b)

        h, s, v = rgb_to_hsv(r, g, b)

        height = self.bg.height()
        width = self.bg.width()
        radius = min(height, width) / 2.0
        centre = height / 2, width / 2

        rx = x - centre[0]
        ry = y - centre[1]

        v = self.get_hue()

        s = ((x - centre[0])**2.0 + (y - centre[1])**2.0)**0.5 / radius
        if s > 1.0:
            s = 100
        else:
            s = int(s * 100)

        h = int(360 * ((math.atan2(ry, rx) / math.pi) + 1.0) / 2.0)

        r, g, b = hsv_to_rgb(h, s, v)

        hexa = rgb_to_hexa(r, g, b)

        #        r, g, b = hsv_to_rgb(h, s, v)
        #        s = round2((1 - float(y) / self.winfo_height()) * 100)
        #        v = round2(100 * float(x) / self.winfo_width())
        return (r, g, b), (h, s, v), hexa
Example #7
0
 def test_hsv_to_rgb(self):
     self.assertEqual(tkf.hsv_to_rgb(0, 100, 100), (255, 0, 0))