Class RGB

This class represents a RGB color value.

Constructor

RGB(r, g, b, a=255)

Creates a new RGB value (r,g,b,a).

All color value ranges are inclusive. So 255 is a valid red value, but 256 is not.

Returns:

a new RGB value (r,g,b,a).

Parameter:
  • r (``int` 0..255) – initial red value
  • g (``int` 0..255) – initial green value
  • b (``int` 0..255) – initial blue value
  • a (``int` 0..255) – initial alpha value (default 255)

Attributes

red

The red channel.

invariant: Value must be an int between 0 and 255, inclusive.

green

The green channel.

invariant: Value must be an int between 0 and 255, inclusive.

blue

The blue channel.

invariant: Value must be an int between 0 and 255, inclusive.

alpha

The alpha channel.

Used for transparency effects (but not in this course).

invariant: Value must be an int between 0 and 255, inclusive.

Methods

glColor()

Returns an OpenGL version of this color.

This conversion allows this object to be used by graphics libraries that depend on OpenGL (e.g. Kivy)

Returns:a 4 element list of the attributes in the range 0 to 1
Return type:list
tkColor()

Returns an Tkinter version of this color.

This conversion allows this object to be used by graphics libraries that depend on Tkinter (e.g. the drawing turtle).

Returns:a 3 element list of the attributes in the range 0 to 1
Return type:tuple

Class Methods

Class methods are methods that are called with the class name before the period, instead of an object. They provide alternate constructors.

CreateName(name)

Creates a new RGB object with the given color name.

Color name conversion is handled by the standard RGB color space. If the color is not valid, this method will fire an assert.

Parameter:name (str) – the color name
Raise:ValueError if name is not a valid color name.
Returns:a new RGB value
CreateWebColor(color)

Creates a new RGB object from the given web color string.

A web color string is a 6-digit hexadecimal string starting with a hashtag (#). It does not include an alpha value. If the string is not , this method will fire an assert.

Parameter:color (hexadecimal str) – the web color
Returns:a new RGB value

Return to top level