コード例 #1
0
ファイル: colour.py プロジェクト: andrewsilke/zoocore
 def apply(self, r, g, b):
     rx = r * self.matrix[0][0] + g * self.matrix[0][1] + b * self.matrix[
         0][2]
     gx = r * self.matrix[1][0] + g * self.matrix[1][1] + b * self.matrix[
         1][2]
     bx = r * self.matrix[2][0] + g * self.matrix[2][1] + b * self.matrix[
         2][2]
     return zoomath.clamp(rx, 0, 255), zoomath.clamp(gx, 0,
                                                     255), zoomath.clamp(
                                                         bx, 0, 255)
コード例 #2
0
ファイル: colour.py プロジェクト: keenfoong/zoocore
def offsetColor(col, offset=0):
    """Returns a color with the offset in tuple form.

    :param col: Color in form of tuple with 3 ints. eg tuple(255,255,255)
    :type col: tuple(int,int,int)
    :param offset: The int to offset the color
    :return: tuple (int,int,int)
    """
    return tuple([zoomath.clamp((c + offset), 0, 255) for c in col])
コード例 #3
0
ファイル: colour.py プロジェクト: andrewsilke/zoocore
def hslColourOffsetFloat(rgb,
                         hueOffset=0,
                         saturationOffset=0,
                         lightnessOffset=0):
    """Offset color with hue, saturation and lightness (brighten/darken) values

    Colour is expected as rgb  in 0.0-1.0 float range eg (0.1, 0.34, 1.0)
    Offsets are in...
        hue: 0-360,
        saturation: 0.0-1.0,
        value (lightness): 0.0-1.0
    Returned colour is rgb in in 0-1.0 range eg (0.1, 0.34, 1.0)

    :param rgb: the rgb color in 0.0-0.1 range eg (0.1, 0.34, 1.0)
    :type rgb: tuple
    :param hueOffset: the hue offset in 0-360 range
    :type hueOffset: float
    :param saturationOffset: the saturation offset in 0-255 range
    :type saturationOffset: float
    :param lightnessOffset: the lightness value offset, lighten (0.2) or darken (-0.3), 0-0.1 range as an offset
    :type lightnessOffset: float
    :return rgb: the changed rgb color in 0.0-0.1 range eg (0.1, 0.34, 1.0)
    :rtype: rgb: tuple
    """
    if hueOffset:
        hsv = convertRgbToHsv(list(rgb))
        newHue = hsv[0] + hueOffset
        if newHue > 360.0:
            newHue -= 360.0
        elif newHue < 360.0:
            newHue += 360.0
        hsv = (newHue, hsv[1], hsv[2])
        rgb = convertHsvToRgb(list(hsv))
    if saturationOffset:
        hsv = convertRgbToHsv(rgb)
        saturationOffset = saturationOffset
        hsv = (hsv[0], zoomath.clamp(hsv[1] + saturationOffset), hsv[2])
        rgb = convertHsvToRgb(list(hsv))
    if lightnessOffset:
        rgb = (zoomath.clamp(rgb[0] + lightnessOffset),
               zoomath.clamp(rgb[1] + lightnessOffset),
               zoomath.clamp(rgb[2] + lightnessOffset))
    return rgb