示例#1
0
 def test_hsl(self):
     for hsl, expected_rgb in [
             # http://en.wikipedia.org/wiki/HSL_and_HSV#Examples
         ((0, 0, 100), (1, 1, 1)),
         ((127, 0, 100), (1, 1, 1)),
         ((0, 0, 50), (0.5, 0.5, 0.5)),
         ((127, 0, 50), (0.5, 0.5, 0.5)),
         ((0, 0, 0), (0, 0, 0)),
         ((127, 0, 0), (0, 0, 0)),
         ((0, 100, 50), (1, 0, 0)),
         ((60, 100, 37.5), (0.75, 0.75, 0)),
         ((780, 100, 37.5), (0.75, 0.75, 0)),
         ((-300, 100, 37.5), (0.75, 0.75, 0)),
         ((120, 100, 25), (0, 0.5, 0)),
         ((180, 100, 75), (0.5, 1, 1)),
         ((240, 100, 75), (0.5, 0.5, 1)),
         ((300, 50, 50), (0.75, 0.25, 0.75)),
         ((61.8, 63.8, 39.3), (0.628, 0.643, 0.142)),
         ((251.1, 83.2, 51.1), (0.255, 0.104, 0.918)),
         ((134.9, 70.7, 39.6), (0.116, 0.675, 0.255)),
         ((49.5, 89.3, 49.7), (0.941, 0.785, 0.053)),
         ((283.7, 77.5, 54.2), (0.704, 0.187, 0.897)),
         ((14.3, 81.7, 62.4), (0.931, 0.463, 0.316)),
         ((56.9, 99.1, 76.5), (0.998, 0.974, 0.532)),
         ((162.4, 77.9, 44.7), (0.099, 0.795, 0.591)),
         ((248.3, 60.1, 37.3), (0.211, 0.149, 0.597)),
         ((240.5, 29, 60.7), (0.495, 0.493, 0.721)),
     ]:
         for got, expected in zip(hsl_to_rgb(*hsl), expected_rgb):
             # Compensate for floating point errors and Wikipedia’s rounding:
             self.assertLess(abs(got - expected), 0.001)
示例#2
0
文件: color3.py 项目: AEliu/calibre
 def test_hsl(self):
     for hsl, expected_rgb in [
         # http://en.wikipedia.org/wiki/HSL_and_HSV#Examples
         ((0,     0,    100), (1,     1,     1)),
         ((127,   0,    100), (1,     1,     1)),
         ((0,     0,    50), (0.5,   0.5,   0.5)),
         ((127,   0,    50), (0.5,   0.5,   0.5)),
         ((0,     0,    0), (0,     0,     0)),
         ((127,   0,    0), (0,     0,     0)),
         ((0,     100,  50), (1,     0,     0)),
         ((60,    100,  37.5), (0.75,  0.75,  0)),
         ((780,   100,  37.5), (0.75,  0.75,  0)),
         ((-300,  100,  37.5), (0.75,  0.75,  0)),
         ((120,   100,  25), (0,     0.5,   0)),
         ((180,   100,  75), (0.5,   1,     1)),
         ((240,   100,  75), (0.5,   0.5,   1)),
         ((300,   50,   50), (0.75,  0.25,  0.75)),
         ((61.8,  63.8, 39.3), (0.628, 0.643, 0.142)),
         ((251.1, 83.2, 51.1), (0.255, 0.104, 0.918)),
         ((134.9, 70.7, 39.6), (0.116, 0.675, 0.255)),
         ((49.5,  89.3, 49.7), (0.941, 0.785, 0.053)),
         ((283.7, 77.5, 54.2), (0.704, 0.187, 0.897)),
         ((14.3,  81.7, 62.4), (0.931, 0.463, 0.316)),
         ((56.9,  99.1, 76.5), (0.998, 0.974, 0.532)),
         ((162.4, 77.9, 44.7), (0.099, 0.795, 0.591)),
         ((248.3, 60.1, 37.3), (0.211, 0.149, 0.597)),
         ((240.5, 29,   60.7), (0.495, 0.493, 0.721)),
     ]:
         for got, expected in zip(hsl_to_rgb(*hsl), expected_rgb):
             # Compensate for floating point errors and Wikipedia’s rounding:
             self.assertLess(abs(got - expected), 0.001)
示例#3
0
def test_hsl(hsl, expected_rgb):
    for got, expected in zip(hsl_to_rgb(*hsl), expected_rgb):
        # Compensate for floating point errors and Wikipedia’s rounding:
        assert abs(got - expected) < 0.001