-
pygame.Color¶ - pygame object for color representationsColor(name) -> ColorColor(r, g, b, a) -> ColorColor(rgbvalue) -> Color
pygame.Color.r — Gets or sets the red value of the Color. pygame.Color.g — Gets or sets the green value of the Color. pygame.Color.b — Gets or sets the blue value of the Color. pygame.Color.a — Gets or sets the alpha value of the Color. pygame.Color.cmy — Gets or sets the CMY representation of the Color. pygame.Color.hsva — Gets or sets the HSVA representation of the Color. pygame.Color.hsla — Gets or sets the HSLA representation of the Color. pygame.Color.i1i2i3 — Gets or sets the I1I2I3 representation of the Color. pygame.Color.normalize — Returns the normalized RGBA values of the Color. pygame.Color.correct_gamma — Applies a certain gamma value to the Color. pygame.Color.set_length — Set the number of elements in the Color to 1,2,3, or 4. The Color class represents
RGBAcolor values using a value range of 0-255. It allows basic arithmetic operations — binary operations+,-,*,//,%, and unary operation~— to create new colors, supports conversions to other color spaces such asHSVorHSLand lets you adjust single color channels. Alpha defaults to 255 when not given. The arithmetic operations andcorrect_gamma()method preserve subclasses. For the binary operators, the class of the returned color is that of the left hand color object of the operator.'rgbvalue' can be either a color name, an
HTMLcolor format string, a hex number string, or an integer pixel value. TheHTMLformat is '#rrggbbaa', where rr, gg, bb, and aa are 2-character 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.
The floor division,
//, and modulus,%, operators do not raise an exception for division by zero. Instead, if a color, or alpha, channel in the right hand color is 0, then the result is 0. For example:# These expressions are True Color(255, 255, 255, 255) // Color(0, 64, 64, 64) == Color(0, 3, 3, 3) Color(255, 255, 255, 255) % Color(64, 64, 64, 0) == Color(63, 63, 63, 0)
New implementation of Color was done in pygame 1.8.1.
-
r¶ - Gets or sets the red value of the Color.r -> int
The red value of the Color.
-
g¶ - Gets or sets the green value of the Color.g -> int
The green value of the Color.
-
b¶ - Gets or sets the blue value of the Color.b -> int
The blue value of the Color.
-
a¶ - Gets or sets the alpha value of the Color.a -> int
The alpha value of the Color.
-
cmy¶ - Gets or sets the CMY representation of the Color.cmy -> tuple
The
CMYrepresentation of the Color. TheCMYcomponents are in the rangesC= [0, 1],M= [0, 1],Y= [0, 1]. Note that this will not return the absolutely exactCMYvalues for the setRGBvalues in all cases. Due to theRGBmapping from 0-255 and theCMYmapping from 0-1 rounding errors may cause theCMYvalues to differ slightly from what you might expect.
-
hsva¶ - Gets or sets the HSVA representation of the Color.hsva -> tuple
The
HSVArepresentation of the Color. TheHSVAcomponents are in the rangesH= [0, 360],S= [0, 100],V= [0, 100], A = [0, 100]. Note that this will not return the absolutely exactHSVvalues for the setRGBvalues in all cases. Due to theRGBmapping from 0-255 and theHSVmapping from 0-100 and 0-360 rounding errors may cause theHSVvalues to differ slightly from what you might expect.
-
hsla¶ - Gets or sets the HSLA representation of the Color.hsla -> tuple
The
HSLArepresentation of the Color. TheHSLAcomponents are in the rangesH= [0, 360],S= [0, 100],V= [0, 100], A = [0, 100]. Note that this will not return the absolutely exactHSLvalues for the setRGBvalues in all cases. Due to theRGBmapping from 0-255 and theHSLmapping from 0-100 and 0-360 rounding errors may cause theHSLvalues to differ slightly from what you might expect.
-
i1i2i3¶ - Gets or sets the I1I2I3 representation of the Color.i1i2i3 -> tuple
The
I1I2I3representation of the Color. TheI1I2I3components are in the rangesI1= [0, 1],I2= [-0.5, 0.5],I3= [-0.5, 0.5]. Note that this will not return the absolutely exactI1I2I3values for the setRGBvalues in all cases. Due to theRGBmapping from 0-255 and theI1I2I3mapping from 0-1 rounding errors may cause theI1I2I3values to differ slightly from what you might expect.
-
normalize()¶ - Returns the normalized RGBA values of the Color.normalize() -> tuple
Returns the normalized
RGBAvalues of the Color as floating point values.
-
correct_gamma()¶ - Applies a certain gamma value to the Color.correct_gamma (gamma) -> Color
Applies a certain gamma value to the Color and returns a new Color with the adjusted
RGBAvalues.
-
set_length()¶ - Set the number of elements in the Color to 1,2,3, or 4.set_length(len) -> None
The default Color length is 4. Colors can have lengths 1,2,3 or 4. This is useful if you want to unpack to r,g,b and not r,g,b,a. If you want to get the length of a Color do
len(acolor).New in pygame 1.9.0.
-