pygame / docs / reST / ref / color.rst


The Color class represents RGBA color values using a value range of 0-255. It allows basic arithmetic operations to create new colors, supports conversions to other color spaces such as HSV or HSL and lets you adjust single color channels. Alpha defaults to 255 when not given.

'rgbvalue' can be either a color name, an HTML color format string, a hex number string, or an integer pixel value. The HTML format is '#rrggbbaa', where rr, gg, bb, and aa are 2 digit hex numbers. The alpha aa is optional. A hex number string has the form '0xrrggbbaa', where aa is optional.

Color objects support equality comparison with other color objects and 3 or 4 element tuples of integers (New in 1.9.0). There was a bug in pygame 1.8.1 where the default alpha was 0, not 255 like previously.

Color objects export the C level array interface. The interface exports a read-only one dimensional unsigned byte array of the same assigned length as the color. For CPython 2.6 and later, the new buffer interface is also exported, with the same characteristics as the array interface. New in pygame 1.9.2.

New implementation of Color was done in pygame 1.8.1.