Class RGB

This class represents a RGB color value.

Constructor

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

Constructor: creates a new RGB value (r,g,b,a).

The alpha channel is 255 by default, unless otherwise specified.

Parameter:
  • r (int between 0 and 255, inclusive) – the initial red value
  • g (int between 0 and 255, inclusive.) – the initial green value
  • b (int between 0 and 255, inclusive.) – initial blue value
  • a (int between 0 and 255, inclusive.) – 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: The 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.

RGB.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 (str naming a valid tkinter color) – the color name
RGB.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:
  • name (str naming a valid web color) – the color name