コード例 #1
0
def test_luminance():
    black = luminance((0, 0, 0))
    blue = luminance((0, 0, 255))
    red = luminance((255, 0, 0))
    green = luminance((0, 255, 0))
    yellow = luminance((255, 255, 0))
    cyan = luminance((0, 255, 255))
    magenta = luminance((255, 0, 255))
    white = luminance((255, 255, 255))

    assert black == 0.0
    assert white == 1.0
    assert black < blue < red < magenta < green < cyan < yellow < white
コード例 #2
0
def is_dark_color(color: Color, dark: float = 0.2) -> bool:
    luma = luminance(hex_to_rgb(color))
    return luma <= dark
コード例 #3
0
 def luminance(self) -> float:
     """ Returns perceived color luminance in range [0, 1] from dark to light.
     """
     return luminance(self.rgb)