Beispiel #1
0
    def test_color(self):
        """Test color constructor on happy path"""
        temp_rgb = Color(Color.RGB, 0, 255, 0)
        temp_hls = Color(Color.HLS, 0, 1, 1)

        self.assertIsInstance(temp_rgb, Color)
        self.assertIsInstance(temp_hls, Color)
    def _calculate_shade_of_triangle(tri: Triangle) -> Color:
        """
        Calculate the shade of a color based on triangles angle to light

        Using color in HLS color space we can manipulate the illumination
        """
        dot_value = tri.angle_to_light
        base_color = Color(Color.RGB, 0, 255, 0)  # Use Green for now

        # Change illumination of triangle based on angle
        color_hls_form = base_color.to_hls()
        color_hls_form[1] *= dot_value

        shade_of_triangle = Color(Color.HLS, *color_hls_form)

        return shade_of_triangle
Beispiel #3
0
    def test_to_hex(self):
        """Test conversion to hex"""
        green_as_rgb = Color(Color.RGB, 0, 255, 0)
        self.assertEqual("#00ff00", green_as_rgb.to_hex())

        green_as_hls = Color(Color.HLS, *green_as_rgb.to_hls())
        self.assertEqual("#00ff00", green_as_hls.to_hex())
Beispiel #4
0
    def test_hls_to_rgb(self):
        """Test hls conversion to rgb"""
        green_as_hls = Color(Color.HLS, 120, 0.5, 1.0)
        self.assertEqual([0, 255, 0], green_as_hls.to_rgb())

        red_as_hls = Color(Color.HLS, 0, 0.5, 1.0)
        self.assertEqual([255, 0, 0], red_as_hls.to_rgb())

        black_as_hls = Color(Color.HLS, 360, 0, 0)
        self.assertEqual([0, 0, 0], black_as_hls.to_rgb())

        black_as_hls_2 = Color(Color.HLS, 34, 0, 0)
        self.assertEqual([0, 0, 0], black_as_hls_2.to_rgb())

        white_as_hls = Color(Color.HLS, 357, 1, 0.21)
        self.assertEqual([255, 255, 255], white_as_hls.to_rgb())
Beispiel #5
0
 def test_rgb_to_hls(self):
     """Test green rgb conversion to hls"""
     green_as_rgb = Color(Color.RGB, 0, 255, 0)
     self.assertEqual([120, 0.5, 1.0], green_as_rgb.to_hls())
Beispiel #6
0
 def test_raises_hue_wrong_value(self):
     """Test constructor raises if Hue beyond range[0, 360]"""
     with self.assertRaises(ValueError):
         Color(Color.HLS, -2, 0, 0)
         Color(Color.HLS, 361, 0, 0)
Beispiel #7
0
 def test_raises_rgb_beyond_range(self):
     """Test constructor raises if RGB values beyond range[0,255]"""
     with self.assertRaises(ValueError):
         Color(Color.RGB, 0, 0, -1)
         Color(Color.RGB, 0, 0, 256)
Beispiel #8
0
 def test_raises_wrong_space(self):
     """Test constructor raises if wrong color space used"""
     with self.assertRaises(ValueError):
         Color("wrong value", 0, 0, 0)
Beispiel #9
0
 def test_raises_args_length(self):
     """Test constructor raises if there aren't 3 values"""
     with self.assertRaises(ValueError):
         Color(Color.RGB, 0)