color - Pygame Documentation

pygame documentation | || Pygame Home || Help Contents || Reference Index || Cdrom || Color || Cursors || Display || Draw || Event || Font || Image || Joystick || Key || Mask || Mixer || Mouse || Movie || Music || Overlay || Pixelarray || Pygame || Rect || Scrap || Sndarray || Sprite || Surface || Surfarray || Time || Transform

pygame.Color

pygame object for color representations
`pygame.Color(name): Return Color`
`pygame.Color(r, g, b, a): Return Color`
`pygame.Color(rgbvalue): Return Color`

Color.r - Gets or sets the red value of the Color. | Gets or sets the red value of the Color.
Color.g - Gets or sets the green value of the Color. | Gets or sets the green value of the Color.
Color.b - Gets or sets the blue value of the Color. | Gets or sets the blue value of the Color.
Color.a - Gets or sets the alpha value of the Color. | Gets or sets the alpha value of the Color.
Color.cmy - Gets or sets the CMY representation of the Color. | Gets or sets the CMY representation of the Color.
Color.hsva - Gets or sets the HSVA representation of the Color. | Gets or sets the HSVA representation of the Color.
Color.hsla - Gets or sets the HSLA representation of the Color. | Gets or sets the HSLA representation of the Color.
Color.i1i2i3 - Gets or sets the I1I2I3 representation of the Color. | Gets or sets the I1I2I3 representation of the Color.
Color.normalize - Returns the normalized RGBA values of the Color. | Returns the normalized RGBA values of the Color.
Color.correct_gamma - Applies a certain gamma value to the Color. | Applies a certain gamma value to the Color.

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.

New in pygame `1.8.1`.

Color.r

Gets or sets the red value of the Color.
`Color.r: Return int`

The red value of the Color.

Color.g

Gets or sets the green value of the Color.
`Color.g: Return int`

The green value of the Color.

Color.b

Gets or sets the blue value of the Color.
`Color.b: Return int`

The blue value of the Color.

Color.a

Gets or sets the alpha value of the Color.
`Color.a: Return int`

The alpha value of the Color.

Color.cmy

Gets or sets the CMY representation of the Color.
`Color.cmy: Return tuple`

The `CMY` representation of the Color. The `CMY` components are in the ranges `C` = [0, 1], `M` = [0, 1], `Y` = [0, 1]. Note that this will not return the absolutely exact `CMY` values for the set `RGB` values in all cases. Due to the `RGB` mapping from 0-255 and the `CMY` mapping from 0-1 rounding errors may cause the `CMY` values to differ slightly from what you might expect.

Color.hsva

Gets or sets the HSVA representation of the Color.
`Color.hsva: Return tuple`

The `HSVA` representation of the Color. The `HSVA` components are in the ranges `H` = [0, 360], `S` = [0, 100], `V` = [0, 100], `A` = [0, 100]. Note that this will not return the absolutely exact `HSV` values for the set `RGB` values in all cases. Due to the `RGB` mapping from 0-255 and the `HSV` mapping from 0-100 and 0-360 rounding errors may cause the `HSV` values to differ slightly from what you might expect.

Color.hsla

Gets or sets the HSLA representation of the Color.
`Color.hsla: Return tuple`

The `HSLA` representation of the Color. The `HSLA` components are in the ranges `H` = [0, 360], `S` = [0, 100], `V` = [0, 100], `A` = [0, 100]. Note that this will not return the absolutely exact `HSL` values for the set `RGB` values in all cases. Due to the `RGB` mapping from 0-255 and the `HSL` mapping from 0-100 and 0-360 rounding errors may cause the `HSL` values to differ slightly from what you might expect.

Color.i1i2i3

Gets or sets the I1I2I3 representation of the Color.
`Color.i1i2i3: Return tuple`

The `I1I2I3` representation of the Color. The `I1I2I3` components are in the ranges `I1` = [0, 1], `I2` = `[-0.5`, `0.5]`, `I3` = `[-0.5`, `0.5]`. Note that this will not return the absolutely exact `I1I2I3` values for the set `RGB` values in all cases. Due to the `RGB` mapping from 0-255 and the `I1I2I3` mapping from 0-1 rounding errors may cause the `I1I2I3` values to differ slightly from what you might expect.

Color.normalize

Returns the normalized RGBA values of the Color.
`Color.normalize(): Return tuple`

Returns the normalized `RGBA` values of the Color as floating point values.

Color.correct_gamma

Applies a certain gamma value to the Color.
`Color.correct_gamma (gamma): Return Color`

Applies a certain gamma value to the Color and returns a new Color with the adjusted `RGBA` values.