Color
Represent a color as red, green, and blue components, with optional transparency.
Use red, green, and blue to build a color directly. Leave any of the three out and a color-selection dialog opens for you to pick one instead.
Ready-made constants are also available:
Color.BLACK = Color( 0, 0, 0)
Color.BLUE = Color( 0, 0, 255)
Color.CYAN = Color( 0, 255, 255)
Color.DARK_GRAY = Color( 44, 44, 44)
Color.GRAY = Color(128, 128, 128)
Color.GREEN = Color( 0, 255, 0)
Color.LIGHT_GRAY = Color(211, 211, 211)
Color.MAGENTA = Color(255, 0, 255)
Color.ORANGE = Color(255, 165, 0)
Color.PINK = Color(255, 192, 203)
Color.PURPLE = Color(128, 0, 128)
Color.RED = Color(255, 0, 0)
Color.WHITE = Color(255, 255, 255)
Color.YELLOW = Color(255, 255, 0)
Color.CLEAR = Color( 0, 0, 0, 0)
All GUI Shapes and many other GUI objects use functions like setColor() and getColor() with Color objects.
Creating a Color
You can create a Color using the following functions:
Color()
Color(red, green, blue)
Color(red, green, blue, alpha)
| Parameter | Type | Default | Description |
|---|---|---|---|
red |
int |
None |
The red component, from 0 to 255. If omitted, a color-selection dialog opens. |
green |
int |
None |
The green component, from 0 to 255. If omitted, a color-selection dialog opens. |
blue |
int |
None |
The blue component, from 0 to 255. If omitted, a color-selection dialog opens. |
alpha |
int |
255 |
The opacity, from 0 (fully transparent) to 255 (fully opaque). |
For example,
color1 = Color(255, 255, 255) # same as Color.WHITE
color2 = Color(255, 255, 255, 150) # same as Color.WHITE, but semi-transparent
Functions
Once a Color has been created, the following functions are available:
| Function | Description |
|---|---|
getRed() |
Return the red component of the color. |
setRed(red) |
Set the red component of the color. |
getGreen() |
Return the green component of the color. |
setGreen(green) |
Set the green component of the color. |
getBlue() |
Return the blue component of the color. |
setBlue(blue) |
Set the blue component of the color. |
getAlpha() |
Return the alpha (transparency) component of the color. |
setAlpha(alpha) |
Set the alpha (transparency) component of the color. |
getRGB() |
Return the color's red, green, and blue components together. |
getRGBA() |
Return the color's red, green, blue, and alpha components together. |
brighter() |
Return a brighter version of the color. |
darker() |
Return a darker version of the color. |
Static Functions
Color has static functions as well - you don't need to create a Color object to use them. Call these functions on the class itself (for example, Color.gradient()).
| Function | Description |
|---|---|
select() |
Open a color-selection dialog and return the RGB values the user picks. |
gradient(startColor, endColor, steps) |
Create a smooth run of colors blending from one color to another. |
getHSBColor(hue, saturation, brightness) |
Create a Color from HSB (hue, saturation, brightness) values. |
HSBtoRGB(hue, saturation, brightness) |
Convert a color from HSB (hue, saturation, brightness) to RGB. |
RGBtoHSB(red, green, blue) |
Convert a color from RGB to HSB (hue, saturation, brightness). |
getHexColor(hex) |
Create a Color from a hex color string. |
HextoRGB(hex) |
Convert a hex color string to RGB. |
RGBtoHex(red, green, blue) |
Convert red, green, and blue values to a hex color string. |