Class RGB¶
This class represents a RGB color value.
Constructor¶
-
RGB(r, g, b, a=255)¶ Constructor: creates a new RGB value (r,g,b,a).
Parameter: r – initial red value Precondition: int between 0 and 255, inclusive.
Parameter: g – initial green value Precondition: int between 0 and 255, inclusive.
Parameter: b – initial blue value Precondition: int between 0 and 255, inclusive.
Parameter: a – initial alpha value (default 255) Precondition: int between 0 and 255, inclusive.
The alpha channel is 255 by default, unless otherwise specified.
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: a 4 element list of the attributes in the range 0 to 1
This is a conversion of this object into a format that can be used in openGL graphics
-
tkColor()¶ Returns: a 3 element tuple of the attributes in the range 0 to 1
This is a conversion of this object into a format that can be used by Tkinter (e.g. the drawing turtle).
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.
Parameter: name – the color name Precondition: name is a valid tkinter color name
-
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.
Parameter: color – the web color Precondition: color is a valid web color string