scallop dome pyformex logo

Previous topic

5. draw — Create 3D graphical representations.

Next topic

7. geometry — A generic interface to the Coords transformation methods

[FSF Associate Member]

Valid XHTML 1.0 Transitional

6. colors — Definition of some RGB colors and color conversion functions

Classes defined in module colors

Functions defined in module colors

colors.GLcolor(color)

Convert a color to an OpenGL RGB color.

The output is a tuple of three RGB float values ranging from 0.0 to 1.0. The input can be any of the following:

  • a QColor
  • a string specifying the Xwindow name of the color
  • a hex string ‘#RGB’ with 1 to 4 hexadecimal digits per color
  • a tuple or list of 3 integer values in the range 0..255
  • a tuple or list of 3 float values in the range 0.0..1.0

Any other input may give unpredictable results.

Examples: >>> GLcolor(‘indianred’) (0.803921568627451, 0.3607843137254902, 0.3607843137254902) >>> print(GLcolor(‘#ff0000’)) (1.0, 0.0, 0.0) >>> GLcolor(red) (1.0, 0.0, 0.0) >>> GLcolor([200,200,255]) (0.7843137254901961, 0.7843137254901961, 1.0) >>> GLcolor([1.,1.,1.]) (1.0, 1.0, 1.0)

colors.RGBcolor(color)

Return an RGB (0-255) tuple for a color

color can be anything that is accepted by GLcolor. Returns the corresponding RGB tuple.

colors.RGBAcolor(color, alpha)

Return an RGBA (0-255) tuple for a color and alpha value.

color can be anything that is accepted by GLcolor. Returns the corresponding RGBA tuple.

colors.WEBcolor(color)

Return an RGB hex string for a color

color can be anything that is accepted by GLcolor. Returns the corresponding WEB color, which is a hexadecimal string representation of the RGB components.

colors.colorName(color)

Return a string designation for the color.

color can be anything that is accepted by GLcolor. In the current ijmplementation, the returned color name is the WEBcolor (hexadecimal string).

Examples: >>> colorName(‘red’) ‘#ff0000’ >>> colorName(‘#ffddff’) ‘#ffddff’ >>> colorName([1.,0.,0.5]) ‘#ff0080’

colors.closestColorName(color)

Return the closest color name.

colors.RGBA(rgb, alpha=1.0)

Adds an alpha channel to an RGB color

colors.GREY(val, alpha=1.0)

Returns a grey OpenGL color of given intensity (0..1)