- Pygame - Discussion
- Pygame - Useful Resources
- Pygame - Quick Guide
- Pygame - Errors and Exception
- Pygame - PyOpenGL
- Pygame - The Sprite Module
- Pygame - Access CDROM
- Pygame - Load cursor
- Pygame - Using Camera module
- Pygame - Playing Movie
- Pygame - Playing music
- Pygame - Mixer channels
- Pygame - Sound objects
- Pygame - Transforming Images
- Pygame - Use Text as Buttons
- Pygame - Moving Rectangular objects
- Pygame - Moving with mouse
- Pygame - Moving with Numeric pad keys
- Pygame - Moving an image
- Pygame - Displaying Text in Window
- Pygame - Loading image
- Pygame - Drawing shapes
- Pygame - Mouse events
- Pygame - Keyboard events
- Pygame - Event objects
- Pygame - Color object
- Pygame - Locals module
- Pygame - Display modes
- Pygame - Hello World
- Pygame - Overview
- Pygame - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Pygame - Color Object
The Color class in Pygame is used to represent color of screen background, text, shapes and all other Pygame objects. It constructed by passing color values for Red, Green, Blue colors and optionally alpha value that represents opaque value. Each of these values range between 0 to 255.
color = pygame.Color(r, g, b, a=255)
Default value of alpha is 255, meaning fully opaque. Inspanidual attributes are accessible and can be set.
pygame.Color.r | Gets or sets the red value of the Color. |
pygame.Color.g | Gets or sets the green value of the Color. |
pygame.Color.b | Gets or sets the blue value of the Color. |
pygame.Color.a | Gets or sets the alpha value of the Color. |
Alternative color models pke CMY, HSVA, HSLA and i1i2i3 can also be used.
pygame.Color.cmy | Gets or sets the CMY representation of the Color. Cyan, Magenta, Yellow |
pygame.Color.hsva | Gets or sets the HSVA representation of the Color. Hue, Saturation, Value |
pygame.Color.hsla | Gets or sets the HSLA representation of the Color. Hue, Saturation, Lightness |
pygame.Color.i1i2i3 | Gets or sets the I1I2I3 representation of the Color. |
We can use predefined string constants to represent RGBA color combinations. Some of the predefined colors are psted below −
black : (0, 0, 0, 255)
blue : (0, 0, 255, 255),
cyan : (0, 255, 255, 255),
gold : (255, 215, 0, 255),
gray : (190, 190, 190, 255),
green : (0, 255, 0, 255),
orange : (255, 165, 0, 255),
purple : (160, 32, 240, 255),
red : (255, 0, 0, 255),
violet : (238, 130, 238, 255)
yellow : (255, 255, 0, 255),
white : (255, 255, 255, 255)
To enpst all predefined colors run following for loop −
for k, v in THECOLORS.items(): THECOLORS[unicode_(k)] = vAdvertisements