There are three primary colors of light: red, green and blue. (Red, blue, and yellow are the primary colors for paints and pigments, but the computer monitor uses light, not paint.) By combining different amounts of these three colors you can form any other color. In Pygame, we represent colors with tuples of three integers. The first value in the tuple is how much red is in the color. An integer value of
0 means there is no red in this color, and a value of
255 means there is the maximum amount of red in the color. The second value is for green and the third value is for blue. These tuples of three integers used to represent a color are often called RGB values.
Because you can use any combination of
255 for each of the three primary colors, this means Pygame can draw 16,777,216 different colors (that is, 256 x 256 x 256 colors). However, if try to use a number larger than 255 or a negative number, you will get an error that looks like "
ValueError: invalid color argument".
For example, we will create the tuple
(0, 0, 0) and store it in a variable named
BLACK. With no amount of red, green, or blue, the resulting color is completely black. The color black is the absence of any color. The tuple
(255, 255, 255) for a maximum amount of red, green, and blue to result in white. The color white is the full combination of red, green, and blue. The tuple
(255, 0, 0) represents the maximum amount of red but no amount of green and blue, so the resulting color is red. Similarly,
(0, 255, 0) is green and
(0, 0, 255) is blue.
You can mix the amount of red, green, and blue to form other colors. Here are the RGB values for a few common colors:
|Aqua||(0, 255, 255)|
|Black||(0, 0, 0)|
|Blue||(0, 0, 255)|
|Fuchsia||(255, 0, 255)|
|Gray||(128, 128, 128)|
|Green||(0, 128, 0)|
|Lime||(0, 255, 0)|
|Maroon||(128, 0, 0)|
|Navy Blue||(0, 0, 128)|
|Olive||(128, 128, 0)|
|Purple||(128, 0, 128)|
|Red||(255, 0, 0)|
|Silver||(192, 192, 192)|
|Teal||(0, 128, 128)|
|White||(255, 255, 255)|
|Yellow||(255, 255, 0)|