예제 #1
0
    def test_pygame2_base_Color_a(self):

        # __doc__ (as of 2008-10-17) for pygame2.base.Color.a:

        # Gets or sets the alpha value of the Color.
        c = Color (100, 100, 100)
        self.assertEqual (c.a, 255)
        
        c = Color (100, 100, 100, 100)
        self.assertEqual (c.a, 100)
        
        c = Color (100, 100, 100)
        self.assertEqual (c.a, 255)
        c.a = 200
        self.assertEqual (c.a, 200)
        c.a += 22
        self.assertEqual (c.a, 222)
        
        c = Color (0xAABBCCDD)
        self.assertEqual (c.a, 0xAA)
        
        c = Color ("0xBBCCDD")
        self.assertEqual (c.a, 0xFF)
        c = Color ("0xAABBCCDD")
        self.assertEqual (c.a, 0xDD)
        
        c = Color ("#AABBCCDD")
        self.assertEqual (c.a, 0xDD)
        c = Color ("#BBCCDD")
        self.assertEqual (c.a, 0xFF)
        
        c = Color ("red")
        self.assertEqual (c.a, 255)
예제 #2
0
    def test_rgba (self):
        c = Color (0)
        self.assertEqual (c.r, 0)
        self.assertEqual (c.g, 0)
        self.assertEqual (c.b, 0)
        self.assertEqual (c.a, 0)

        # Test simple assignments
        c.r = 123
        self.assertEqual (c.r, 123)
        self.assertRaises (ValueError, _assignr, c, 537)
        self.assertEqual (c.r, 123)
        self.assertRaises (ValueError, _assignr, c, -3)
        self.assertEqual (c.r, 123)

        c.g = 55
        self.assertEqual (c.g, 55)
        self.assertRaises (ValueError, _assigng, c, 348)
        self.assertEqual (c.g, 55)
        self.assertRaises (ValueError, _assigng, c, -44)
        self.assertEqual (c.g, 55)

        c.b = 77
        self.assertEqual (c.b, 77)
        self.assertRaises (ValueError, _assignb, c, 256)
        self.assertEqual (c.b, 77)
        self.assertRaises (ValueError, _assignb, c, -12)
        self.assertEqual (c.b, 77)

        c.a = 255
        self.assertEqual (c.a, 255)
        self.assertRaises (ValueError, _assigna, c, 312)
        self.assertEqual (c.a, 255)
        self.assertRaises (ValueError, _assigna, c, -10)
        self.assertEqual (c.a, 255)
예제 #3
0
    def test_normalize (self):
        c = Color (204, 38, 194, 55)
        self.assertEqual (c.r, 204)
        self.assertEqual (c.g, 38)
        self.assertEqual (c.b, 194)
        self.assertEqual (c.a, 55)

        t = c.normalize ()

        self.assertAlmostEqual (t[0], 0.800000, places=5)
        self.assertAlmostEqual (t[1], 0.149016, places=5)
        self.assertAlmostEqual (t[2], 0.760784, places=5)
        self.assertAlmostEqual (t[3], 0.215686, places=5)
예제 #4
0
    def test_pygame2_base_Color_normalize(self):

        # __doc__ (as of 2008-10-17) for pygame2.base.Color.normalize:

        # Color.normalize() -> tuple
        # 
        # Returns the normalized RGBA values of the Color.
        # 
        # Returns the normalized RGBA values of the Color as floating
        # point values.
        c = Color (255, 255, 255, 255)
        self.assertEqual (c.normalize (), (1.0, 1.0, 1.0, 1.0))
        c = Color (0, 0, 0, 0)
        self.assertEqual (c.normalize (), (0.0, 0.0, 0.0, 0.0))
        c = Color (128, 128, 128, 128)
        t = c.normalize ()
        for v in t:
            self.assertAlmostEqual (v, 0.5, places=2)

        c = Color (128, 255, 0, 52)
        t = c.normalize ()
        self.assertAlmostEqual (t[0], 0.5, places=2)
        self.assertEqual (t[1], 1.0)
        self.assertEqual (t[2], 0.0)
        # 52 / 255 ~= .20
        self.assertAlmostEqual (t[3], 0.2, places=2)
