
- Pygame Tutorial
- Pygame - Home
- Pygame - Overview
- Pygame - Hello World
- Pygame - Display modes
- Pygame - Locals module
- Pygame - Color object
- Pygame - Event objects
- Pygame - Keyboard events
- Pygame - Mouse events
- Pygame - Drawing shapes
- Pygame - Loading image
- Pygame - Displaying Text in Window
- Pygame - Moving an image
- Pygame - Moving with Numeric pad keys
- Pygame - Moving with mouse
- Pygame - Moving Rectangular objects
- Pygame - Use Text as Buttons
- Pygame - Transforming Images
- Pygame - Sound objects
- Pygame - Mixer channels
- Pygame - Playing music
- Pygame - Playing Movie
- Pygame - Using Camera module
- Pygame - Load cursor
- Pygame - Access CDROM
- Pygame - The Sprite Module
- Pygame - PyOpenGL
- Pygame - Errors and Exception
- Pygame Useful Resources
- Pygame - Quick Guide
- Pygame - Useful Resources
- Pygame - Discussion
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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. Individual 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 like 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 listed 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 enlist all predefined colors run following for loop −
for k, v in THECOLORS.items(): THECOLORS[unicode_(k)] = v
Advertisements