예제 #5
0
    def test_pygame2_base_Color_r(self):

        # __doc__ (as of 2008-10-17) for pygame2.base.Color.r:

        # Gets or sets the red value of the Color.
        
        c = Color (100, 100, 100)
        self.assertEqual (c.r, 100)
        
        c = Color (100, 100, 100, 100)
        self.assertEqual (c.r, 100)
        
        c = Color (100, 100, 100)
        self.assertEqual (c.r, 100)
        c.r = 200
        self.assertEqual (c.r, 200)
        c.r += 22
        self.assertEqual (c.r, 222)
        
        c = Color (0xAABBCCDD)
        self.assertEqual (c.r, 0xBB)
        
        c = Color ("0xBBCCDD")
        self.assertEqual (c.r, 0xBB)
        c = Color ("0xAABBCCDD")
        self.assertEqual (c.r, 0xAA)
        
        c = Color ("#AABBCCDD")
        self.assertEqual (c.r, 0xAA)
        c = Color ("#BBCCDD")
        self.assertEqual (c.r, 0xBB)
        
        c = Color ("red")
        self.assertEqual (c.r, 255)
        c = Color ("blue")
        self.assertEqual (c.r, 0)
예제 #6
0
    def test_pygame2_base_Color_g(self):

        # __doc__ (as of 2008-10-17) for pygame2.base.Color.g:

        # Gets or sets the green value of the Color.

        c = Color (100, 100, 100)
        self.assertEqual (c.g, 100)
        
        c = Color (100, 100, 100, 100)
        self.assertEqual (c.g, 100)
        
        c = Color (100, 100, 100)
        self.assertEqual (c.g, 100)
        c.g = 200
        self.assertEqual (c.g, 200)
        c.g += 22
        self.assertEqual (c.g, 222)
        
        c = Color (0xAABBCCDD)
        self.assertEqual (c.g, 0xCC)
        
        c = Color ("0xBBCCDD")
        self.assertEqual (c.g, 0xCC)
        c = Color ("0xAABBCCDD")
        self.assertEqual (c.g, 0xBB)
        
        c = Color ("#AABBCCDD")
        self.assertEqual (c.g, 0xBB)
        c = Color ("#BBCCDD")
        self.assertEqual (c.g, 0xCC)
        
        c = Color ("red")
        self.assertEqual (c.g, 0)
        c = Color ("green")
        self.assertEqual (c.g, 255)
예제 #7
0
    def test_pygame2_base_Color_b(self):

        # __doc__ (as of 2008-10-17) for pygame2.base.Color.b:

        # Gets or sets the blue value of the Color.
        c = Color (100, 100, 100)
        self.assertEqual (c.b, 100)
        
        c = Color (100, 100, 100, 100)
        self.assertEqual (c.b, 100)
        
        c = Color (100, 100, 100)
        self.assertEqual (c.b, 100)
        c.b = 200
        self.assertEqual (c.b, 200)
        c.b += 22
        self.assertEqual (c.b, 222)
        
        c = Color (0xAABBCCDD)
        self.assertEqual (c.b, 0xDD)
        
        c = Color ("0xBBCCDD")
        self.assertEqual (c.b, 0xDD)
        c = Color ("0xAABBCCDD")
        self.assertEqual (c.b, 0xCC)
        
        c = Color ("#AABBCCDD")
        self.assertEqual (c.b, 0xCC)
        c = Color ("#BBCCDD")
        self.assertEqual (c.b, 0xDD)
        
        c = Color ("red")
        self.assertEqual (c.b, 0)
        c = Color ("blue")
        self.assertEqual (c.b, 255)